aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py3/tests/test_async_generator.py
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/python/prompt-toolkit/py3/tests/test_async_generator.py
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/tests/test_async_generator.py')
-rw-r--r--contrib/python/prompt-toolkit/py3/tests/test_async_generator.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/contrib/python/prompt-toolkit/py3/tests/test_async_generator.py b/contrib/python/prompt-toolkit/py3/tests/test_async_generator.py
new file mode 100644
index 0000000000..fd2c109c95
--- /dev/null
+++ b/contrib/python/prompt-toolkit/py3/tests/test_async_generator.py
@@ -0,0 +1,24 @@
+from prompt_toolkit.eventloop import generator_to_async_generator, get_event_loop
+
+
+def _sync_generator():
+ yield 1
+ yield 10
+
+
+def test_generator_to_async_generator():
+ """
+ Test conversion of sync to asycn generator.
+ This should run the synchronous parts in a background thread.
+ """
+ async_gen = generator_to_async_generator(_sync_generator)
+
+ items = []
+
+ async def consume_async_generator():
+ async for item in async_gen:
+ items.append(item)
+
+ # Run the event loop until all items are collected.
+ get_event_loop().run_until_complete(consume_async_generator())
+ assert items == [1, 10]