2020-04-19 14:23:53 +00:00
|
|
|
import io
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from rich.console import Console
|
|
|
|
from rich.rule import Rule
|
|
|
|
from rich.text import Text
|
|
|
|
|
|
|
|
|
|
|
|
def test_rule():
|
2020-06-20 17:29:01 +00:00
|
|
|
console = Console(
|
2020-06-20 17:39:00 +00:00
|
|
|
width=16, file=io.StringIO(), force_terminal=True, legacy_windows=False
|
2020-06-20 17:29:01 +00:00
|
|
|
)
|
2020-04-19 14:23:53 +00:00
|
|
|
console.rule()
|
|
|
|
console.rule("foo")
|
|
|
|
console.rule(Text("foo", style="bold"))
|
|
|
|
console.rule("foobarbazeggfoobarbazegg")
|
2020-07-27 16:21:03 +00:00
|
|
|
expected = "\x1b[92m────────────────\x1b[0m\n\x1b[92m───── \x1b[0mfoo\x1b[92m ──────\x1b[0m\n\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ──────\x1b[0m\n\x1b[92m─ \x1b[0mfoobarbazeg…\x1b[92m ─\x1b[0m\n"
|
|
|
|
result = console.file.getvalue()
|
|
|
|
print(repr(result))
|
|
|
|
assert result == expected
|
2020-04-19 14:23:53 +00:00
|
|
|
|
|
|
|
|
2020-06-10 11:55:04 +00:00
|
|
|
def test_rule_cjk():
|
|
|
|
console = Console(
|
2020-06-20 17:29:01 +00:00
|
|
|
width=16,
|
|
|
|
file=io.StringIO(),
|
|
|
|
force_terminal=True,
|
|
|
|
color_system=None,
|
2020-06-20 17:39:00 +00:00
|
|
|
legacy_windows=False,
|
2020-06-10 11:55:04 +00:00
|
|
|
)
|
|
|
|
console.rule("欢迎!")
|
|
|
|
expected = "──── 欢迎! ────\n"
|
|
|
|
assert console.file.getvalue() == expected
|
|
|
|
|
|
|
|
|
2020-04-19 14:23:53 +00:00
|
|
|
def test_repr():
|
|
|
|
rule = Rule("foo")
|
|
|
|
assert isinstance(repr(rule), str)
|
|
|
|
|
|
|
|
|
|
|
|
def test_error():
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
Rule(character="bar")
|