Update tests/test_utils_richcfg.py
Run CI Tests / test (push) Successful in 2m37s

This commit is contained in:
2025-08-05 13:40:09 +02:00
parent 7268423a68
commit e5838b6fde
+19 -9
View File
@@ -4,8 +4,7 @@ import sys
import inspect as std_inspect
from IPython.core.oinspect import Inspector, OInfo
from slic.utils.richcfg import replace_ipython_inspect # ← adapt this to your actual module path
from slic.utils.richcfg import replace_ipython_inspect
# A realistic class to inspect
@@ -23,13 +22,24 @@ class User:
return f"Welcome, {self.name}!"
def dict_to_oinfo(info_dict):
info_obj = OInfo()
info_obj = OInfo(
ismagic=False,
isalias=False,
found=True,
namespace='',
parent=None,
obj=None
)
# Fill in optional fields from dict
for key, value in info_dict.items():
setattr(info_obj, key, value)
if hasattr(info_obj, key):
setattr(info_obj, key, value)
return info_obj
def test_rich_inspector_outputs_more_than_builtin(monkeypatch):
# --- Simulate a fake IPython shell ---
# Simulate a fake IPython shell
class FakeInspector:
def __init__(self):
self.pinfo = None
@@ -41,11 +51,11 @@ def test_rich_inspector_outputs_more_than_builtin(monkeypatch):
fake_ipy = FakeIPython()
monkeypatch.setattr("slic.utils.richcfg.get_ipython", lambda: fake_ipy)
# --- Apply your Rich-based inspector patch ---
# Apply your Rich-based inspector patch
replace_ipython_inspect()
assert isinstance(fake_ipy.inspector.pinfo, types.FunctionType)
# --- Capture Rich inspector output ---
# Capture Rich inspector output
rich_buf = io.StringIO()
monkeypatch.setattr("sys.stdout", rich_buf)
@@ -53,7 +63,7 @@ def test_rich_inspector_outputs_more_than_builtin(monkeypatch):
fake_ipy.inspector.pinfo(user, oname="user", detail_level=1)
rich_text = rich_buf.getvalue()
# --- Capture original IPython inspector output ---
# Capture original IPython inspector output
builtin_buf = io.StringIO()
user = User("Alice", 30)
original_stdout = sys.stdout
@@ -70,7 +80,7 @@ def test_rich_inspector_outputs_more_than_builtin(monkeypatch):
print(rich_text, '\n\n\n')
print(builtin_text)
# --- Comparison assertions: Rich adds structure and content ---
# Comparison assertions: Rich adds structure and content
# Rich has sections and decoration
assert "" in rich_text or "" in rich_text # Decorative borders
assert "Methods" in rich_text and "Methods" not in builtin_text