-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) |