2020-08-08 10:47:10 +00:00
|
|
|
from rich.console import Console
|
|
|
|
from rich.containers import Lines, Renderables
|
2020-10-09 02:19:35 +00:00
|
|
|
from rich.text import Span, Text
|
|
|
|
from rich.style import Style
|
2020-08-08 10:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_renderables_measure():
|
|
|
|
console = Console()
|
|
|
|
text = Text("foo")
|
|
|
|
renderables = Renderables([text])
|
|
|
|
|
2021-03-25 21:08:36 +00:00
|
|
|
result = renderables.__rich_measure__(console, console.options)
|
2020-08-08 10:47:10 +00:00
|
|
|
_min, _max = result
|
|
|
|
assert _min == 3
|
|
|
|
assert _max == 3
|
|
|
|
|
|
|
|
assert list(renderables) == [text]
|
|
|
|
|
|
|
|
|
|
|
|
def test_renderables_empty():
|
|
|
|
console = Console()
|
|
|
|
renderables = Renderables()
|
|
|
|
|
2021-03-25 21:08:36 +00:00
|
|
|
result = renderables.__rich_measure__(console, console.options)
|
2020-08-08 10:47:10 +00:00
|
|
|
_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")]
|
2020-10-09 02:19:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_lines_justify():
|
|
|
|
console = Console()
|
2021-03-01 19:42:00 +00:00
|
|
|
lines1 = Lines([Text("foo", style="b"), Text("test", style="b")])
|
2020-10-09 02:19:35 +00:00
|
|
|
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")]
|
|
|
|
|
2021-03-01 19:42:00 +00:00
|
|
|
lines2 = Lines([Text("foo bar", style="b"), Text("test", style="b")])
|
2020-10-09 02:19:35 +00:00
|
|
|
lines2.justify(console, 7, justify="full")
|
2021-03-01 19:42:00 +00:00
|
|
|
print(repr(lines2._lines[0].spans))
|
2020-10-09 02:19:35 +00:00
|
|
|
assert lines2._lines == [
|
|
|
|
Text(
|
|
|
|
"foo bar",
|
2021-03-01 19:42:00 +00:00
|
|
|
spans=[Span(0, 3, "b"), Span(3, 4, Style.parse("bold")), Span(4, 7, "b")],
|
2020-10-09 02:19:35 +00:00
|
|
|
),
|
|
|
|
Text("test"),
|
|
|
|
]
|