mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 10:08:40 +00:00
protocol and abc
This commit is contained in:
parent
48bb8b9c63
commit
084860050b
9 changed files with 50 additions and 12 deletions
|
@ -1,12 +1,13 @@
|
|||
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):
|
||||
def __rich__(self) -> Text:
|
||||
return Text("Foo")
|
||||
|
||||
|
||||
|
@ -22,3 +23,13 @@ def test_rich_cast_container():
|
|||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue