(self)
| 1470 | sys.unraisablehook(exc) |
| 1471 | |
| 1472 | def test_custom_unraisablehook(self): |
| 1473 | _testcapi = import_helper.import_module('_testcapi') |
| 1474 | from _testcapi import err_writeunraisable, err_formatunraisable |
| 1475 | hook_args = None |
| 1476 | |
| 1477 | def hook_func(args): |
| 1478 | nonlocal hook_args |
| 1479 | hook_args = args |
| 1480 | |
| 1481 | obj = hex |
| 1482 | try: |
| 1483 | with test.support.swap_attr(sys, 'unraisablehook', hook_func): |
| 1484 | exc = ValueError(42) |
| 1485 | err_writeunraisable(exc, obj) |
| 1486 | self.assertIs(hook_args.exc_type, type(exc)) |
| 1487 | self.assertIs(hook_args.exc_value, exc) |
| 1488 | self.assertIs(hook_args.exc_traceback, exc.__traceback__) |
| 1489 | self.assertIsNone(hook_args.err_msg) |
| 1490 | self.assertEqual(hook_args.object, obj) |
| 1491 | |
| 1492 | err_formatunraisable(exc, "custom hook %R", obj) |
| 1493 | self.assertIs(hook_args.exc_type, type(exc)) |
| 1494 | self.assertIs(hook_args.exc_value, exc) |
| 1495 | self.assertIs(hook_args.exc_traceback, exc.__traceback__) |
| 1496 | self.assertEqual(hook_args.err_msg, f'custom hook {obj!r}') |
| 1497 | self.assertIsNone(hook_args.object) |
| 1498 | finally: |
| 1499 | # expected and hook_args contain an exception: break reference cycle |
| 1500 | expected = None |
| 1501 | hook_args = None |
| 1502 | |
| 1503 | def test_custom_unraisablehook_fail(self): |
| 1504 | _testcapi = import_helper.import_module('_testcapi') |
nothing calls this directly
no test coverage detected