summaryrefslogtreecommitdiffstats
path: root/tests/test_async_generator.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:35:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:35:20 +0000
commite106bf94eff07d9a59771d9ccc4406421e18ab64 (patch)
treeedb6545500e39df9c67aa918a6125bffc8ec1aee /tests/test_async_generator.py
parentInitial commit. (diff)
downloadprompt-toolkit-0a3e0a12a3f6453f8e5b1cffb2f7e1e619420f44.tar.xz
prompt-toolkit-0a3e0a12a3f6453f8e5b1cffb2f7e1e619420f44.zip
Adding upstream version 3.0.36.upstream/3.0.36upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_async_generator.py')
-rw-r--r--tests/test_async_generator.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_async_generator.py b/tests/test_async_generator.py
new file mode 100644
index 0000000..fd2c109
--- /dev/null
+++ b/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]