Passes when the provided `exc` matches the structure of `template`. Individual exceptions don't have to be the same objects or even pass an equality test: they only need to be the same type and contain equal `exc_obj.args`.
(self, exc, template)
| 3 | |
| 4 | class ExceptionIsLikeMixin: |
| 5 | def assertExceptionIsLike(self, exc, template): |
| 6 | """ |
| 7 | Passes when the provided `exc` matches the structure of `template`. |
| 8 | Individual exceptions don't have to be the same objects or even pass |
| 9 | an equality test: they only need to be the same type and contain equal |
| 10 | `exc_obj.args`. |
| 11 | """ |
| 12 | if exc is None and template is None: |
| 13 | return |
| 14 | |
| 15 | if template is None: |
| 16 | self.fail(f"unexpected exception: {exc}") |
| 17 | |
| 18 | if exc is None: |
| 19 | self.fail(f"expected an exception like {template!r}, got None") |
| 20 | |
| 21 | if not isinstance(exc, ExceptionGroup): |
| 22 | self.assertEqual(exc.__class__, template.__class__) |
| 23 | self.assertEqual(exc.args[0], template.args[0]) |
| 24 | else: |
| 25 | self.assertEqual(exc.message, template.message) |
| 26 | self.assertEqual(len(exc.exceptions), len(template.exceptions)) |
| 27 | for e, t in zip(exc.exceptions, template.exceptions): |
| 28 | self.assertExceptionIsLike(e, t) |
| 29 | |
| 30 | |
| 31 | class FloatsAreIdenticalMixin: |
no test coverage detected