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

Function test_reference_cycle_custom_repr

tests/test_pretty.py:393–417  ·  tests/test_pretty.py::test_reference_cycle_custom_repr
()

Source from the content-addressed store, hash-verified

391
392
393def test_reference_cycle_custom_repr() -> None:
394 class Example:
395 def __init__(self, x, y):
396 self.x = x
397 self.y = y
398
399 def __rich_repr__(self):
400 yield (class="st">"x", self.x)
401 yield (class="st">"y", self.y)
402
403 test = Example(1, None)
404 test.y = test
405 res = pretty_repr(test)
406 assert res == class="st">"Example(x=1, y=...)"
407
408 test = Example(1, Example(2, None))
409 test.y.y = test
410 res = pretty_repr(test)
411 assert res == class="st">"Example(x=1, y=Example(x=2, y=...))"
412
413 class="cm"># Not a cyclic reference, just a repeated reference
414 a = Example(2, None)
415 test = Example(1, [a, a])
416 res = pretty_repr(test)
417 assert res == class="st">"Example(x=1, y=[Example(x=2, y=None), Example(x=2, y=None)])"
418
419
420def test_max_depth() -> None:

Callers

nothing calls this directly

Calls 2

pretty_reprFunction · 0.90
ExampleClass · 0.85

Tested by

no test coverage detected