diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-02-05 02:07:05 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-02-05 02:07:05 (GMT) |
commit | 77aa6a71769a36fb6845bb6f9be188b984f00223 (patch) | |
tree | 70abb488f8bf40c4b6fcde898033330a701ee652 | |
parent | 2d6c39b24fee77b32ce3bebd1ca01291ba47d15d (diff) | |
download | cpython-77aa6a71769a36fb6845bb6f9be188b984f00223.zip cpython-77aa6a71769a36fb6845bb6f9be188b984f00223.tar.gz cpython-77aa6a71769a36fb6845bb6f9be188b984f00223.tar.bz2 |
Merged revisions 77980 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77980 | benjamin.peterson | 2010-02-04 19:53:27 -0600 (Thu, 04 Feb 2010) | 1 line
add a test for #7853; the exception must be normalized for with
........
-rw-r--r-- | Lib/test/test_with.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py index f59032e..3cbae02 100644 --- a/Lib/test/test_with.py +++ b/Lib/test/test_with.py @@ -215,11 +215,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) @@ -357,6 +363,17 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase): 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() |