File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import asyncio
2+ import os
3+ from unittest .mock import ANY
4+
5+ import pytest
6+
7+ import qasync
8+
9+ @pytest .fixture
10+ def get_event_loop_coro (expected_loop ):
11+ async def coro (expected_debug ):
12+ event_loop = asyncio .get_event_loop ()
13+
14+ assert type (event_loop ).__name__ == expected_loop
15+ assert event_loop .get_debug () == expected_debug
16+ await asyncio .sleep (0 )
17+ return coro
18+
19+ @pytest .fixture
20+ def expected_loop ():
21+ return "QIOCPEventLoop" if os .name == "nt" else "QSelectorEventLoop"
22+
23+ def test_run_with_contextmanager (get_event_loop_coro ):
24+ asyncio .set_event_loop (None )
25+ qasync .run (get_event_loop_coro (ANY ))
26+
27+ with pytest .raises (RuntimeError ):
28+ _ = asyncio .get_event_loop ()
29+
30+ def test_run_reset_policy (get_event_loop_coro ):
31+ old_loop = asyncio .new_event_loop ()
32+ qasync .run (get_event_loop_coro (ANY ))
33+ new_loop = asyncio .new_event_loop ()
34+ assert type (old_loop ) == type (new_loop )
35+
36+ def test_run_debug (get_event_loop_coro ):
37+ qasync .run (get_event_loop_coro (True ), debug = True )
38+ qasync .run (get_event_loop_coro (False ), debug = False )
You can’t perform that action at this time.
0 commit comments