diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:35:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:35:31 +0000 |
commit | 4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1 (patch) | |
tree | e5dee7be2f0d963da4faad6517278d03783e3adc /tests/test_async_generator.py | |
parent | Initial commit. (diff) | |
download | prompt-toolkit-upstream/3.0.43.tar.xz prompt-toolkit-upstream/3.0.43.zip |
Adding upstream version 3.0.43.upstream/3.0.43
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/test_async_generator.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_async_generator.py b/tests/test_async_generator.py new file mode 100644 index 0000000..8c95f8c --- /dev/null +++ b/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 async 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] |