Skip to content

Commit 2f5e316

Browse files
committed
test rule
1 parent 122b12b commit 2f5e316

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

rich/rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __console__(self, console: Console, options: ConsoleOptions) -> RenderResult
5353
yield rule_text
5454

5555

56-
if __name__ == "__main__":
56+
if __name__ == "__main__": # pragma: no cover
5757
from rich.console import Console
5858
import sys
5959

tests/test_rule.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import io
2+
3+
import pytest
4+
5+
from rich.console import Console
6+
from rich.rule import Rule
7+
from rich.text import Text
8+
9+
10+
def test_rule():
11+
console = Console(width=16, file=io.StringIO(), force_terminal=True)
12+
console.rule()
13+
console.rule("foo")
14+
console.rule(Text("foo", style="bold"))
15+
console.rule("foobarbazeggfoobarbazegg")
16+
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[0mfoobarbazegg\x1b[38;5;10m ─\x1b[0m\n"
17+
assert console.file.getvalue() == expected
18+
19+
20+
def test_repr():
21+
rule = Rule("foo")
22+
assert isinstance(repr(rule), str)
23+
24+
25+
def test_error():
26+
with pytest.raises(ValueError):
27+
Rule(character="bar")

0 commit comments

Comments
 (0)