forked from python-trio/trio-asyncio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_coroutine.py
36 lines (28 loc) · 1.13 KB
/
test_coroutine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from tests import aiotest
import trio_asyncio
import pytest
async def hello_world(asyncio, result, delay, loop):
result.append("Hello")
# retrieve the event loop from the policy
await asyncio.sleep(delay, loop=loop)
result.append('World')
return "."
class TestCoroutine(aiotest.TestCase):
@pytest.mark.trio
async def test_hello_world(self, loop, config):
result = []
coro = hello_world(config.asyncio, result, 0.001, loop)
await loop.run_aio_coroutine(config.asyncio.ensure_future(coro, loop=loop))
assert result == ['Hello', 'World']
@pytest.mark.trio
async def test_waiter(self, loop, config):
async def waiter(asyncio, hello_world, result):
fut = asyncio.Future(loop=loop)
loop.call_soon(fut.set_result, "Future")
value = await fut
result.append(value)
value = await hello_world(asyncio, result, 0.001, loop)
result.append(value)
result = []
await trio_asyncio.aio_as_trio(waiter)(config.asyncio, hello_world, result)
assert result == ['Future', 'Hello', 'World', '.']