blob: 08beccc229cce8e01a8f0eb35cb131a6d3f095a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import sys
import pytest
from rich.console import Console
from rich.layout import Layout
from rich.panel import Panel
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
def test_render():
layout = Layout(name="root")
repr(layout)
layout.split(Layout(name="top"), Layout(name="bottom"))
top = layout["top"]
top.update(Panel("foo"))
print(type(top._renderable))
assert isinstance(top.renderable, Panel)
layout["bottom"].split(
Layout(name="left"), Layout(name="right"), direction="horizontal"
)
assert layout["root"].name == "root"
assert layout["left"].name == "left"
with pytest.raises(KeyError):
top["asdasd"]
layout["left"].update("foobar")
print(layout["left"].children)
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(Layout("foo", size=2), Layout("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
|