()
| 391 | |
| 392 | |
| 393 | def 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 | |
| 420 | def test_max_depth() -> None: |
nothing calls this directly
no test coverage detected