diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-06-24 16:49:28 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-06-24 16:49:28 (GMT) |
commit | f847f1fba757b94938364c29b14bfc1129024d06 (patch) | |
tree | 323c43dab833d70cb11f95b434521675ebc1e4cd /Lib/test/test_types.py | |
parent | 00e337235855999bfa5339a7d87322b9e0f07148 (diff) | |
download | cpython-f847f1fba757b94938364c29b14bfc1129024d06.zip cpython-f847f1fba757b94938364c29b14bfc1129024d06.tar.gz cpython-f847f1fba757b94938364c29b14bfc1129024d06.tar.bz2 |
Issue #24400, #24325: More tests for types._GeneratorWrapper
Also, make 'wrapped' and 'isgen' private.
Diffstat (limited to 'Lib/test/test_types.py')
-rw-r--r-- | Lib/test/test_types.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index e489898..e283f32 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -1316,6 +1316,11 @@ class CoroutineTests(unittest.TestCase): wrapper.send(1) gen.send.assert_called_once_with(1) + gen.reset_mock() + + next(wrapper) + gen.__next__.assert_called_once_with() + gen.reset_mock() wrapper.throw(1, 2, 3) gen.throw.assert_called_once_with(1, 2, 3) @@ -1412,8 +1417,10 @@ class CoroutineTests(unittest.TestCase): self.fail('StopIteration was expected') def test_gen(self): - def gen(): yield - gen = gen() + def gen_func(): + yield 1 + return (yield 2) + gen = gen_func() @types.coroutine def foo(): return gen wrapper = foo() @@ -1426,6 +1433,17 @@ class CoroutineTests(unittest.TestCase): getattr(gen, name)) self.assertIs(foo().cr_code, gen.gi_code) + self.assertEqual(next(wrapper), 1) + self.assertEqual(wrapper.send(None), 2) + with self.assertRaisesRegex(StopIteration, 'spam'): + wrapper.send('spam') + + gen = gen_func() + wrapper = foo() + wrapper.send(None) + with self.assertRaisesRegex(Exception, 'ham'): + wrapper.throw(Exception, Exception('ham')) + def test_genfunc(self): def gen(): yield self.assertIs(types.coroutine(gen), gen) |