File: test_async_generator.py

package info (click to toggle)
prompt-toolkit 3.0.51-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,232 kB
  • sloc: python: 30,894; makefile: 151; sh: 6
file content (28 lines) | stat: -rw-r--r-- 658 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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]