diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-11 16:20:35 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-11 16:20:35 (GMT) |
commit | c775ad615a6370ec8424422422bbec3f0976428b (patch) | |
tree | 44ae0e24459750d4f01cc2b5ffc9e03c9fc8b9b5 /Lib/test/test_generators.py | |
parent | cf4a2f29adb6bdae0b18e983250d7c48d486c9d6 (diff) | |
download | cpython-c775ad615a6370ec8424422422bbec3f0976428b.zip cpython-c775ad615a6370ec8424422422bbec3f0976428b.tar.gz cpython-c775ad615a6370ec8424422422bbec3f0976428b.tar.bz2 |
Issue #23192: Fixed generator lambdas. Patch by Bruno Cauet.
Diffstat (limited to 'Lib/test/test_generators.py')
-rw-r--r-- | Lib/test/test_generators.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 7825a77..5c455cd 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -49,6 +49,26 @@ class FinalizationTest(unittest.TestCase): self.assertTrue(finalized) self.assertEqual(gc.garbage, old_garbage) + def test_lambda_generator(self): + # Issue #23192: Test that a lambda returning a generator behaves + # like the equivalent function + f = lambda: (yield 1) + def g(): return (yield 1) + + # test 'yield from' + f2 = lambda: (yield from g()) + def g2(): return (yield from g()) + + f3 = lambda: (yield from f()) + def g3(): return (yield from f()) + + for gen_fun in (f, g, f2, g2, f3, g3): + gen = gen_fun() + self.assertEqual(next(gen), 1) + with self.assertRaises(StopIteration) as cm: + gen.send(2) + self.assertEqual(cm.exception.value, 2) + class ExceptionTest(unittest.TestCase): # Tests for the issue #23353: check that the currently handled exception |