diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-06 16:47:03 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-06 16:47:03 (GMT) |
commit | 60e49aa7560ca70bc5de461abc68eb72d8739e17 (patch) | |
tree | cecbf64f1c2c52048c04d337132af485aeffd87a /Lib/test/test_generators.py | |
parent | f66f03bd358c3c481292f2624b8c947f4f77c370 (diff) | |
parent | 24411f8a8daace4ebf8abd41091b681160b4fb89 (diff) | |
download | cpython-60e49aa7560ca70bc5de461abc68eb72d8739e17.zip cpython-60e49aa7560ca70bc5de461abc68eb72d8739e17.tar.gz cpython-60e49aa7560ca70bc5de461abc68eb72d8739e17.tar.bz2 |
Issue #23996: Added _PyGen_SetStopIterationValue for safe raising
StopIteration with value. More safely handle non-normalized exceptions
in -_PyGen_FetchStopIterationValue.
Diffstat (limited to 'Lib/test/test_generators.py')
-rw-r--r-- | Lib/test/test_generators.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index f4b33af..f81c82f 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -277,6 +277,27 @@ class ExceptionTest(unittest.TestCase): # hence no warning. next(g) + def test_return_tuple(self): + def g(): + return (yield 1) + + gen = g() + self.assertEqual(next(gen), 1) + with self.assertRaises(StopIteration) as cm: + gen.send((2,)) + self.assertEqual(cm.exception.value, (2,)) + + def test_return_stopiteration(self): + def g(): + return (yield 1) + + gen = g() + self.assertEqual(next(gen), 1) + with self.assertRaises(StopIteration) as cm: + gen.send(StopIteration(2)) + self.assertIsInstance(cm.exception.value, StopIteration) + self.assertEqual(cm.exception.value.value, 2) + class YieldFromTests(unittest.TestCase): def test_generator_gi_yieldfrom(self): |