summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-02-05 02:12:14 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-02-05 02:12:14 (GMT)
commit565d78586babda2b62cbe4f89c2dd3cace79c0fa (patch)
treeaded6af69242e82a89f34df49512202d5c2ae08a /Lib/test
parent4a7ff1d80abf841287043c5965d1c1c74a1c694a (diff)
downloadcpython-565d78586babda2b62cbe4f89c2dd3cace79c0fa.zip
cpython-565d78586babda2b62cbe4f89c2dd3cace79c0fa.tar.gz
cpython-565d78586babda2b62cbe4f89c2dd3cace79c0fa.tar.bz2
normalize exceptions passed to the __exit__ method #7853
In Python 2.x, exceptions in finally blocks are not normalized. Since with statements are implemented using finally blocks, ceval.c had to be tweaked to distinguish between with finally blocks and normal ones. A test for the finalization of generators containing with statements was also added.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_generators.py11
-rw-r--r--Lib/test/test_with.py1
2 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index ad7e17c..19bfe07 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -1700,6 +1700,17 @@ And finalization:
>>> del g
exiting
+>>> class context(object):
+... def __enter__(self): pass
+... def __exit__(self, *args): print 'exiting'
+>>> def f():
+... with context():
+... yield
+>>> g = f()
+>>> g.next()
+>>> del g
+exiting
+
GeneratorExit is not caught by except Exception:
diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py
index 4b947d8..a1ec80b 100644
--- a/Lib/test/test_with.py
+++ b/Lib/test/test_with.py
@@ -361,7 +361,6 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
self.assertAfterWithManagerInvariantsWithError(cm)
self.assertAfterWithGeneratorInvariantsWithError(self.resource)
- @unittest.expectedFailure
def testExceptionNormalized(self):
cm = mock_contextmanager_generator()
def shouldThrow():