summaryrefslogtreecommitdiff
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2008-08-26 22:42:08 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2008-08-26 22:42:08 +0000
commit0668c62677e76b2acf7e4d11d5e9c1f4420a54f1 (patch)
tree0d6001ed47c5e6f715996eb2fc7e512d8c7a2de7 /Lib/test/test_exceptions.py
parent14cb6bcf2ba953735ec1ef622f8ff8e23db1f326 (diff)
downloadcpython-git-0668c62677e76b2acf7e4d11d5e9c1f4420a54f1.tar.gz
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
match Python 2.5 speed despite the __instancecheck__ / __subclasscheck__ mechanism. In the process, fix a bug where isinstance() and issubclass(), when given a tuple of classes as second argument, were looking up __instancecheck__ / __subclasscheck__ on the tuple rather than on each type object. Reviewed by Benjamin Peterson and Raymond Hettinger.
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index c3a93082bf..0576b6249f 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -333,7 +333,19 @@ class ExceptionTests(unittest.TestCase):
return g()
except ValueError:
return -1
- self.assertRaises(RuntimeError, g)
+
+ # The test prints an unraisable recursion error when
+ # doing "except ValueError", this is because subclass
+ # checking has recursion checking too.
+ with captured_output("stderr"):
+ try:
+ g()
+ except RuntimeError:
+ pass
+ except:
+ self.fail("Should have raised KeyError")
+ else:
+ self.fail("Should have raised KeyError")
def testUnicodeStrUsage(self):
# Make sure both instances and classes have a str and unicode
@@ -363,12 +375,20 @@ class ExceptionTests(unittest.TestCase):
except KeyError:
pass
except:
- self.fail("Should have raised TypeError")
+ self.fail("Should have raised KeyError")
else:
- self.fail("Should have raised TypeError")
- self.assertEqual(stderr.getvalue(),
- "Exception ValueError: ValueError() in "
- "<type 'exceptions.KeyError'> ignored\n")
+ self.fail("Should have raised KeyError")
+
+ with captured_output("stderr") as stderr:
+ def g():
+ try:
+ return g()
+ except RuntimeError:
+ return sys.exc_info()
+ e, v, tb = g()
+ self.assert_(e is RuntimeError, e)
+ self.assert_("maximum recursion depth exceeded" in str(v), v)
+
def test_main():
run_unittest(ExceptionTests)