diff options
author | Yury Selivanov <yury@magic.io> | 2017-10-06 06:58:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-06 06:58:28 (GMT) |
commit | b8ab9d3fc816f85f4d6dbef12b7414e6dc10e4dd (patch) | |
tree | 0baec2d80c9dc9f81b215fafd0074edec43730cb /Lib/test/test_asyncgen.py | |
parent | faa135acbfcd55f79fb97f7525c8aa6f5a5b6a22 (diff) | |
download | cpython-b8ab9d3fc816f85f4d6dbef12b7414e6dc10e4dd.zip cpython-b8ab9d3fc816f85f4d6dbef12b7414e6dc10e4dd.tar.gz cpython-b8ab9d3fc816f85f4d6dbef12b7414e6dc10e4dd.tar.bz2 |
bpo-31708: Allow async generator expressions in synchronous functions (#3905)
Diffstat (limited to 'Lib/test/test_asyncgen.py')
-rw-r--r-- | Lib/test/test_asyncgen.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py index 8c69d2b..5a36423 100644 --- a/Lib/test/test_asyncgen.py +++ b/Lib/test/test_asyncgen.py @@ -1037,5 +1037,37 @@ class AsyncGenAsyncioTest(unittest.TestCase): t.cancel() self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop)) + def test_async_gen_expression_01(self): + async def arange(n): + for i in range(n): + await asyncio.sleep(0.01, loop=self.loop) + yield i + + def make_arange(n): + # This syntax is legal starting with Python 3.7 + return (i * 2 async for i in arange(n)) + + async def run(): + return [i async for i in make_arange(10)] + + res = self.loop.run_until_complete(run()) + self.assertEqual(res, [i * 2 for i in range(10)]) + + def test_async_gen_expression_02(self): + async def wrap(n): + await asyncio.sleep(0.01, loop=self.loop) + return n + + def make_arange(n): + # This syntax is legal starting with Python 3.7 + return (i * 2 for i in range(n) if await wrap(i)) + + async def run(): + return [i async for i in make_arange(10)] + + res = self.loop.run_until_complete(run()) + self.assertEqual(res, [i * 2 for i in range(1, 10)]) + + if __name__ == "__main__": unittest.main() |