2020-04-27 15:22:39 +00:00
|
|
|
import io
|
|
|
|
|
|
|
|
from rich.console import Console
|
2020-08-24 16:26:30 +00:00
|
|
|
from rich.panel import Panel
|
2020-04-27 15:22:39 +00:00
|
|
|
from rich.text import Text
|
|
|
|
|
|
|
|
|
|
|
|
class Foo:
|
|
|
|
def __rich__(self):
|
|
|
|
return Text("Foo")
|
|
|
|
|
|
|
|
|
2020-08-24 16:26:30 +00:00
|
|
|
def test_rich_cast():
|
2020-04-27 15:22:39 +00:00
|
|
|
foo = Foo()
|
|
|
|
console = Console(file=io.StringIO())
|
|
|
|
console.print(foo)
|
|
|
|
assert console.file.getvalue() == "Foo\n"
|
2020-08-24 16:26:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_rich_cast_container():
|
|
|
|
foo = Foo()
|
2020-08-25 16:23:06 +00:00
|
|
|
console = Console(file=io.StringIO(), legacy_windows=False)
|
2020-08-24 16:26:30 +00:00
|
|
|
console.print(Panel.fit(foo))
|
|
|
|
assert console.file.getvalue() == "╭───╮\n│Foo│\n╰───╯\n"
|