summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_with.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-02-05 01:53:27 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-02-05 01:53:27 (GMT)
commit4a7ff1d80abf841287043c5965d1c1c74a1c694a (patch)
tree3b70da6b71fae72a1477298ce0fab87018edbcf5 /Lib/test/test_with.py
parentf7610b23de274199185bab686efbf963aca89c47 (diff)
downloadcpython-4a7ff1d80abf841287043c5965d1c1c74a1c694a.zip
cpython-4a7ff1d80abf841287043c5965d1c1c74a1c694a.tar.gz
cpython-4a7ff1d80abf841287043c5965d1c1c74a1c694a.tar.bz2
add a test for #7853; the exception must be normalized for with
Diffstat (limited to 'Lib/test/test_with.py')
-rw-r--r--Lib/test/test_with.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py
index 3e33e31..4b947d8 100644
--- a/Lib/test/test_with.py
+++ b/Lib/test/test_with.py
@@ -213,11 +213,17 @@ class ContextmanagerAssertionMixin(object):
def raiseTestException(self):
raise self.TEST_EXCEPTION
- def assertAfterWithManagerInvariantsWithError(self, mock_manager):
+ def assertAfterWithManagerInvariantsWithError(self, mock_manager,
+ exc_type=None):
self.assertTrue(mock_manager.enter_called)
self.assertTrue(mock_manager.exit_called)
- self.assertEqual(mock_manager.exit_args[0], RuntimeError)
- self.assertEqual(mock_manager.exit_args[1], self.TEST_EXCEPTION)
+ if exc_type is None:
+ self.assertEqual(mock_manager.exit_args[1], self.TEST_EXCEPTION)
+ exc_type = type(self.TEST_EXCEPTION)
+ self.assertEqual(mock_manager.exit_args[0], exc_type)
+ # Test the __exit__ arguments. Issue #7853
+ self.assertIsInstance(mock_manager.exit_args[1], exc_type)
+ self.assertIsNot(mock_manager.exit_args[2], None)
def assertAfterWithGeneratorInvariantsWithError(self, mock_generator):
self.assertTrue(mock_generator.yielded)
@@ -355,6 +361,17 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
self.assertAfterWithManagerInvariantsWithError(cm)
self.assertAfterWithGeneratorInvariantsWithError(self.resource)
+ @unittest.expectedFailure
+ def testExceptionNormalized(self):
+ cm = mock_contextmanager_generator()
+ def shouldThrow():
+ with cm as self.resource:
+ # Note this relies on the fact that 1 // 0 produces an exception
+ # that is not normalized immediately.
+ 1 // 0
+ self.assertRaises(ZeroDivisionError, shouldThrow)
+ self.assertAfterWithManagerInvariantsWithError(cm, ZeroDivisionError)
+
def testNestedSingleStatements(self):
mock_a = mock_contextmanager_generator()
mock_b = mock_contextmanager_generator()