diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
commit | f8363b456f1ab31ee56abad579b215af195093d5 (patch) | |
tree | b1500c675c2e0a55fb75721a854e1510acf7c862 /tests/test_protocol.py | |
parent | Initial commit. (diff) | |
download | rich-f8363b456f1ab31ee56abad579b215af195093d5.tar.xz rich-f8363b456f1ab31ee56abad579b215af195093d5.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_protocol.py')
-rw-r--r-- | tests/test_protocol.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_protocol.py b/tests/test_protocol.py new file mode 100644 index 0000000..310b994 --- /dev/null +++ b/tests/test_protocol.py @@ -0,0 +1,35 @@ +import io + +from rich.abc import RichRenderable +from rich.console import Console +from rich.panel import Panel +from rich.text import Text + + +class Foo: + def __rich__(self) -> Text: + return Text("Foo") + + +def test_rich_cast(): + foo = Foo() + console = Console(file=io.StringIO()) + console.print(foo) + assert console.file.getvalue() == "Foo\n" + + +def test_rich_cast_container(): + foo = Foo() + console = Console(file=io.StringIO(), legacy_windows=False) + console.print(Panel.fit(foo, padding=0)) + assert console.file.getvalue() == "╭───╮\n│Foo│\n╰───╯\n" + + +def test_abc(): + foo = Foo() + assert isinstance(foo, RichRenderable) + assert isinstance(Text("hello"), RichRenderable) + assert isinstance(Panel("hello"), RichRenderable) + assert not isinstance(foo, str) + assert not isinstance("foo", RichRenderable) + assert not isinstance([], RichRenderable) |