Skip to content

Commit e1feef8

Browse files
committed
Add async generator tests.
1 parent f1bfafc commit e1feef8

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/interop/test_calls.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ class Seen:
99
flag = 0
1010

1111

12+
async def async_gen_to_list(generator):
13+
result = []
14+
async for item in generator:
15+
result.append(item)
16+
return result
17+
18+
1219
class TestCalls(aiotest.TestCase):
1320
async def call_t_a(self, proc, *args, loop=None):
1421
"""called from Trio"""
@@ -231,3 +238,24 @@ def err_asyncio():
231238
with pytest.raises(RuntimeError) as err:
232239
await self.call_t_a(err_asyncio, loop=loop)
233240
assert err.value.args[0] == "I has an owie"
241+
242+
@pytest.mark.trio
243+
async def test_trio_asyncio_generator(self, loop):
244+
async def dly_asyncio():
245+
yield 1
246+
await asyncio.sleep(0.01, loop=loop)
247+
yield 2
248+
249+
res = await async_gen_to_list(loop.wrap_generator(dly_asyncio))
250+
assert res == [1, 2]
251+
252+
@pytest.mark.trio
253+
async def test_trio_asyncio_generator_with_error(self, loop):
254+
async def dly_asyncio():
255+
yield 1
256+
raise RuntimeError("I has an owie")
257+
yield 2
258+
259+
with pytest.raises(RuntimeError) as err:
260+
await async_gen_to_list(loop.wrap_generator(dly_asyncio))
261+
assert err.value.args[0] == "I has an owie"

0 commit comments

Comments
 (0)