Add rich.inspect

This commit is contained in:
Will McGugan 2020-09-07 16:44:31 +01:00
parent 38b11c8617
commit c0a580ca1a
17 changed files with 445 additions and 50 deletions

41
tests/test_inspect.py Normal file
View file

@ -0,0 +1,41 @@
import io
from rich import inspect
from rich.console import Console
class Foo:
"""Foo test
Second line
"""
def __init__(self, foo: int) -> None:
"""constructor docs."""
self.foo = foo
@property
def broken(self):
1 / 0
def method(self, a, b) -> str:
"""Multi line
docs.
"""
return "test"
def __dir__(self):
return ["__init__", "broken", "method"]
def test_render():
console = Console(width=100, file=io.StringIO(), legacy_windows=False)
foo = Foo("hello")
inspect(foo, console=console, all=True)
result = console.file.getvalue()
print(repr(result))
expected = "╭──────────── <class 'tests.test_inspect.Foo'> ────────────╮\n│ Foo test │\n│ │\n│ broken = ZeroDivisionError('division by zero') │\n│ __init__ = __init__(foo: int) -> None: constructor docs. │\n│ method = method(a, b) -> str: Multi line │\n╰──────────────────────────────────────────────────────────╯\n"
assert expected == result