MCPcopy
hub / github.com/Textualize/rich / test_reference_cycle_dataclass

Function test_reference_cycle_dataclass

tests/test_pretty.py:347–367  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

345
346
347def test_reference_cycle_dataclass() -> None:
348 @dataclass
349 class Example:
350 x: int
351 y: Any
352
353 test = Example(1, None)
354 test.y = test
355 res = pretty_repr(test)
356 assert res == "Example(x=1, y=...)"
357
358 test = Example(1, Example(2, None))
359 test.y.y = test
360 res = pretty_repr(test)
361 assert res == "Example(x=1, y=Example(x=2, y=...))"
362
363 # Not a cyclic reference, just a repeated reference
364 a = Example(2, None)
365 test = Example(1, [a, a])
366 res = pretty_repr(test)
367 assert res == "Example(x=1, y=[Example(x=2, y=None), Example(x=2, y=None)])"
368
369
370def test_reference_cycle_attrs() -> None:

Callers

nothing calls this directly

Calls 2

pretty_reprFunction · 0.90
ExampleClass · 0.85

Tested by

no test coverage detected