@@ -2547,8 +2547,9 @@ def test_event_loop_policy(self):
25472547 def test_get_event_loop (self ):
25482548 policy = asyncio .DefaultEventLoopPolicy ()
25492549 self .assertIsNone (policy ._local ._loop )
2550-
2551- loop = policy .get_event_loop ()
2550+ with self .assertWarns (DeprecationWarning ) as cm :
2551+ loop = policy .get_event_loop ()
2552+ self .assertEqual (cm .filename , __file__ )
25522553 self .assertIsInstance (loop , asyncio .AbstractEventLoop )
25532554
25542555 self .assertIs (policy ._local ._loop , loop )
@@ -2562,7 +2563,10 @@ def test_get_event_loop_calls_set_event_loop(self):
25622563 policy , "set_event_loop" ,
25632564 wraps = policy .set_event_loop ) as m_set_event_loop :
25642565
2565- loop = policy .get_event_loop ()
2566+ with self .assertWarns (DeprecationWarning ) as cm :
2567+ loop = policy .get_event_loop ()
2568+ self .addCleanup (loop .close )
2569+ self .assertEqual (cm .filename , __file__ )
25662570
25672571 # policy._local._loop must be set through .set_event_loop()
25682572 # (the unix DefaultEventLoopPolicy needs this call to attach
@@ -2596,7 +2600,8 @@ def test_new_event_loop(self):
25962600
25972601 def test_set_event_loop (self ):
25982602 policy = asyncio .DefaultEventLoopPolicy ()
2599- old_loop = policy .get_event_loop ()
2603+ old_loop = policy .new_event_loop ()
2604+ policy .set_event_loop (old_loop )
26002605
26012606 self .assertRaises (TypeError , policy .set_event_loop , object ())
26022607
@@ -2709,15 +2714,11 @@ def get_event_loop(self):
27092714 asyncio .set_event_loop_policy (Policy ())
27102715 loop = asyncio .new_event_loop ()
27112716
2712- with self .assertWarns (DeprecationWarning ) as cm :
2713- with self .assertRaises (TestError ):
2714- asyncio .get_event_loop ()
2715- self .assertEqual (cm .filename , __file__ )
2717+ with self .assertRaises (TestError ):
2718+ asyncio .get_event_loop ()
27162719 asyncio .set_event_loop (None )
2717- with self .assertWarns (DeprecationWarning ) as cm :
2718- with self .assertRaises (TestError ):
2719- asyncio .get_event_loop ()
2720- self .assertEqual (cm .filename , __file__ )
2720+ with self .assertRaises (TestError ):
2721+ asyncio .get_event_loop ()
27212722
27222723 with self .assertRaisesRegex (RuntimeError , 'no running' ):
27232724 asyncio .get_running_loop ()
@@ -2731,16 +2732,11 @@ async def func():
27312732 loop .run_until_complete (func ())
27322733
27332734 asyncio .set_event_loop (loop )
2734- with self .assertWarns (DeprecationWarning ) as cm :
2735- with self .assertRaises (TestError ):
2736- asyncio .get_event_loop ()
2737- self .assertEqual (cm .filename , __file__ )
2738-
2735+ with self .assertRaises (TestError ):
2736+ asyncio .get_event_loop ()
27392737 asyncio .set_event_loop (None )
2740- with self .assertWarns (DeprecationWarning ) as cm :
2741- with self .assertRaises (TestError ):
2742- asyncio .get_event_loop ()
2743- self .assertEqual (cm .filename , __file__ )
2738+ with self .assertRaises (TestError ):
2739+ asyncio .get_event_loop ()
27442740
27452741 finally :
27462742 asyncio .set_event_loop_policy (old_policy )
@@ -2764,10 +2760,8 @@ def test_get_event_loop_returns_running_loop2(self):
27642760 self .addCleanup (loop2 .close )
27652761 self .assertEqual (cm .filename , __file__ )
27662762 asyncio .set_event_loop (None )
2767- with self .assertWarns (DeprecationWarning ) as cm :
2768- with self .assertRaisesRegex (RuntimeError , 'no current' ):
2769- asyncio .get_event_loop ()
2770- self .assertEqual (cm .filename , __file__ )
2763+ with self .assertRaisesRegex (RuntimeError , 'no current' ):
2764+ asyncio .get_event_loop ()
27712765
27722766 with self .assertRaisesRegex (RuntimeError , 'no running' ):
27732767 asyncio .get_running_loop ()
@@ -2781,15 +2775,11 @@ async def func():
27812775 loop .run_until_complete (func ())
27822776
27832777 asyncio .set_event_loop (loop )
2784- with self .assertWarns (DeprecationWarning ) as cm :
2785- self .assertIs (asyncio .get_event_loop (), loop )
2786- self .assertEqual (cm .filename , __file__ )
2778+ self .assertIs (asyncio .get_event_loop (), loop )
27872779
27882780 asyncio .set_event_loop (None )
2789- with self .assertWarns (DeprecationWarning ) as cm :
2790- with self .assertRaisesRegex (RuntimeError , 'no current' ):
2791- asyncio .get_event_loop ()
2792- self .assertEqual (cm .filename , __file__ )
2781+ with self .assertRaisesRegex (RuntimeError , 'no current' ):
2782+ asyncio .get_event_loop ()
27932783
27942784 finally :
27952785 asyncio .set_event_loop_policy (old_policy )
0 commit comments