summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_with.py
diff options
context:
space:
mode:
authorPhillip J. Eby <pje@telecommunity.com>2006-04-03 20:05:05 (GMT)
committerPhillip J. Eby <pje@telecommunity.com>2006-04-03 20:05:05 (GMT)
commit9444bd51c46a34410e92560e8f96ab75bd9eb332 (patch)
treef439b7e2658f49e350f1c5e4fc33862265b0368d /Lib/test/test_with.py
parent9161a0d8da0ea3d8159ceed0d0bdb9e85e52e448 (diff)
downloadcpython-9444bd51c46a34410e92560e8f96ab75bd9eb332.zip
cpython-9444bd51c46a34410e92560e8f96ab75bd9eb332.tar.gz
cpython-9444bd51c46a34410e92560e8f96ab75bd9eb332.tar.bz2
Fix SF#1462485: StopIteration raised in body of 'with' statement suppressed
Diffstat (limited to 'Lib/test/test_with.py')
-rw-r--r--Lib/test/test_with.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py
index 4854436..48e00f4 100644
--- a/Lib/test/test_with.py
+++ b/Lib/test/test_with.py
@@ -494,6 +494,62 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
self.assertAfterWithGeneratorInvariantsWithError(self.foo)
self.assertAfterWithGeneratorInvariantsNoError(self.bar)
+ def testRaisedStopIteration1(self):
+ @contextmanager
+ def cm():
+ yield
+
+ def shouldThrow():
+ with cm():
+ raise StopIteration("from with")
+
+ self.assertRaises(StopIteration, shouldThrow)
+
+ def testRaisedStopIteration2(self):
+ class cm (object):
+ def __context__(self):
+ return self
+
+ def __enter__(self):
+ pass
+
+ def __exit__(self, type, value, traceback):
+ pass
+
+ def shouldThrow():
+ with cm():
+ raise StopIteration("from with")
+
+ self.assertRaises(StopIteration, shouldThrow)
+
+ def testRaisedGeneratorExit1(self):
+ @contextmanager
+ def cm():
+ yield
+
+ def shouldThrow():
+ with cm():
+ raise GeneratorExit("from with")
+
+ self.assertRaises(GeneratorExit, shouldThrow)
+
+ def testRaisedGeneratorExit2(self):
+ class cm (object):
+ def __context__(self):
+ return self
+
+ def __enter__(self):
+ pass
+
+ def __exit__(self, type, value, traceback):
+ pass
+
+ def shouldThrow():
+ with cm():
+ raise GeneratorExit("from with")
+
+ self.assertRaises(GeneratorExit, shouldThrow)
+
class NonLocalFlowControlTestCase(unittest.TestCase):