summaryrefslogtreecommitdiffstats
path: root/tests/test_rule.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:18:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:18:28 +0000
commitf8363b456f1ab31ee56abad579b215af195093d5 (patch)
treeb1500c675c2e0a55fb75721a854e1510acf7c862 /tests/test_rule.py
parentInitial commit. (diff)
downloadrich-upstream.tar.xz
rich-upstream.zip
Adding upstream version 9.11.0.upstream/9.11.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/test_rule.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/test_rule.py b/tests/test_rule.py
new file mode 100644
index 0000000..d5edcf4
--- /dev/null
+++ b/tests/test_rule.py
@@ -0,0 +1,83 @@
+import io
+
+import pytest
+
+from rich.console import Console
+from rich.rule import Rule
+from rich.text import Text
+
+
+def test_rule():
+ console = Console(
+ width=16, file=io.StringIO(), force_terminal=True, legacy_windows=False
+ )
+ console.print(Rule())
+ console.print(Rule("foo"))
+ console.rule(Text("foo", style="bold"))
+ console.rule("foobarbazeggfoobarbazegg")
+ expected = "\x1b[92m────────────────\x1b[0m\n"
+ expected += "\x1b[92m───── \x1b[0mfoo\x1b[92m ──────\x1b[0m\n"
+ expected += "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ──────\x1b[0m\n"
+ expected += "\x1b[92m─ \x1b[0mfoobarbazeg…\x1b[92m ─\x1b[0m\n"
+
+ result = console.file.getvalue()
+ assert result == expected
+
+
+def test_rule_error():
+ console = Console(width=16, file=io.StringIO(), legacy_windows=False)
+ with pytest.raises(ValueError):
+ console.rule("foo", align="foo")
+
+
+def test_rule_align():
+ console = Console(width=16, file=io.StringIO(), legacy_windows=False)
+ console.rule("foo")
+ console.rule("foo", align="left")
+ console.rule("foo", align="center")
+ console.rule("foo", align="right")
+ console.rule()
+ result = console.file.getvalue()
+ print(repr(result))
+ expected = "───── foo ──────\nfoo ────────────\n───── foo ──────\n──────────── foo\n────────────────\n"
+ assert result == expected
+
+
+def test_rule_cjk():
+ console = Console(
+ width=16,
+ file=io.StringIO(),
+ force_terminal=True,
+ color_system=None,
+ legacy_windows=False,
+ )
+ console.rule("欢迎!")
+ expected = "──── 欢迎! ────\n"
+ assert console.file.getvalue() == expected
+
+
+def test_characters():
+ console = Console(
+ width=16,
+ file=io.StringIO(),
+ force_terminal=True,
+ color_system=None,
+ legacy_windows=False,
+ )
+ console.rule(characters="+*")
+ console.rule("foo", characters="+*")
+ console.print(Rule(characters=".,"))
+ expected = "+*+*+*+*+*+*+*+*\n"
+ expected += "+*+*+ foo +*+*+*\n"
+ expected += ".,.,.,.,.,.,.,.,\n"
+ assert console.file.getvalue() == expected
+
+
+def test_repr():
+ rule = Rule("foo")
+ assert isinstance(repr(rule), str)
+
+
+def test_error():
+ with pytest.raises(ValueError):
+ Rule(characters="")