diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-11 16:22:29 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-11 16:22:29 (GMT) |
commit | 91427733ea26a72a987d66db202ed4ddbb95805f (patch) | |
tree | 1952b7a298ab28ea2190a9facb13a8ab30462936 /Lib | |
parent | 354ecf1ef2283434600a12cf544da6df679d03d9 (diff) | |
parent | c775ad615a6370ec8424422422bbec3f0976428b (diff) | |
download | cpython-91427733ea26a72a987d66db202ed4ddbb95805f.zip cpython-91427733ea26a72a987d66db202ed4ddbb95805f.tar.gz cpython-91427733ea26a72a987d66db202ed4ddbb95805f.tar.bz2 |
Issue #23192: Fixed generator lambdas. Patch by Bruno Cauet.
Diffstat (limited to 'Lib')
-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 9e61013..85e09a1 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 GeneratorTest(unittest.TestCase): |