@@ -9,7 +9,7 @@ class at a time.
99"""
1010
1111import asyncio
12- from collections .abc import AsyncIterator , Iterator
12+ from collections .abc import AsyncIterator
1313from typing import Any
1414
1515import async_solipsism
@@ -33,17 +33,11 @@ class TestSelect:
3333 recv1 : Event
3434 recv2 : Event
3535 recv3 : Event
36- loop : async_solipsism .EventLoop
3736
3837 @pytest .fixture (autouse = True )
39- def event_loop (
40- self , request : pytest .FixtureRequest
41- ) -> Iterator [async_solipsism .EventLoop ]:
42- """Replace the loop with one that doesn't interact with the outside world."""
43- loop = async_solipsism .EventLoop ()
44- request .cls .loop = loop
45- yield loop
46- loop .close ()
38+ def event_loop_policy (self ) -> async_solipsism .EventLoopPolicy :
39+ """Return an event loop policy that uses the async solipsism event loop."""
40+ return async_solipsism .EventLoopPolicy ()
4741
4842 @pytest .fixture ()
4943 async def start_run_ordered_sequence (self ) -> AsyncIterator [asyncio .Task [None ]]:
@@ -92,10 +86,16 @@ def assert_received_from(
9286 assert selected .exception is None
9387 assert not selected .was_stopped
9488 if expected_pending_tasks > 0 :
95- assert len (asyncio .all_tasks (self .loop )) == expected_pending_tasks
89+ assert (
90+ len (asyncio .all_tasks (asyncio .get_event_loop ()))
91+ == expected_pending_tasks
92+ )
9693 elif expected_pending_tasks < 0 :
97- assert len (asyncio .all_tasks (self .loop )) > expected_pending_tasks
98- assert self .loop .time () == at_time
94+ assert (
95+ len (asyncio .all_tasks (asyncio .get_event_loop ()))
96+ > expected_pending_tasks
97+ )
98+ assert asyncio .get_event_loop ().time () == at_time
9999
100100 def assert_receiver_stopped (
101101 self ,
@@ -125,10 +125,16 @@ def assert_receiver_stopped(
125125 assert isinstance (selected .exception , ReceiverStoppedError )
126126 assert selected .exception .receiver is receiver
127127 if expected_pending_tasks > 0 :
128- assert len (asyncio .all_tasks (self .loop )) == expected_pending_tasks
128+ assert (
129+ len (asyncio .all_tasks (asyncio .get_event_loop ()))
130+ == expected_pending_tasks
131+ )
129132 elif expected_pending_tasks < 0 :
130- assert len (asyncio .all_tasks (self .loop )) > expected_pending_tasks
131- assert self .loop .time () == at_time
133+ assert (
134+ len (asyncio .all_tasks (asyncio .get_event_loop ()))
135+ > expected_pending_tasks
136+ )
137+ assert asyncio .get_event_loop ().time () == at_time
132138
133139 # We use the loop time (and the sleeps in the run_ordered_sequence method) mainly to
134140 # ensure we are processing the events in the correct order and we are really
@@ -362,11 +368,11 @@ async def test_multiple_ready(
362368 Also test that the loop waits forever if there are no more receivers ready.
363369 """
364370 received : set [str ] = set ()
365- last_time : float = self . loop .time ()
371+ last_time : float = asyncio . get_event_loop () .time ()
366372 try :
367373 async with asyncio .timeout (15 ):
368374 async for selected in select (self .recv1 , self .recv2 , self .recv3 ):
369- now = self . loop .time ()
375+ now = asyncio . get_event_loop () .time ()
370376 if now != last_time : # Only check when there was a jump in time
371377 match now :
372378 case 1 :
@@ -401,7 +407,7 @@ async def test_multiple_ready(
401407 else :
402408 assert False , "Should not reach this point"
403409 except asyncio .TimeoutError :
404- assert self . loop .time () == 15
410+ assert asyncio . get_event_loop () .time () == 15
405411 # This happened after time == 3, but the loop never resumes because
406412 # there is nothing ready, so we need to check it after the timeout.
407413 assert received == {
0 commit comments