@@ -2704,33 +2704,22 @@ def test_event_loop_policy(self):
2704
2704
def test_get_event_loop (self ):
2705
2705
policy = asyncio .DefaultEventLoopPolicy ()
2706
2706
self .assertIsNone (policy ._local ._loop )
2707
- with self .assertWarns (DeprecationWarning ) as cm :
2708
- loop = policy .get_event_loop ()
2709
- self .assertEqual (cm .filename , __file__ )
2710
- self .assertIsInstance (loop , asyncio .AbstractEventLoop )
2711
2707
2712
- self .assertIs ( policy . _local . _loop , loop )
2713
- self . assertIs ( loop , policy .get_event_loop () )
2714
- loop . close ( )
2708
+ with self .assertRaises ( RuntimeError ):
2709
+ loop = policy .get_event_loop ()
2710
+ self . assertIsNone ( policy . _local . _loop )
2715
2711
2716
- def test_get_event_loop_calls_set_event_loop (self ):
2712
+ def test_get_event_loop_does_not_call_set_event_loop (self ):
2717
2713
policy = asyncio .DefaultEventLoopPolicy ()
2718
2714
2719
2715
with mock .patch .object (
2720
2716
policy , "set_event_loop" ,
2721
2717
wraps = policy .set_event_loop ) as m_set_event_loop :
2722
2718
2723
- with self .assertWarns ( DeprecationWarning ) as cm :
2719
+ with self .assertRaises ( RuntimeError ) :
2724
2720
loop = policy .get_event_loop ()
2725
- self .addCleanup (loop .close )
2726
- self .assertEqual (cm .filename , __file__ )
2727
2721
2728
- # policy._local._loop must be set through .set_event_loop()
2729
- # (the unix DefaultEventLoopPolicy needs this call to attach
2730
- # the child watcher correctly)
2731
- m_set_event_loop .assert_called_with (loop )
2732
-
2733
- loop .close ()
2722
+ m_set_event_loop .assert_not_called ()
2734
2723
2735
2724
def test_get_event_loop_after_set_none (self ):
2736
2725
policy = asyncio .DefaultEventLoopPolicy ()
@@ -2912,17 +2901,12 @@ def test_get_event_loop_returns_running_loop2(self):
2912
2901
loop = asyncio .new_event_loop ()
2913
2902
self .addCleanup (loop .close )
2914
2903
2915
- with self .assertWarns (DeprecationWarning ) as cm :
2916
- loop2 = asyncio .get_event_loop ()
2917
- self .addCleanup (loop2 .close )
2918
- self .assertEqual (cm .filename , __file__ )
2919
- asyncio .set_event_loop (None )
2920
2904
with self .assertRaisesRegex (RuntimeError , 'no current' ):
2921
2905
asyncio .get_event_loop ()
2922
2906
2923
- with self . assertRaisesRegex ( RuntimeError , 'no running' ):
2924
- asyncio . get_running_loop ()
2925
- self . assertIs ( asyncio ._get_running_loop (), None )
2907
+ asyncio . set_event_loop ( None )
2908
+ with self . assertRaisesRegex ( RuntimeError , 'no current' ):
2909
+ asyncio .get_event_loop ( )
2926
2910
2927
2911
async def func ():
2928
2912
self .assertIs (asyncio .get_event_loop (), loop )
0 commit comments