diff options
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) |