Update changelog, add test for inspecting modules containing classes

This commit is contained in:
Darren Burns 2022-01-27 12:36:07 +00:00
parent f715403f1a
commit 8ceeb83fd4
2 changed files with 24 additions and 8 deletions

View File

@ -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
- 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
- Handle classes in inspect when methods=True https://github.com/Textualize/rich/pull/1874
### Added

View File

@ -1,5 +1,6 @@
import io
import sys
from types import ModuleType
import pytest
@ -81,7 +82,6 @@ def test_render():
def test_inspect_text():
expected = (
"╭──────────────── <class 'str'> ─────────────────╮\n"
"│ str(object='') -> str │\n"
@ -99,7 +99,6 @@ def test_inspect_text():
@skip_py36
@skip_py37
def test_inspect_empty_dict():
expected = (
"╭──────────────── <class 'dict'> ────────────────╮\n"
"│ dict() -> new empty dictionary │\n"
@ -121,7 +120,6 @@ def test_inspect_empty_dict():
def test_inspect_builtin_function():
expected = (
"╭────────── <built-in function print> ───────────╮\n"
"│ def print(...) │\n"
@ -138,7 +136,6 @@ def test_inspect_builtin_function():
@skip_py36
def test_inspect_integer():
expected = (
"╭────── <class 'int'> ───────╮\n"
"│ int([x]) -> integer │\n"
@ -155,7 +152,6 @@ def test_inspect_integer():
@skip_py36
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"
value = render(1, value=True)
print(repr(value))
@ -166,7 +162,6 @@ def test_inspect_integer_with_value():
@skip_py37
@skip_py310
def test_inspect_integer_with_methods():
expected = (
"╭──────────────── <class 'int'> ─────────────────╮\n"
"│ int([x]) -> integer │\n"
@ -204,7 +199,6 @@ def test_inspect_integer_with_methods():
@skip_py38
@skip_py39
def test_inspect_integer_with_methods():
expected = (
"╭──────────────── <class 'int'> ─────────────────╮\n"
"│ int([x]) -> integer │\n"
@ -274,3 +268,25 @@ def test_inspect_swig_edge_case():
inspect(thing)
except Exception as 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