summaryrefslogtreecommitdiffstats
path: root/tests/test_panel.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_panel.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_panel.py')
-rw-r--r--tests/test_panel.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test_panel.py b/tests/test_panel.py
new file mode 100644
index 0000000..da6ad78
--- /dev/null
+++ b/tests/test_panel.py
@@ -0,0 +1,62 @@
+import io
+from rich.console import Console
+from rich.measure import Measurement
+from rich.panel import Panel
+
+import pytest
+
+tests = [
+ Panel("Hello, World", padding=0),
+ Panel("Hello, World", expand=False, padding=0),
+ Panel.fit("Hello, World", padding=0),
+ Panel("Hello, World", width=8, padding=0),
+ Panel(Panel("Hello, World", padding=0), padding=0),
+ Panel("Hello, World", title="FOO", padding=0),
+]
+
+expected = [
+ "╭────────────────────────────────────────────────╮\n│Hello, World │\n╰────────────────────────────────────────────────╯\n",
+ "╭────────────╮\n│Hello, World│\n╰────────────╯\n",
+ "╭────────────╮\n│Hello, World│\n╰────────────╯\n",
+ "╭──────╮\n│Hello,│\n│World │\n╰──────╯\n",
+ "╭────────────────────────────────────────────────╮\n│╭──────────────────────────────────────────────╮│\n││Hello, World ││\n│╰──────────────────────────────────────────────╯│\n╰────────────────────────────────────────────────╯\n",
+ "╭───────────────────── FOO ──────────────────────╮\n│Hello, World │\n╰────────────────────────────────────────────────╯\n",
+]
+
+
+def render(panel, width=50) -> str:
+ console = Console(file=io.StringIO(), width=50, legacy_windows=False)
+ console.print(panel)
+ return console.file.getvalue()
+
+
+@pytest.mark.parametrize("panel,expected", zip(tests, expected))
+def test_render_panel(panel, expected):
+ assert render(panel) == expected
+
+
+def test_console_width():
+ console = Console(file=io.StringIO(), width=50, legacy_windows=False)
+ panel = Panel("Hello, World", expand=False)
+ min_width, max_width = panel.__rich_measure__(console, 50)
+ assert min_width == 16
+ assert max_width == 16
+
+
+def test_fixed_width():
+ console = Console(file=io.StringIO(), width=50, legacy_windows=False)
+ panel = Panel("Hello World", width=20)
+ min_width, max_width = panel.__rich_measure__(console, 100)
+ assert min_width == 20
+ assert max_width == 20
+
+
+if __name__ == "__main__":
+ expected = []
+ for panel in tests:
+ result = render(panel)
+ print(result)
+ expected.append(result)
+ print("--")
+ print()
+ print(f"expected={repr(expected)}")