@@ -48,7 +48,7 @@ async def __aenter__(self):
4848 self .parent .did_it = 1
4949 if sys .version_info >= (3 , 7 ):
5050 assert sniffio .current_async_library () == "asyncio"
51- await asyncio .sleep (0.01 )
51+ await asyncio .sleep (0.01 , loop = self . loop )
5252 self .parent .did_it = 2
5353 return self
5454
@@ -60,7 +60,7 @@ async def __aexit__(self, *tb):
6060class TestCalls (aiotest .TestCase ):
6161 async def call_t_a (self , proc , * args , loop = None ):
6262 """called from Trio"""
63- return await aio_as_trio (proc )(* args )
63+ return await aio_as_trio (proc , loop = loop )(* args )
6464
6565 async def call_t_a_depr (self , proc , * args , loop = None ):
6666 """called from Trio"""
@@ -69,7 +69,7 @@ async def call_t_a_depr(self, proc, *args, loop=None):
6969
7070 async def call_a_t (self , proc , * args , loop = None ):
7171 """call from asyncio to an async trio function"""
72- return await trio_as_aio (proc )(* args )
72+ return await trio_as_aio (proc , loop = loop )(* args )
7373
7474 async def call_a_t_depr (self , proc , * args , loop = None ):
7575 """call from asyncio to an async trio function"""
@@ -83,17 +83,17 @@ async def call_a_ts(self, proc, *args, loop=None):
8383 @pytest .mark .trio
8484 async def test_call_at (self , loop ):
8585 async def delay (t ):
86- done = asyncio .Event ()
86+ done = asyncio .Event (loop = loop )
8787 loop .call_at (t , done .set )
8888 await done .wait ()
8989
9090 t = loop .time () + 0.1
91- await aio_as_trio (delay )(t )
91+ await aio_as_trio (delay , loop = loop )(t )
9292
9393 @pytest .mark .trio
9494 async def test_call_at_depr (self , loop ):
9595 async def delay (t ):
96- done = asyncio .Event ()
96+ done = asyncio .Event (loop = loop )
9797 loop .call_at (t , done .set )
9898 await done .wait ()
9999
@@ -111,7 +111,7 @@ async def dly_trio(seen):
111111 return 8
112112
113113 seen = Seen ()
114- res = await aio_as_trio (partial (self .call_a_t , loop = loop ))(dly_trio , seen )
114+ res = await aio_as_trio (partial (self .call_a_t , loop = loop ), loop = loop )(dly_trio , seen )
115115 assert res == 8
116116 assert seen .flag == 2
117117
@@ -125,14 +125,14 @@ async def dly_trio(seen):
125125 return 8
126126
127127 seen = Seen ()
128- res = await aio_as_trio (partial (self .call_a_t_depr , loop = loop ))(dly_trio , seen )
128+ res = await aio_as_trio (partial (self .call_a_t_depr , loop = loop ), loop = loop )(dly_trio , seen )
129129 assert res == 8
130130 assert seen .flag == 2
131131
132132 @pytest .mark .trio
133133 async def test_call_asyncio_ctx (self , loop ):
134134 self .did_it = 0
135- async with aio_as_trio (AioContext (self , loop )) as ctx :
135+ async with aio_as_trio (AioContext (self , loop ), loop = loop ) as ctx :
136136 assert ctx .parent is self
137137 assert self .did_it == 2
138138 self .did_it = 3
@@ -148,7 +148,7 @@ async def _call_trio_ctx():
148148 self .did_it = 3
149149 assert self .did_it == 4
150150
151- await aio_as_trio (_call_trio_ctx )()
151+ await aio_as_trio (_call_trio_ctx , loop = loop )()
152152
153153 @pytest .mark .trio
154154 async def test_call_trio_ctx_depr (self , loop ):
@@ -172,7 +172,7 @@ def dly_trio(seen):
172172 return 8
173173
174174 seen = Seen ()
175- res = await aio_as_trio (partial (self .call_a_ts , loop = loop ))(dly_trio , seen )
175+ res = await aio_as_trio (partial (self .call_a_ts , loop = loop ), loop = loop )(dly_trio , seen )
176176 assert res == 8
177177 assert seen .flag == 2
178178
@@ -193,7 +193,7 @@ def dly_trio(seen):
193193 @pytest .mark .trio
194194 async def test_trio_asyncio (self , loop ):
195195 async def dly_asyncio (seen ):
196- await asyncio .sleep (0.01 )
196+ await asyncio .sleep (0.01 , loop = loop )
197197 seen .flag |= 1
198198 return 4
199199
@@ -205,7 +205,7 @@ async def dly_asyncio(seen):
205205 @pytest .mark .trio
206206 async def test_trio_asyncio_depr (self , loop ):
207207 async def dly_asyncio (seen ):
208- await asyncio .sleep (0.01 )
208+ await asyncio .sleep (0.01 , loop = loop )
209209 seen .flag |= 1
210210 return 4
211211
@@ -221,7 +221,7 @@ async def err_trio():
221221 raise RuntimeError ("I has another owie" )
222222
223223 with pytest .raises (RuntimeError ) as err :
224- await aio_as_trio (partial (self .call_a_t , loop = loop ))(err_trio )
224+ await aio_as_trio (partial (self .call_a_t , loop = loop ), loop = loop )(err_trio )
225225 assert err .value .args [0 ] == "I has another owie"
226226
227227 @pytest .mark .trio
@@ -231,7 +231,7 @@ async def err_trio():
231231 raise RuntimeError ("I has another owie" )
232232
233233 with pytest .raises (RuntimeError ) as err :
234- await aio_as_trio (partial (self .call_a_t_depr , loop = loop ))(err_trio )
234+ await aio_as_trio (partial (self .call_a_t_depr , loop = loop ), loop = loop )(err_trio )
235235 assert err .value .args [0 ] == "I has another owie"
236236
237237 @pytest .mark .trio
@@ -253,8 +253,7 @@ async def err_trio():
253253
254254 with pytest .raises (RuntimeError ) as err :
255255 with test_utils .deprecate (self ):
256- await loop .run_asyncio (partial (self .call_a_t_depr ,
257- loop = loop ), err_trio )
256+ await loop .run_asyncio (partial (self .call_a_t_depr , loop = loop ), err_trio )
258257 assert err .value .args [0 ] == "I has another owie"
259258
260259 @pytest .mark .trio
@@ -264,7 +263,7 @@ def err_trio_sync():
264263 raise RuntimeError ("I has more owie" )
265264
266265 with pytest .raises (RuntimeError ) as err :
267- await aio_as_trio (partial (self .call_a_ts , loop = loop ))(err_trio_sync )
266+ await aio_as_trio (partial (self .call_a_ts , loop = loop ), loop = loop )(err_trio_sync )
268267 assert err .value .args [0 ] == "I has more owie"
269268
270269 @pytest .mark .trio
@@ -281,7 +280,7 @@ def err_trio_sync():
281280 @pytest .mark .trio
282281 async def test_trio_asyncio_error (self , loop ):
283282 async def err_asyncio ():
284- await asyncio .sleep (0.01 )
283+ await asyncio .sleep (0.01 , loop = loop )
285284 raise RuntimeError ("I has an owie" )
286285
287286 with pytest .raises (RuntimeError ) as err :
@@ -291,7 +290,7 @@ async def err_asyncio():
291290 @pytest .mark .trio
292291 async def test_trio_asyncio_error_depr (self , loop ):
293292 async def err_asyncio ():
294- await asyncio .sleep (0.01 )
293+ await asyncio .sleep (0.01 , loop = loop )
295294 raise RuntimeError ("I has an owie" )
296295
297296 with pytest .raises (RuntimeError ) as err :
@@ -311,21 +310,21 @@ async def cancelled_trio(seen):
311310
312311 seen = Seen ()
313312 with pytest .raises (asyncio .CancelledError ):
314- await aio_as_trio (partial (self .call_a_t , loop = loop ))(cancelled_trio , seen )
313+ await aio_as_trio (partial (self .call_a_t , loop = loop ), loop = loop )(cancelled_trio , seen )
315314 assert seen .flag == 3
316315
317316 @pytest .mark .trio
318317 async def test_trio_asyncio_cancel_out (self , loop ):
319318 async def cancelled_asyncio (seen ):
320319 seen .flag |= 1
321- await asyncio .sleep (0.01 )
322- f = asyncio .Future ()
320+ await asyncio .sleep (0.01 , loop = loop )
321+ f = asyncio .Future (loop = loop )
323322 f .cancel ()
324323 return f .result () # raises error
325324
326325 def cancelled_future (seen ):
327326 seen .flag |= 1
328- f = asyncio .Future ()
327+ f = asyncio .Future (loop = loop )
329328 f .cancel ()
330329 return f # contains error
331330
@@ -348,14 +347,14 @@ async def check_cancel(proc, seen):
348347 async def test_trio_asyncio_cancel_out_depr (self , loop ):
349348 async def cancelled_asyncio (seen ):
350349 seen .flag |= 1
351- await asyncio .sleep (0.01 )
352- f = asyncio .Future ()
350+ await asyncio .sleep (0.01 , loop = loop )
351+ f = asyncio .Future (loop = loop )
353352 f .cancel ()
354353 return f .result () # raises error
355354
356355 def cancelled_future (seen ):
357356 seen .flag |= 1
358- f = asyncio .Future ()
357+ f = asyncio .Future (loop = loop )
359358 f .cancel ()
360359 return f # contains error
361360
@@ -388,7 +387,7 @@ async def in_trio(started, seen):
388387 seen .flag |= 2
389388
390389 async def cancel_asyncio (seen ):
391- started = asyncio .Event ()
390+ started = asyncio .Event (loop = loop )
392391 f = asyncio .ensure_future (self .call_a_t (in_trio , started , seen , loop = loop ))
393392 await started .wait ()
394393 f .cancel ()
@@ -397,15 +396,15 @@ async def cancel_asyncio(seen):
397396 seen .flag |= 8
398397
399398 seen = Seen ()
400- await aio_as_trio (cancel_asyncio )(seen )
399+ await aio_as_trio (cancel_asyncio , loop = loop )(seen )
401400 assert seen .flag == 1 | 2 | 8
402401
403402 @pytest .mark .trio
404403 async def test_trio_asyncio_cancel_in (self , loop ):
405404 async def in_asyncio (started , seen ):
406405 started .set ()
407406 try :
408- await asyncio .sleep (9999 )
407+ await asyncio .sleep (9999 , loop = loop )
409408 except asyncio .CancelledError :
410409 seen .flag |= 1
411410 except trio .Cancelled :
@@ -432,7 +431,7 @@ async def test_trio_asyncio_cancel_in_depr(self, loop):
432431 async def in_asyncio (started , seen ):
433432 started .set ()
434433 try :
435- await asyncio .sleep (9999 )
434+ await asyncio .sleep (9999 , loop = loop )
436435 except asyncio .CancelledError :
437436 seen .flag |= 1
438437 except trio .Cancelled :
@@ -528,7 +527,7 @@ def err_asyncio():
528527 async def test_trio_asyncio_generator (self , loop ):
529528 async def dly_asyncio ():
530529 yield 1
531- await asyncio .sleep (0.01 )
530+ await asyncio .sleep (0.01 , loop = loop )
532531 yield 2
533532
534533 with test_utils .deprecate (self ):
@@ -558,7 +557,7 @@ async def cancel_soon(nursery):
558557 await trio .sleep (0.01 )
559558 nursery .cancel_scope .cancel ()
560559
561- hold = asyncio .Event ()
560+ hold = asyncio .Event (loop = loop )
562561 seen = Seen ()
563562
564563 with test_utils .deprecate (self ):
@@ -572,7 +571,7 @@ async def cancel_soon(nursery):
572571 async def test_trio_asyncio_iterator (self , loop ):
573572 async def slow_nums ():
574573 for n in range (1 , 6 ):
575- await asyncio .sleep (0.01 )
574+ await asyncio .sleep (0.01 , loop = loop )
576575 yield n
577576
578577 sum = 0
@@ -584,11 +583,13 @@ async def slow_nums():
584583 async def test_trio_asyncio_iterator_depr (self , loop ):
585584 async def slow_nums ():
586585 for n in range (1 , 6 ):
587- await asyncio .sleep (0.01 )
586+ await asyncio .sleep (0.01 , loop = loop )
588587 yield n
589588
590589 sum = 0
591590 # with test_utils.deprecate(self): ## not yet
592- async for n in aio_as_trio (slow_nums ()):
591+ async for n in aio_as_trio (
592+ slow_nums (), loop = loop
593+ ):
593594 sum += n
594595 assert sum == 15
0 commit comments