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