rich/tests/test_rule.py

43 lines
1.2 KiB
Python
Raw Normal View History

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(
width=16, file=io.StringIO(), force_terminal=True, windows_legacy=False
)
2020-04-19 14:23:53 +00:00
console.rule()
console.rule("foo")
console.rule(Text("foo", style="bold"))
console.rule("foobarbazeggfoobarbazegg")
2020-06-10 14:21:07 +00:00
expected = "\x1b[38;5;10m────────────────\x1b[0m\n\x1b[38;5;10m───── \x1b[0mfoo\x1b[38;5;10m ──────\x1b[0m\n\x1b[38;5;10m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[38;5;10m ──────\x1b[0m\n\x1b[38;5;10m─ \x1b[0mfoobarbazeg…\x1b[38;5;10m ─\x1b[0m\n"
2020-04-19 14:23:53 +00:00
assert console.file.getvalue() == expected
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,
windows_legacy=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")