Skip to content

Commit

Permalink
fix: add queue tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Aug 6, 2023
1 parent 5a31232 commit bd5211f
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,52 @@ async def put(value: Any, queue: Queue[Any]) -> None:

assert set(result) == set(range(10))
assert queue._closed # noqa: SLF001


@pytest.mark.anyio()
@pytest.mark.parametrize("x", range(1, 4))
async def test_queue_empty(x: int):
queue: Queue[Any] = create_queue(x)

assert queue.empty()
await queue.aput(1)
assert not queue.empty()
await queue.aget()
assert queue.empty()


@pytest.mark.anyio()
@pytest.mark.parametrize("x", range(1, 4))
async def test_queue_full(x: int):
queue: Queue[Any] = create_queue(x)

async with create_task_group() as task_group:
for i in range(x):
task_group.start_soon(queue.aput, i)

assert queue.full()
await queue.aget()
assert not queue.full()
await queue.aput(1)
assert queue.full()


@pytest.mark.anyio()
@pytest.mark.parametrize("x", range(1, 4))
async def test_queue_size(x: int):
queue: Queue[Any] = create_queue(x)

async with create_task_group() as task_group:
for i in range(x):
task_group.start_soon(queue.aput, i)

assert queue.qsize() == x
await queue.aget()
assert queue.qsize() == x - 1


@pytest.mark.anyio()
@pytest.mark.parametrize("x", range(1, 4))
async def test_queue_length(x: int):
queue: Queue[Any] = create_queue(x)
assert queue.maxsize == x

0 comments on commit bd5211f

Please sign in to comment.