diff options
author | Thomas Wouters <thomas@python.org> | 2006-04-20 22:42:37 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2006-04-20 22:42:37 (GMT) |
commit | 303de6a25b4dc4874eded29c34c719a3bd6a4f40 (patch) | |
tree | 09598a8bf4f8353de8b3c1e728eea522803b39a1 /Lib | |
parent | 4f564bd68a5bf3e22c81c0c74f0e781fa0d3f70a (diff) | |
download | cpython-303de6a25b4dc4874eded29c34c719a3bd6a4f40.zip cpython-303de6a25b4dc4874eded29c34c719a3bd6a4f40.tar.gz cpython-303de6a25b4dc4874eded29c34c719a3bd6a4f40.tar.bz2 |
Fix (and add test for) missing check for BaseException subclasses in the C
API.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_exceptions.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 65f7876..7946142 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -171,10 +171,15 @@ 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: +class BadException(Exception): def __init__(self): raise RuntimeError, "can't instantiate BadException" +# Exceptions must inherit from BaseException, raising invalid exception +# should instead raise SystemError +class InvalidException: + pass + def test_capi1(): import _testcapi try: @@ -201,8 +206,21 @@ def test_capi2(): else: print "Expected exception" +def test_capi3(): + import _testcapi + try: + _testcapi.raise_exception(InvalidException, 1) + except SystemError: + pass + except InvalidException: + raise AssertionError("Managed to raise InvalidException"); + else: + print "Expected SystemError exception" + + if not sys.platform.startswith('java'): test_capi1() test_capi2() + test_capi3() unlink(TESTFN) |