Helper method for `RaisesGroup.matches` and `RaisesGroup._check_exceptions` to check one of potentially several expected exceptions.
(
expected_type: (
type[BaseException] | RaisesExc[BaseException] | RaisesGroup[BaseException]
),
exception: BaseException,
)
| 1214 | |
| 1215 | @staticmethod |
| 1216 | def _check_expected( |
| 1217 | expected_type: ( |
| 1218 | type[BaseException] | RaisesExc[BaseException] | RaisesGroup[BaseException] |
| 1219 | ), |
| 1220 | exception: BaseException, |
| 1221 | ) -> str | None: |
| 1222 | """Helper method for `RaisesGroup.matches` and `RaisesGroup._check_exceptions` |
| 1223 | to check one of potentially several expected exceptions.""" |
| 1224 | if isinstance(expected_type, type): |
| 1225 | return _check_raw_type(expected_type, exception) |
| 1226 | res = expected_type.matches(exception) |
| 1227 | if res: |
| 1228 | return None |
| 1229 | assert expected_type.fail_reason is not None |
| 1230 | if expected_type.fail_reason.startswith("\n"): |
| 1231 | return f"\n{expected_type!r}: {indent(expected_type.fail_reason, ' ')}" |
| 1232 | return f"{expected_type!r}: {expected_type.fail_reason}" |
| 1233 | |
| 1234 | @staticmethod |
| 1235 | def _repr_expected(e: type[BaseException] | AbstractRaises[BaseException]) -> str: |
no test coverage detected