File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ from asyncio import AbstractEventLoop
5
+
6
+ import pytest
7
+
8
+ from tests .custom_loop_utils import CustomLoop , custom_loop_factory
9
+ from tests .utils import get_asyncio_default_loop_per_os
10
+ from uvicorn ._compat import asyncio_run
11
+
12
+
13
+ async def assert_event_loop (expected_loop_class : type [AbstractEventLoop ]):
14
+ assert isinstance (asyncio .get_event_loop (), expected_loop_class )
15
+
16
+
17
+ def test_asyncio_run__default_loop_factory () -> None :
18
+ asyncio_run (assert_event_loop (get_asyncio_default_loop_per_os ()), loop_factory = None )
19
+
20
+
21
+ def test_asyncio_run__custom_loop_factory () -> None :
22
+ asyncio_run (assert_event_loop (CustomLoop ), loop_factory = custom_loop_factory (use_subprocess = False ))
23
+
24
+
25
+ def test_asyncio_run__passing_a_non_awaitable_callback_should_throw_error () -> None :
26
+ with pytest .raises (ValueError ):
27
+ asyncio_run (
28
+ lambda : None , # type: ignore
29
+ loop_factory = custom_loop_factory (use_subprocess = False ),
30
+ )
You can’t perform that action at this time.
0 commit comments