@@ -2550,29 +2550,8 @@ def test_event_loop_policy(self):
25502550 def test_get_event_loop (self ):
25512551 policy = asyncio .DefaultEventLoopPolicy ()
25522552 self .assertIsNone (policy ._local ._loop )
2553-
2554- loop = policy .get_event_loop ()
2555- self .assertIsInstance (loop , asyncio .AbstractEventLoop )
2556-
2557- self .assertIs (policy ._local ._loop , loop )
2558- self .assertIs (loop , policy .get_event_loop ())
2559- loop .close ()
2560-
2561- def test_get_event_loop_calls_set_event_loop (self ):
2562- policy = asyncio .DefaultEventLoopPolicy ()
2563-
2564- with mock .patch .object (
2565- policy , "set_event_loop" ,
2566- wraps = policy .set_event_loop ) as m_set_event_loop :
2567-
2568- loop = policy .get_event_loop ()
2569-
2570- # policy._local._loop must be set through .set_event_loop()
2571- # (the unix DefaultEventLoopPolicy needs this call to attach
2572- # the child watcher correctly)
2573- m_set_event_loop .assert_called_with (loop )
2574-
2575- loop .close ()
2553+ with self .assertRaisesRegex (RuntimeError , 'no current event loop' ):
2554+ policy .get_event_loop ()
25762555
25772556 def test_get_event_loop_after_set_none (self ):
25782557 policy = asyncio .DefaultEventLoopPolicy ()
@@ -2599,7 +2578,8 @@ def test_new_event_loop(self):
25992578
26002579 def test_set_event_loop (self ):
26012580 policy = asyncio .DefaultEventLoopPolicy ()
2602- old_loop = policy .get_event_loop ()
2581+ old_loop = policy .new_event_loop ()
2582+ policy .set_event_loop (old_loop )
26032583
26042584 self .assertRaises (TypeError , policy .set_event_loop , object ())
26052585
@@ -2716,15 +2696,11 @@ def get_event_loop(self):
27162696 asyncio .set_event_loop_policy (Policy ())
27172697 loop = asyncio .new_event_loop ()
27182698
2719- with self .assertWarns (DeprecationWarning ) as cm :
2720- with self .assertRaises (TestError ):
2721- asyncio .get_event_loop ()
2722- self .assertEqual (cm .filename , __file__ )
2699+ with self .assertRaises (TestError ):
2700+ asyncio .get_event_loop ()
27232701 asyncio .set_event_loop (None )
2724- with self .assertWarns (DeprecationWarning ) as cm :
2725- with self .assertRaises (TestError ):
2726- asyncio .get_event_loop ()
2727- self .assertEqual (cm .filename , __file__ )
2702+ with self .assertRaises (TestError ):
2703+ asyncio .get_event_loop ()
27282704
27292705 with self .assertRaisesRegex (RuntimeError , 'no running' ):
27302706 asyncio .get_running_loop ()
@@ -2738,16 +2714,11 @@ async def func():
27382714 loop .run_until_complete (func ())
27392715
27402716 asyncio .set_event_loop (loop )
2741- with self .assertWarns (DeprecationWarning ) as cm :
2742- with self .assertRaises (TestError ):
2743- asyncio .get_event_loop ()
2744- self .assertEqual (cm .filename , __file__ )
2745-
2717+ with self .assertRaises (TestError ):
2718+ asyncio .get_event_loop ()
27462719 asyncio .set_event_loop (None )
2747- with self .assertWarns (DeprecationWarning ) as cm :
2748- with self .assertRaises (TestError ):
2749- asyncio .get_event_loop ()
2750- self .assertEqual (cm .filename , __file__ )
2720+ with self .assertRaises (TestError ):
2721+ asyncio .get_event_loop ()
27512722
27522723 finally :
27532724 asyncio .set_event_loop_policy (old_policy )
@@ -2766,15 +2737,11 @@ def test_get_event_loop_returns_running_loop2(self):
27662737 loop = asyncio .new_event_loop ()
27672738 self .addCleanup (loop .close )
27682739
2769- with self .assertWarns (DeprecationWarning ) as cm :
2770- loop2 = asyncio .get_event_loop ()
2771- self .addCleanup (loop2 .close )
2772- self .assertEqual (cm .filename , __file__ )
2740+ with self .assertRaisesRegex (RuntimeError , 'no current' ):
2741+ asyncio .get_event_loop ()
27732742 asyncio .set_event_loop (None )
2774- with self .assertWarns (DeprecationWarning ) as cm :
2775- with self .assertRaisesRegex (RuntimeError , 'no current' ):
2776- asyncio .get_event_loop ()
2777- self .assertEqual (cm .filename , __file__ )
2743+ with self .assertRaisesRegex (RuntimeError , 'no current' ):
2744+ asyncio .get_event_loop ()
27782745
27792746 with self .assertRaisesRegex (RuntimeError , 'no running' ):
27802747 asyncio .get_running_loop ()
@@ -2788,15 +2755,11 @@ async def func():
27882755 loop .run_until_complete (func ())
27892756
27902757 asyncio .set_event_loop (loop )
2791- with self .assertWarns (DeprecationWarning ) as cm :
2792- self .assertIs (asyncio .get_event_loop (), loop )
2793- self .assertEqual (cm .filename , __file__ )
2758+ self .assertIs (asyncio .get_event_loop (), loop )
27942759
27952760 asyncio .set_event_loop (None )
2796- with self .assertWarns (DeprecationWarning ) as cm :
2797- with self .assertRaisesRegex (RuntimeError , 'no current' ):
2798- asyncio .get_event_loop ()
2799- self .assertEqual (cm .filename , __file__ )
2761+ with self .assertRaisesRegex (RuntimeError , 'no current' ):
2762+ asyncio .get_event_loop ()
28002763
28012764 finally :
28022765 asyncio .set_event_loop_policy (old_policy )
0 commit comments