summaryrefslogtreecommitdiffstats
path: root/tests/test_containers.py
blob: 80098982edd7bad4dca7781bd648bb805c2a9f08 (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
55
56
from rich.console import Console
from rich.containers import Lines, Renderables
from rich.text import Span, Text
from rich.style import Style


def test_renderables_measure():
    console = Console()
    text = Text("foo")
    renderables = Renderables([text])

    result = renderables.__rich_measure__(console, console.width)
    _min, _max = result
    assert _min == 3
    assert _max == 3

    assert list(renderables) == [text]


def test_renderables_empty():
    console = Console()
    renderables = Renderables()

    result = renderables.__rich_measure__(console, console.width)
    _min, _max = result
    assert _min == 1
    assert _max == 1


def test_lines_rich_console():
    console = Console()
    lines = Lines([Text("foo")])

    result = list(lines.__rich_console__(console, console.options))
    assert result == [Text("foo")]


def test_lines_justify():
    console = Console()
    lines1 = Lines([Text("foo"), Text("test")])
    lines1.justify(console, 10, justify="left")
    assert lines1._lines == [Text("foo       "), Text("test      ")]
    lines1.justify(console, 10, justify="center")
    assert lines1._lines == [Text("   foo    "), Text("   test   ")]
    lines1.justify(console, 10, justify="right")
    assert lines1._lines == [Text("       foo"), Text("      test")]

    lines2 = Lines([Text("foo bar"), Text("test")])
    lines2.justify(console, 7, justify="full")
    assert lines2._lines == [
        Text(
            "foo bar",
            spans=[Span(0, 3, ""), Span(3, 4, Style.parse("none")), Span(4, 7, "")],
        ),
        Text("test"),
    ]