diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2012-04-19 12:33:43 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2012-04-19 12:33:43 (GMT) |
commit | aa2efcb0bcb80465cfa7114bb20d99c13be57f1c (patch) | |
tree | c9af5b98cf8d7803c1e86d6b9b7104a6a569a77a /Lib/test/test_capi.py | |
parent | e27b3608ef04daa5e27029c329ad426782c9670c (diff) | |
download | cpython-aa2efcb0bcb80465cfa7114bb20d99c13be57f1c.zip cpython-aa2efcb0bcb80465cfa7114bb20d99c13be57f1c.tar.gz cpython-aa2efcb0bcb80465cfa7114bb20d99c13be57f1c.tar.bz2 |
Issue #14098: New functions PyErr_GetExcInfo and PyErr_SetExcInfo.
Patch by Stefan Behnel.
Diffstat (limited to 'Lib/test/test_capi.py')
-rw-r--r-- | Lib/test/test_capi.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 2f94f90..07ec623 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -55,6 +55,29 @@ class CAPITest(unittest.TestCase): def test_memoryview_from_NULL_pointer(self): self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer) + def test_exc_info(self): + raised_exception = ValueError("5") + new_exc = TypeError("TEST") + try: + raise raised_exception + except ValueError as e: + tb = e.__traceback__ + orig_sys_exc_info = sys.exc_info() + orig_exc_info = _testcapi.set_exc_info(new_exc.__class__, new_exc, None) + new_sys_exc_info = sys.exc_info() + new_exc_info = _testcapi.set_exc_info(*orig_exc_info) + reset_sys_exc_info = sys.exc_info() + + self.assertEqual(orig_exc_info[1], e) + + self.assertSequenceEqual(orig_exc_info, (raised_exception.__class__, raised_exception, tb)) + self.assertSequenceEqual(orig_sys_exc_info, orig_exc_info) + self.assertSequenceEqual(reset_sys_exc_info, orig_exc_info) + self.assertSequenceEqual(new_exc_info, (new_exc.__class__, new_exc, None)) + self.assertSequenceEqual(new_sys_exc_info, new_exc_info) + else: + self.assertTrue(False) + @unittest.skipUnless(threading, 'Threading required for this test.') class TestPendingCalls(unittest.TestCase): |