diff options
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 104258a..d194c8b 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -3,6 +3,8 @@ from test_support import * from types import ClassType import warnings +import sys, traceback +import _testcapi warnings.filterwarnings("error", "", OverflowWarning, __name__) @@ -161,4 +163,37 @@ r(Exception) try: x = 1/0 except Exception, e: pass +# test that setting an exception at the C level works even if the +# exception object can't be constructed. + +class BadException: + def __init__(self): + raise RuntimeError, "can't instantiate BadException" + +def test_capi1(): + try: + _testcapi.raise_exception(BadException, 1) + except TypeError, err: + exc, err, tb = sys.exc_info() + co = tb.tb_frame.f_code + assert co.co_name == "test_capi1" + assert co.co_filename.endswith('test_exceptions.py') + else: + print "Expected exception" +test_capi1() + +def test_capi2(): + try: + _testcapi.raise_exception(BadException, 0) + except RuntimeError, err: + exc, err, tb = sys.exc_info() + co = tb.tb_frame.f_code + assert co.co_name == "__init__" + assert co.co_filename.endswith('test_exceptions.py') + co2 = tb.tb_frame.f_back.f_code + assert co2.co_name == "test_capi2" + else: + print "Expected exception" +test_capi2() + unlink(TESTFN) |