@@ -2550,29 +2550,8 @@ def test_event_loop_policy(self):
2550
2550
def test_get_event_loop (self ):
2551
2551
policy = asyncio .DefaultEventLoopPolicy ()
2552
2552
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 ()
2576
2555
2577
2556
def test_get_event_loop_after_set_none (self ):
2578
2557
policy = asyncio .DefaultEventLoopPolicy ()
@@ -2599,7 +2578,8 @@ def test_new_event_loop(self):
2599
2578
2600
2579
def test_set_event_loop (self ):
2601
2580
policy = asyncio .DefaultEventLoopPolicy ()
2602
- old_loop = policy .get_event_loop ()
2581
+ old_loop = policy .new_event_loop ()
2582
+ policy .set_event_loop (old_loop )
2603
2583
2604
2584
self .assertRaises (TypeError , policy .set_event_loop , object ())
2605
2585
@@ -2716,15 +2696,11 @@ def get_event_loop(self):
2716
2696
asyncio .set_event_loop_policy (Policy ())
2717
2697
loop = asyncio .new_event_loop ()
2718
2698
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 ()
2723
2701
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 ()
2728
2704
2729
2705
with self .assertRaisesRegex (RuntimeError , 'no running' ):
2730
2706
asyncio .get_running_loop ()
@@ -2738,16 +2714,11 @@ async def func():
2738
2714
loop .run_until_complete (func ())
2739
2715
2740
2716
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 ()
2746
2719
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 ()
2751
2722
2752
2723
finally :
2753
2724
asyncio .set_event_loop_policy (old_policy )
@@ -2766,15 +2737,11 @@ def test_get_event_loop_returns_running_loop2(self):
2766
2737
loop = asyncio .new_event_loop ()
2767
2738
self .addCleanup (loop .close )
2768
2739
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 ()
2773
2742
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 ()
2778
2745
2779
2746
with self .assertRaisesRegex (RuntimeError , 'no running' ):
2780
2747
asyncio .get_running_loop ()
@@ -2788,15 +2755,11 @@ async def func():
2788
2755
loop .run_until_complete (func ())
2789
2756
2790
2757
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 )
2794
2759
2795
2760
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 ()
2800
2763
2801
2764
finally :
2802
2765
asyncio .set_event_loop_policy (old_policy )
0 commit comments