()
| 38 | |
| 39 | |
| 40 | def test_exceptions() -> None: |
| 41 | class BrokenRepr: |
| 42 | def __init__(self, ex): |
| 43 | self.ex = ex |
| 44 | |
| 45 | def __repr__(self): |
| 46 | raise self.ex |
| 47 | |
| 48 | class BrokenReprException(Exception): |
| 49 | __str__ = None # type: ignore[assignment] |
| 50 | __repr__ = None # type: ignore[assignment] |
| 51 | |
| 52 | assert "Exception" in saferepr(BrokenRepr(Exception("broken"))) |
| 53 | s = saferepr(BrokenReprException("really broken")) |
| 54 | assert "TypeError" in s |
| 55 | assert "TypeError" in saferepr(BrokenRepr("string")) |
| 56 | |
| 57 | none = None |
| 58 | try: |
| 59 | none() # type: ignore[misc] |
| 60 | except BaseException as exc: |
| 61 | exp_exc = repr(exc) |
| 62 | obj = BrokenRepr(BrokenReprException("omg even worse")) |
| 63 | s2 = saferepr(obj) |
| 64 | assert s2 == ( |
| 65 | f"<[unpresentable exception ({exp_exc!s}) raised in repr()] BrokenRepr object at 0x{id(obj):x}>" |
| 66 | ) |
| 67 | |
| 68 | |
| 69 | def test_baseexception(): |
nothing calls this directly
no test coverage detected