@@ -2561,8 +2561,9 @@ def test_event_loop_policy(self):
25612561 def test_get_event_loop (self ):
25622562 policy = asyncio .DefaultEventLoopPolicy ()
25632563 self .assertIsNone (policy ._local ._loop )
2564-
2565- loop = policy .get_event_loop ()
2564+ with self .assertWarns (DeprecationWarning ) as cm :
2565+ loop = policy .get_event_loop ()
2566+ self .assertEqual (cm .filename , __file__ )
25662567 self .assertIsInstance (loop , asyncio .AbstractEventLoop )
25672568
25682569 self .assertIs (policy ._local ._loop , loop )
@@ -2576,7 +2577,10 @@ def test_get_event_loop_calls_set_event_loop(self):
25762577 policy , "set_event_loop" ,
25772578 wraps = policy .set_event_loop ) as m_set_event_loop :
25782579
2579- loop = policy .get_event_loop ()
2580+ with self .assertWarns (DeprecationWarning ) as cm :
2581+ loop = policy .get_event_loop ()
2582+ self .addCleanup (loop .close )
2583+ self .assertEqual (cm .filename , __file__ )
25802584
25812585 # policy._local._loop must be set through .set_event_loop()
25822586 # (the unix DefaultEventLoopPolicy needs this call to attach
@@ -2610,7 +2614,8 @@ def test_new_event_loop(self):
26102614
26112615 def test_set_event_loop (self ):
26122616 policy = asyncio .DefaultEventLoopPolicy ()
2613- old_loop = policy .get_event_loop ()
2617+ old_loop = policy .new_event_loop ()
2618+ policy .set_event_loop (old_loop )
26142619
26152620 self .assertRaises (AssertionError , policy .set_event_loop , object ())
26162621
@@ -2723,15 +2728,11 @@ def get_event_loop(self):
27232728 asyncio .set_event_loop_policy (Policy ())
27242729 loop = asyncio .new_event_loop ()
27252730
2726- with self .assertWarns (DeprecationWarning ) as cm :
2727- with self .assertRaises (TestError ):
2728- asyncio .get_event_loop ()
2729- self .assertEqual (cm .warnings [0 ].filename , __file__ )
2731+ with self .assertRaises (TestError ):
2732+ asyncio .get_event_loop ()
27302733 asyncio .set_event_loop (None )
2731- with self .assertWarns (DeprecationWarning ) as cm :
2732- with self .assertRaises (TestError ):
2733- asyncio .get_event_loop ()
2734- self .assertEqual (cm .warnings [0 ].filename , __file__ )
2734+ with self .assertRaises (TestError ):
2735+ asyncio .get_event_loop ()
27352736
27362737 with self .assertRaisesRegex (RuntimeError , 'no running' ):
27372738 asyncio .get_running_loop ()
@@ -2745,16 +2746,11 @@ async def func():
27452746 loop .run_until_complete (func ())
27462747
27472748 asyncio .set_event_loop (loop )
2748- with self .assertWarns (DeprecationWarning ) as cm :
2749- with self .assertRaises (TestError ):
2750- asyncio .get_event_loop ()
2751- self .assertEqual (cm .warnings [0 ].filename , __file__ )
2752-
2749+ with self .assertRaises (TestError ):
2750+ asyncio .get_event_loop ()
27532751 asyncio .set_event_loop (None )
2754- with self .assertWarns (DeprecationWarning ) as cm :
2755- with self .assertRaises (TestError ):
2756- asyncio .get_event_loop ()
2757- self .assertEqual (cm .warnings [0 ].filename , __file__ )
2752+ with self .assertRaises (TestError ):
2753+ asyncio .get_event_loop ()
27582754
27592755 finally :
27602756 asyncio .set_event_loop_policy (old_policy )
@@ -2778,10 +2774,8 @@ def test_get_event_loop_returns_running_loop2(self):
27782774 self .addCleanup (loop2 .close )
27792775 self .assertEqual (cm .warnings [0 ].filename , __file__ )
27802776 asyncio .set_event_loop (None )
2781- with self .assertWarns (DeprecationWarning ) as cm :
2782- with self .assertRaisesRegex (RuntimeError , 'no current' ):
2783- asyncio .get_event_loop ()
2784- self .assertEqual (cm .warnings [0 ].filename , __file__ )
2777+ with self .assertRaisesRegex (RuntimeError , 'no current' ):
2778+ asyncio .get_event_loop ()
27852779
27862780 with self .assertRaisesRegex (RuntimeError , 'no running' ):
27872781 asyncio .get_running_loop ()
@@ -2795,15 +2789,11 @@ async def func():
27952789 loop .run_until_complete (func ())
27962790
27972791 asyncio .set_event_loop (loop )
2798- with self .assertWarns (DeprecationWarning ) as cm :
2799- self .assertIs (asyncio .get_event_loop (), loop )
2800- self .assertEqual (cm .warnings [0 ].filename , __file__ )
2792+ self .assertIs (asyncio .get_event_loop (), loop )
28012793
28022794 asyncio .set_event_loop (None )
2803- with self .assertWarns (DeprecationWarning ) as cm :
2804- with self .assertRaisesRegex (RuntimeError , 'no current' ):
2805- asyncio .get_event_loop ()
2806- self .assertEqual (cm .warnings [0 ].filename , __file__ )
2795+ with self .assertRaisesRegex (RuntimeError , 'no current' ):
2796+ asyncio .get_event_loop ()
28072797
28082798 finally :
28092799 asyncio .set_event_loop_policy (old_policy )
0 commit comments