summaryrefslogtreecommitdiffstats
path: root/tests/test_live_render.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:18:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:18:28 +0000
commitf8363b456f1ab31ee56abad579b215af195093d5 (patch)
treeb1500c675c2e0a55fb75721a854e1510acf7c862 /tests/test_live_render.py
parentInitial commit. (diff)
downloadrich-upstream.tar.xz
rich-upstream.zip
Adding upstream version 9.11.0.upstream/9.11.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_live_render.py')
-rw-r--r--tests/test_live_render.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test_live_render.py b/tests/test_live_render.py
new file mode 100644
index 0000000..17b5632
--- /dev/null
+++ b/tests/test_live_render.py
@@ -0,0 +1,44 @@
+import pytest
+from rich.live_render import LiveRender
+from rich.console import Console, ConsoleDimensions, ConsoleOptions
+from rich.style import Style
+from rich.segment import Segment
+
+
+@pytest.fixture
+def live_render():
+ return LiveRender(renderable="my string")
+
+
+def test_renderable(live_render):
+ assert live_render.renderable == "my string"
+ live_render.set_renderable("another string")
+ assert live_render.renderable == "another string"
+
+
+def test_position_cursor(live_render):
+ assert str(live_render.position_cursor()) == ""
+ live_render._shape = (80, 2)
+ assert str(live_render.position_cursor()) == "\r\x1b[2K\x1b[1A\x1b[2K"
+
+
+def test_restore_cursor(live_render):
+ assert str(live_render.restore_cursor()) == ""
+ live_render._shape = (80, 2)
+ assert str(live_render.restore_cursor()) == "\r\x1b[1A\x1b[2K\x1b[1A\x1b[2K"
+
+
+def test_rich_console(live_render):
+ options = ConsoleOptions(
+ ConsoleDimensions(80, 25),
+ legacy_windows=False,
+ min_width=10,
+ max_width=20,
+ is_terminal=False,
+ encoding="utf-8",
+ )
+ rich_console = live_render.__rich_console__(Console(), options)
+ assert [Segment("my string", Style.parse("none"))] == list(rich_console)
+ live_render.style = "red"
+ rich_console = live_render.__rich_console__(Console(), options)
+ assert [Segment("my string", Style.parse("red"))] == list(rich_console)