Skip to content

Commit

Permalink
Add tests for _compat.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gnir-work committed Aug 18, 2024
1 parent 9e2bcee commit 46078a9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import annotations

import asyncio
from asyncio import AbstractEventLoop

import pytest

from tests.custom_loop_utils import CustomLoop, custom_loop_factory
from tests.utils import get_asyncio_default_loop_per_os
from uvicorn._compat import asyncio_run


async def assert_event_loop(expected_loop_class: type[AbstractEventLoop]):
assert isinstance(asyncio.get_event_loop(), expected_loop_class)


def test_asyncio_run__default_loop_factory() -> None:
asyncio_run(assert_event_loop(get_asyncio_default_loop_per_os()), loop_factory=None)


def test_asyncio_run__custom_loop_factory() -> None:
asyncio_run(assert_event_loop(CustomLoop), loop_factory=custom_loop_factory(use_subprocess=False))


def test_asyncio_run__passing_a_non_awaitable_callback_should_throw_error() -> None:
with pytest.raises(ValueError):
asyncio_run(
lambda: None, # type: ignore
loop_factory=custom_loop_factory(use_subprocess=False),
)

0 comments on commit 46078a9

Please sign in to comment.