Henry Schreiner | d8c7ee0 | 2020-07-20 13:35:21 -0400 | [diff] [blame^] | 1 | # -*- coding: utf-8 -*- |
Jeremy Maitin-Shepard | a3f4a0e | 2019-07-18 00:02:35 -0700 | [diff] [blame] | 2 | import asyncio |
| 3 | import pytest |
| 4 | from pybind11_tests import async_module as m |
| 5 | |
| 6 | |
| 7 | @pytest.fixture |
| 8 | def event_loop(): |
| 9 | loop = asyncio.new_event_loop() |
| 10 | yield loop |
| 11 | loop.close() |
| 12 | |
| 13 | |
| 14 | async def get_await_result(x): |
| 15 | return await x |
| 16 | |
| 17 | |
| 18 | def test_await(event_loop): |
| 19 | assert 5 == event_loop.run_until_complete(get_await_result(m.SupportsAsync())) |
| 20 | |
| 21 | |
| 22 | def test_await_missing(event_loop): |
| 23 | with pytest.raises(TypeError): |
| 24 | event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync())) |