diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2023-03-16 10:16:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-16 10:16:01 (GMT) |
commit | 51d693c58454a2c525094a7c74ebac86859353fd (patch) | |
tree | 9c5bd67c259638864cc3e57031ead3707355ba8d /Lib | |
parent | 2dc94634b50f0e5e207787e5ac1d56c68b22c3ae (diff) | |
download | cpython-51d693c58454a2c525094a7c74ebac86859353fd.zip cpython-51d693c58454a2c525094a7c74ebac86859353fd.tar.gz cpython-51d693c58454a2c525094a7c74ebac86859353fd.tar.bz2 |
gh-102594: PyErr_SetObject adds note to exception raised on normalization error (#102675)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_capi/test_exceptions.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_capi/test_exceptions.py b/Lib/test/test_capi/test_exceptions.py index 55f1316..b1c1a61 100644 --- a/Lib/test/test_capi/test_exceptions.py +++ b/Lib/test/test_capi/test_exceptions.py @@ -169,5 +169,25 @@ class Test_ErrSetAndRestore(unittest.TestCase): with self.assertRaises(ZeroDivisionError) as e: _testcapi.exc_set_object(Broken, Broken()) + def test_set_object_and_fetch(self): + class Broken(Exception): + def __init__(self, *arg): + raise ValueError("Broken __init__") + + exc = _testcapi.exc_set_object_fetch(Broken, 'abcd') + self.assertIsInstance(exc, ValueError) + self.assertEqual(exc.__notes__[0], + "Normalization failed: type=Broken args='abcd'") + + class BadArg: + def __repr__(self): + raise TypeError('Broken arg type') + + exc = _testcapi.exc_set_object_fetch(Broken, BadArg()) + self.assertIsInstance(exc, ValueError) + self.assertEqual(exc.__notes__[0], + 'Normalization failed: type=Broken args=<unknown>') + + if __name__ == "__main__": unittest.main() |