mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Issue #14098: New functions PyErr_GetExcInfo and PyErr_SetExcInfo.
Patch by Stefan Behnel.
This commit is contained in:
parent
e27b3608ef
commit
aa2efcb0bc
6 changed files with 120 additions and 0 deletions
|
@ -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):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue