mirror of https://github.com/Textualize/rich.git
Update changelog, add test for inspecting modules containing classes
This commit is contained in:
parent
f715403f1a
commit
8ceeb83fd4
|
@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Workaround for edge case of object from Faiss with no `__class__` https://github.com/Textualize/rich/issues/1838
|
- Workaround for edge case of object from Faiss with no `__class__` https://github.com/Textualize/rich/issues/1838
|
||||||
- Add `Syntax.guess_lexer`, add support for more lexers (e.g. Django templates etc.) https://github.com/Textualize/rich/pull/1869
|
- Add `Syntax.guess_lexer`, add support for more lexers (e.g. Django templates etc.) https://github.com/Textualize/rich/pull/1869
|
||||||
- Ensure `Syntax` always justifies left https://github.com/Textualize/rich/pull/1872
|
- Ensure `Syntax` always justifies left https://github.com/Textualize/rich/pull/1872
|
||||||
|
- Handle classes in inspect when methods=True https://github.com/Textualize/rich/pull/1874
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import io
|
import io
|
||||||
import sys
|
import sys
|
||||||
|
from types import ModuleType
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -81,7 +82,6 @@ def test_render():
|
||||||
|
|
||||||
|
|
||||||
def test_inspect_text():
|
def test_inspect_text():
|
||||||
|
|
||||||
expected = (
|
expected = (
|
||||||
"╭──────────────── <class 'str'> ─────────────────╮\n"
|
"╭──────────────── <class 'str'> ─────────────────╮\n"
|
||||||
"│ str(object='') -> str │\n"
|
"│ str(object='') -> str │\n"
|
||||||
|
@ -99,7 +99,6 @@ def test_inspect_text():
|
||||||
@skip_py36
|
@skip_py36
|
||||||
@skip_py37
|
@skip_py37
|
||||||
def test_inspect_empty_dict():
|
def test_inspect_empty_dict():
|
||||||
|
|
||||||
expected = (
|
expected = (
|
||||||
"╭──────────────── <class 'dict'> ────────────────╮\n"
|
"╭──────────────── <class 'dict'> ────────────────╮\n"
|
||||||
"│ dict() -> new empty dictionary │\n"
|
"│ dict() -> new empty dictionary │\n"
|
||||||
|
@ -121,7 +120,6 @@ def test_inspect_empty_dict():
|
||||||
|
|
||||||
|
|
||||||
def test_inspect_builtin_function():
|
def test_inspect_builtin_function():
|
||||||
|
|
||||||
expected = (
|
expected = (
|
||||||
"╭────────── <built-in function print> ───────────╮\n"
|
"╭────────── <built-in function print> ───────────╮\n"
|
||||||
"│ def print(...) │\n"
|
"│ def print(...) │\n"
|
||||||
|
@ -138,7 +136,6 @@ def test_inspect_builtin_function():
|
||||||
|
|
||||||
@skip_py36
|
@skip_py36
|
||||||
def test_inspect_integer():
|
def test_inspect_integer():
|
||||||
|
|
||||||
expected = (
|
expected = (
|
||||||
"╭────── <class 'int'> ───────╮\n"
|
"╭────── <class 'int'> ───────╮\n"
|
||||||
"│ int([x]) -> integer │\n"
|
"│ int([x]) -> integer │\n"
|
||||||
|
@ -155,7 +152,6 @@ def test_inspect_integer():
|
||||||
|
|
||||||
@skip_py36
|
@skip_py36
|
||||||
def test_inspect_integer_with_value():
|
def test_inspect_integer_with_value():
|
||||||
|
|
||||||
expected = "╭────── <class 'int'> ───────╮\n│ int([x]) -> integer │\n│ int(x, base=10) -> integer │\n│ │\n│ ╭────────────────────────╮ │\n│ │ 1 │ │\n│ ╰────────────────────────╯ │\n│ │\n│ denominator = 1 │\n│ imag = 0 │\n│ numerator = 1 │\n│ real = 1 │\n╰────────────────────────────╯\n"
|
expected = "╭────── <class 'int'> ───────╮\n│ int([x]) -> integer │\n│ int(x, base=10) -> integer │\n│ │\n│ ╭────────────────────────╮ │\n│ │ 1 │ │\n│ ╰────────────────────────╯ │\n│ │\n│ denominator = 1 │\n│ imag = 0 │\n│ numerator = 1 │\n│ real = 1 │\n╰────────────────────────────╯\n"
|
||||||
value = render(1, value=True)
|
value = render(1, value=True)
|
||||||
print(repr(value))
|
print(repr(value))
|
||||||
|
@ -166,7 +162,6 @@ def test_inspect_integer_with_value():
|
||||||
@skip_py37
|
@skip_py37
|
||||||
@skip_py310
|
@skip_py310
|
||||||
def test_inspect_integer_with_methods():
|
def test_inspect_integer_with_methods():
|
||||||
|
|
||||||
expected = (
|
expected = (
|
||||||
"╭──────────────── <class 'int'> ─────────────────╮\n"
|
"╭──────────────── <class 'int'> ─────────────────╮\n"
|
||||||
"│ int([x]) -> integer │\n"
|
"│ int([x]) -> integer │\n"
|
||||||
|
@ -204,7 +199,6 @@ def test_inspect_integer_with_methods():
|
||||||
@skip_py38
|
@skip_py38
|
||||||
@skip_py39
|
@skip_py39
|
||||||
def test_inspect_integer_with_methods():
|
def test_inspect_integer_with_methods():
|
||||||
|
|
||||||
expected = (
|
expected = (
|
||||||
"╭──────────────── <class 'int'> ─────────────────╮\n"
|
"╭──────────────── <class 'int'> ─────────────────╮\n"
|
||||||
"│ int([x]) -> integer │\n"
|
"│ int([x]) -> integer │\n"
|
||||||
|
@ -274,3 +268,25 @@ def test_inspect_swig_edge_case():
|
||||||
inspect(thing)
|
inspect(thing)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert False, f"Object with no __class__ shouldn't raise {e}"
|
assert False, f"Object with no __class__ shouldn't raise {e}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_inspect_module_with_class():
|
||||||
|
def function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Thing:
|
||||||
|
"""Docstring"""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
module = ModuleType("my_module")
|
||||||
|
module.SomeClass = Thing
|
||||||
|
module.function = function
|
||||||
|
|
||||||
|
expected = (
|
||||||
|
"╭────────── <module 'my_module'> ──────────╮\n"
|
||||||
|
"│ function = def function(): │\n"
|
||||||
|
"│ SomeClass = class SomeClass(): Docstring │\n"
|
||||||
|
"╰──────────────────────────────────────────╯\n"
|
||||||
|
)
|
||||||
|
assert render(module, methods=True) == expected
|
||||||
|
|
Loading…
Reference in New Issue