Skip to content

Commit a48ed93

Browse files
committed
Test run_forever and run_until_complete return values
1 parent 3b78c45 commit a48ed93

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

tests/conftest.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
# © 2018 Gerard Marull-Paretas <gerard@teslabs.com>
2-
# © 2014 Mark Harviston <mark.harviston@gmail.com>
3-
# © 2014 Arve Knudsen <arve.knudsen@gmail.com>
4-
# BSD License
1+
"""
2+
Copyright (c) 2018 Gerard Marull-Paretas <gerard@teslabs.com>
3+
Copyright (c) 2014 Mark Harviston <mark.harviston@gmail.com>
4+
Copyright (c) 2014 Arve Knudsen <arve.knudsen@gmail.com>
5+
6+
BSD License
7+
"""
58

6-
import os
79
import logging
8-
from pytest import fixture
10+
import os
911

12+
from pytest import fixture
1013

1114
logging.basicConfig(
1215
level=logging.DEBUG, format="%(levelname)s\t%(filename)s:%(lineno)s %(message)s"

tests/test_qeventloop.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
import asyncio
77
import ctypes
8-
import threading
98
import logging
109
import multiprocessing
1110
import os
1211
import socket
1312
import subprocess
1413
import sys
14+
import threading
1515
import time
1616
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
1717

@@ -809,6 +809,23 @@ async def mycoro():
809809
assert "seconds" in msg
810810

811811

812+
def test_run_until_complete_returns_future_result(loop):
813+
async def coro():
814+
await asyncio.sleep(0)
815+
return 42
816+
817+
assert loop.run_until_complete(asyncio.wait_for(coro(), timeout=0.1)) == 42
818+
819+
820+
def test_run_forever_custom_exit_code(loop, application):
821+
orig_exec = application.exec
822+
application.exec = lambda: 42
823+
try:
824+
assert loop.run_forever() == 42
825+
finally:
826+
application.exec = orig_exec
827+
828+
812829
@pytest.mark.skipif(sys.version_info < (3, 12), reason="Requires Python 3.12+")
813830
def test_asyncio_run(application):
814831
"""Test that QEventLoop is compatible with asyncio.run()"""

0 commit comments

Comments
 (0)