Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions tests/test_trio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

from typing import NoReturn

import pytest
import pytest_trio.plugin # type: ignore # noqa
import trio
Expand All @@ -12,7 +14,7 @@ class PyeeTestError(Exception):


@pytest.mark.trio
async def test_trio_emit():
async def test_trio_emit() -> None:
"""Test that the trio event emitter can handle wrapping
coroutines
"""
Expand All @@ -35,7 +37,7 @@ async def event_handler():


@pytest.mark.trio
async def test_trio_once_emit():
async def test_trio_once_emit() -> None:
"""Test that trio event emitters also wrap coroutines when
using once
"""
Expand All @@ -58,13 +60,13 @@ async def event_handler():


@pytest.mark.trio
async def test_trio_error():
async def test_trio_error() -> None:
"""Test that trio event emitters can handle errors when
wrapping coroutines
"""

async with TrioEventEmitter() as ee:
send, rcv = trio.open_memory_channel(1)
send, rcv = trio.open_memory_channel[PyeeTestError](1)

@ee.on("event")
async def event_handler():
Expand All @@ -86,18 +88,18 @@ async def handle_error(exc):


@pytest.mark.trio
async def test_sync_error(event_loop):
async def test_sync_error() -> None:
"""Test that regular functions have the same error handling as coroutines"""

async with TrioEventEmitter() as ee:
send, rcv = trio.open_memory_channel(1)
send, rcv = trio.open_memory_channel[PyeeTestError](1)

@ee.on("event")
def sync_handler():
def sync_handler() -> NoReturn:
raise PyeeTestError()

@ee.on("error")
async def handle_error(exc):
async def handle_error(exc) -> None:
async with send:
await send.send(exc)

Expand Down