Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Mar 25, 2023
1 parent 290346c commit eb48d71
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/test_event.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import gc
from asyncio import AbstractEventLoop, Queue, all_tasks, current_task
from asyncio import AbstractEventLoop, Queue, all_tasks, current_task, sleep
from datetime import datetime, timedelta, timezone
from typing import NoReturn

Expand Down Expand Up @@ -93,6 +93,19 @@ async def callback(event: Event) -> None:
assert events[0].args == ("x", "y")
assert events[0].kwargs == {"a": 1, "b": 2}

@pytest.mark.asyncio
async def test_dispatch_event_coroutine_complete(self, source: DummySource, capfd) -> None:
"""Test that a coroutine function listening to an event runs until complete."""

async def callback(event: Event) -> None:
await sleep(0.1)
print("callback done")

source.event_a.connect(callback)
assert await source.event_a.dispatch()
out, err = capfd.readouterr()
assert out == "callback done\n"

@pytest.mark.asyncio
async def test_dispatch_raw(self, source: DummySource) -> None:
"""Test that dispatch_raw() correctly dispatches the given event."""
Expand Down

0 comments on commit eb48d71

Please sign in to comment.