aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py3/tests/test_async_generator.py
diff options
context:
space:
mode:
authornkozlovskiy <nmk@ydb.tech>2023-09-29 12:24:06 +0300
committernkozlovskiy <nmk@ydb.tech>2023-09-29 12:41:34 +0300
commite0e3e1717e3d33762ce61950504f9637a6e669ed (patch)
treebca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/prompt-toolkit/py3/tests/test_async_generator.py
parent38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff)
downloadydb-e0e3e1717e3d33762ce61950504f9637a6e669ed.tar.gz
add ydb deps
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.py28
1 files changed, 28 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..4a01c0e3d6
--- /dev/null
+++ b/contrib/python/prompt-toolkit/py3/tests/test_async_generator.py
@@ -0,0 +1,28 @@
+from __future__ import annotations
+
+from asyncio import run
+
+from prompt_toolkit.eventloop import generator_to_async_generator
+
+
+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.
+ run(consume_async_generator())
+ assert items == [1, 10]