22import asyncio
33import trio
44import sniffio
5+ from async_generator import async_generator , yield_
56from trio_asyncio import aio_as_trio , trio_as_aio
67from tests import aiotest
78from functools import partial
@@ -302,7 +303,7 @@ async def test_asyncio_trio_cancel_out(self, loop):
302303 async def cancelled_trio (seen ):
303304 seen .flag |= 1
304305 await trio .sleep (0.01 )
305- scope = trio .hazmat .current_task ()._cancel_stack [ - 1 ]
306+ scope = trio .hazmat .current_task ()._cancel_status . _scope
306307 scope .cancel ()
307308 seen .flag |= 2
308309 await trio .sleep (0.01 )
@@ -525,21 +526,23 @@ def err_asyncio():
525526
526527 @pytest .mark .trio
527528 async def test_trio_asyncio_generator (self , loop ):
529+ @async_generator
528530 async def dly_asyncio ():
529- yield 1
531+ await yield_ ( 1 )
530532 await asyncio .sleep (0.01 , loop = loop )
531- yield 2
533+ await yield_ ( 2 )
532534
533535 with test_utils .deprecate (self ):
534536 res = await async_gen_to_list (loop .wrap_generator (dly_asyncio ))
535537 assert res == [1 , 2 ]
536538
537539 @pytest .mark .trio
538540 async def test_trio_asyncio_generator_with_error (self , loop ):
541+ @async_generator
539542 async def dly_asyncio ():
540- yield 1
543+ await yield_ ( 1 )
541544 raise RuntimeError ("I has an owie" )
542- yield 2
545+ await yield_ ( 2 )
543546
544547 with test_utils .deprecate (self ):
545548 with pytest .raises (RuntimeError ) as err :
@@ -548,8 +551,9 @@ async def dly_asyncio():
548551
549552 @pytest .mark .trio
550553 async def test_trio_asyncio_generator_with_cancellation (self , loop ):
554+ @async_generator
551555 async def dly_asyncio (hold , seen ):
552- yield 1
556+ await yield_ ( 1 )
553557 seen .flag |= 1
554558 await hold .wait ()
555559
@@ -569,10 +573,11 @@ async def cancel_soon(nursery):
569573
570574 @pytest .mark .trio
571575 async def test_trio_asyncio_iterator (self , loop ):
576+ @async_generator
572577 async def slow_nums ():
573578 for n in range (1 , 6 ):
574- asyncio .sleep (0.01 , loop = loop )
575- yield n
579+ await asyncio .sleep (0.01 , loop = loop )
580+ await yield_ ( n )
576581
577582 sum = 0
578583 async for n in aio_as_trio (slow_nums ()):
@@ -581,10 +586,11 @@ async def slow_nums():
581586
582587 @pytest .mark .trio
583588 async def test_trio_asyncio_iterator_depr (self , loop ):
589+ @async_generator
584590 async def slow_nums ():
585591 for n in range (1 , 6 ):
586- asyncio .sleep (0.01 , loop = loop )
587- yield n
592+ await asyncio .sleep (0.01 , loop = loop )
593+ await yield_ ( n )
588594
589595 sum = 0
590596 # with test_utils.deprecate(self): ## not yet
0 commit comments