2024-06-22 04:55:00 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-07-18 18:50:38 +00:00
|
|
|
import sys
|
|
|
|
|
2019-07-18 07:02:35 +00:00
|
|
|
import pytest
|
2020-08-16 20:02:12 +00:00
|
|
|
|
|
|
|
asyncio = pytest.importorskip("asyncio")
|
|
|
|
m = pytest.importorskip("pybind11_tests.async_module")
|
2019-07-18 07:02:35 +00:00
|
|
|
|
2024-07-18 18:50:38 +00:00
|
|
|
if sys.platform.startswith("emscripten"):
|
|
|
|
pytest.skip("Can't run a new event_loop in pyodide", allow_module_level=True)
|
|
|
|
|
2019-07-18 07:02:35 +00:00
|
|
|
|
2023-02-22 14:18:55 +00:00
|
|
|
@pytest.fixture()
|
2019-07-18 07:02:35 +00:00
|
|
|
def event_loop():
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
yield loop
|
|
|
|
loop.close()
|
|
|
|
|
|
|
|
|
|
|
|
async def get_await_result(x):
|
|
|
|
return await x
|
|
|
|
|
|
|
|
|
|
|
|
def test_await(event_loop):
|
2023-02-22 14:18:55 +00:00
|
|
|
assert event_loop.run_until_complete(get_await_result(m.SupportsAsync())) == 5
|
2019-07-18 07:02:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_await_missing(event_loop):
|
|
|
|
with pytest.raises(TypeError):
|
|
|
|
event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync()))
|