| 3520 | # Reimplemented to provide special behavior when |
| 3521 | # _ignore_not_implemented_error is True |
| 3522 | def assertRaisesRegex(self, expected_exception, expected_regex, *args, **kwargs): |
| 3523 | # Verifies that an exception with the type expected_exception and message |
| 3524 | # matching the regular expression defined by expected_regex is thrown. |
| 3525 | # If the test is instantiated for a non-native device type (like XLA) |
| 3526 | # then the message is not validated. |
| 3527 | |
| 3528 | # Checks whether the test is instantiated for a device type by testing |
| 3529 | # if the test class has defined the device_type attribute and, |
| 3530 | # if so, tests whether the instantiated device type is native or not |
| 3531 | if hasattr(self, 'device_type') and self.device_type not in NATIVE_DEVICES and self.device_type != "mps": # type: ignore[attr-defined] |
| 3532 | # empty string matches any string |
| 3533 | expected_regex = '' |
| 3534 | |
| 3535 | if self._ignore_not_implemented_error: |
| 3536 | context = AssertRaisesContextIgnoreNotImplementedError( # type: ignore[call-arg] |
| 3537 | expected_exception, self, expected_regex) |
| 3538 | return context.handle('assertRaisesRegex', args, kwargs) # type: ignore[attr-defined] |
| 3539 | else: |
| 3540 | return super().assertRaisesRegex(expected_exception, expected_regex, *args, **kwargs) |
| 3541 | |
| 3542 | # Verifies that no unraisable exceptions are raised by callable. Unlike regular |
| 3543 | # exceptions, these do not actually propagate to the caller and are |