mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 10:08:40 +00:00
tests
This commit is contained in:
parent
70a3cb2903
commit
da69cff49f
2 changed files with 178 additions and 0 deletions
49
tests/test_layout.py
Normal file
49
tests/test_layout.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import pytest
|
||||
|
||||
from rich.console import Console
|
||||
from rich.layout import Layout
|
||||
from rich.panel import Panel
|
||||
|
||||
|
||||
def test_render():
|
||||
layout = Layout(name="root")
|
||||
repr(layout)
|
||||
top = layout.split()
|
||||
top.update(Panel("foo"))
|
||||
print(type(top._renderable))
|
||||
assert isinstance(top.renderable, Panel)
|
||||
bottom = layout.split(direction="horizontal")
|
||||
bottom.split(name="left")
|
||||
bottom.split(name="right")
|
||||
|
||||
assert layout["root"].name == "root"
|
||||
assert layout["left"].name == "left"
|
||||
with pytest.raises(KeyError):
|
||||
top["asdasd"]
|
||||
|
||||
layout["left"].update("foobar")
|
||||
|
||||
console = Console(width=60, color_system=None)
|
||||
|
||||
with console.capture() as capture:
|
||||
console.print(layout, height=10)
|
||||
|
||||
result = capture.get()
|
||||
expected = "╭──────────────────────────────────────────────────────────╮\n│ foo │\n│ │\n│ │\n╰──────────────────────────────────────────────────────────╯\nfoobar ╭───── 'right' (30 x 5) ─────╮\n │ { │\n │ 'size': None, │\n │ 'minimum_size': 1, │\n ╰────────────────────────────╯\n"
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_tree():
|
||||
layout = Layout(name="root")
|
||||
layout.split("foo", size=2)
|
||||
layout.split("bar")
|
||||
|
||||
console = Console(width=60, color_system=None)
|
||||
|
||||
with console.capture() as capture:
|
||||
console.print(layout.tree, height=10)
|
||||
result = capture.get()
|
||||
print(repr(result))
|
||||
expected = "'root' (ratio=1) \n├── (size=2) \n└── (ratio=1) \n"
|
||||
|
||||
assert result == expected
|
Loading…
Add table
Add a link
Reference in a new issue