summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-07-31 01:47:08 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-07-31 01:47:08 (GMT)
commit69c88f74a377380eb34e1040f320039e3ab4d014 (patch)
tree5491fe578bbf73d6a23bffffb356b07a41a5abab /Lib
parentebaf75dc0bd7cce14196daedfd8fe2b88726572b (diff)
downloadcpython-69c88f74a377380eb34e1040f320039e3ab4d014.zip
cpython-69c88f74a377380eb34e1040f320039e3ab4d014.tar.gz
cpython-69c88f74a377380eb34e1040f320039e3ab4d014.tar.bz2
Merged revisions 65320 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r65320 | amaury.forgeotdarc | 2008-07-30 19:42:16 -0500 (Wed, 30 Jul 2008) | 3 lines #2542: now that issubclass() may call arbitrary code, make sure that PyErr_ExceptionMatches returns 0 when an exception occurs there. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_exceptions.py35
1 files changed, 33 insertions, 2 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index aa77292..2b248e1 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -6,12 +6,20 @@ import unittest
import pickle
import weakref
-from test.support import TESTFN, unlink, run_unittest
+from test.support import TESTFN, unlink, run_unittest, captured_output
# XXX This is not really enough, each *operation* should be tested!
class ExceptionTests(unittest.TestCase):
+ def test00(self):
+ try:
+ sys.exit(ValueError('aaa'))
+ except SystemExit:
+ pass
+ finally:
+ pass
+
def raise_catch(self, exc, excname):
try:
raise exc("spam")
@@ -404,7 +412,6 @@ class ExceptionTests(unittest.TestCase):
def testExceptionCleanupNames(self):
# Make sure the local variable bound to the exception instance by
# an "except" statement is only visible inside the except block.
-
try:
raise Exception()
except Exception as e:
@@ -565,6 +572,30 @@ class ExceptionTests(unittest.TestCase):
pass
self.assertEquals(e, (None, None, None))
+ def test_badisinstance(self):
+ # Bug #2542: if issubclass(e, MyException) raises an exception,
+ # it should be ignored
+ class Meta(type):
+ def __subclasscheck__(cls, subclass):
+ raise ValueError()
+ class MyException(Exception, metaclass=Meta):
+ pass
+
+ with captured_output("stderr") as stderr:
+ try:
+ raise KeyError()
+ except MyException as e:
+ self.fail("exception should not be a MyException")
+ except KeyError:
+ pass
+ except:
+ self.fail("Should have raised TypeError")
+ else:
+ self.fail("Should have raised TypeError")
+ self.assertEqual(stderr.getvalue(),
+ "Exception ValueError: ValueError() "
+ "in <class 'KeyError'> ignored\n")
+
def test_main():
run_unittest(ExceptionTests)