mirror of
https://github.com/Textualize/rich.git
synced 2025-08-31 07:27:29 +00:00
Add test_rich_console()
This commit is contained in:
parent
14d4d0bf65
commit
26647019e1
1 changed files with 27 additions and 1 deletions
|
@ -1,6 +1,9 @@
|
|||
import pytest
|
||||
|
||||
from rich.padding import Padding
|
||||
from rich.console import Console, ConsoleOptions
|
||||
from rich.style import Style
|
||||
from rich.segment import Segment
|
||||
|
||||
|
||||
def test_repr():
|
||||
|
@ -9,7 +12,11 @@ def test_repr():
|
|||
|
||||
|
||||
def test_indent():
|
||||
assert Padding.indent("test", 4).left == 4
|
||||
indent_result = Padding.indent("test", 4)
|
||||
assert indent_result.top == 0
|
||||
assert indent_result.right == 0
|
||||
assert indent_result.bottom == 0
|
||||
assert indent_result.left == 4
|
||||
|
||||
|
||||
def test_unpack():
|
||||
|
@ -19,3 +26,22 @@ def test_unpack():
|
|||
assert Padding.unpack((3, 4, 5, 6)) == (3, 4, 5, 6)
|
||||
with pytest.raises(ValueError):
|
||||
Padding.unpack((1, 2, 3))
|
||||
|
||||
|
||||
def test_rich_console():
|
||||
renderable = "test renderable"
|
||||
style = Style(color="red")
|
||||
options = ConsoleOptions(
|
||||
min_width=10, max_width=20, is_terminal=False, encoding="utf-8"
|
||||
)
|
||||
|
||||
expected_outputs = [
|
||||
Segment(renderable, style=style),
|
||||
Segment(" " * (20 - len(renderable)), style=style),
|
||||
Segment("\n", style=None),
|
||||
]
|
||||
padding_generator = Padding(renderable, style=style).__rich_console__(
|
||||
Console(), options
|
||||
)
|
||||
for output, expected in zip(padding_generator, expected_outputs):
|
||||
assert output == expected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue