diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-09 15:44:30 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-09 15:44:30 (GMT) |
commit | 8170e8c0d12cb9414f3a3d3ca81a447b4afc5f26 (patch) | |
tree | d6353155110b49bf7953fd0d7d3f808512e8feb1 /Lib/test/test_contextlib.py | |
parent | bd60e8dece89440ebdc80a19b2217d5ba2515124 (diff) | |
download | cpython-8170e8c0d12cb9414f3a3d3ca81a447b4afc5f26.zip cpython-8170e8c0d12cb9414f3a3d3ca81a447b4afc5f26.tar.gz cpython-8170e8c0d12cb9414f3a3d3ca81a447b4afc5f26.tar.bz2 |
PEP 479: Change StopIteration handling inside generators.
Closes issue #22906.
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r-- | Lib/test/test_contextlib.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index c52066b..a5d68a9 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -83,6 +83,40 @@ class ContextManagerTestCase(unittest.TestCase): raise ZeroDivisionError(999) self.assertEqual(state, [1, 42, 999]) + def test_contextmanager_except_stopiter(self): + stop_exc = StopIteration('spam') + @contextmanager + def woohoo(): + yield + try: + with woohoo(): + raise stop_exc + except Exception as ex: + self.assertIs(ex, stop_exc) + else: + self.fail('StopIteration was suppressed') + + def test_contextmanager_except_pep479(self): + code = """\ +from __future__ import generator_stop +from contextlib import contextmanager +@contextmanager +def woohoo(): + yield +""" + locals = {} + exec(code, locals, locals) + woohoo = locals['woohoo'] + + stop_exc = StopIteration('spam') + try: + with woohoo(): + raise stop_exc + except Exception as ex: + self.assertIs(ex, stop_exc) + else: + self.fail('StopIteration was suppressed') + def _create_contextmanager_attribs(self): def attribs(**kw): def decorate(func): |