Skip to content

Commit 565aa99

Browse files
committed
Merge branch 'testrun' into py316-deprecate
2 parents 9efe4f7 + 36b09cf commit 565aa99

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/test_run.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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)

0 commit comments

Comments
 (0)