36
36
from test .support import socket_helper
37
37
from test .support import threading_helper
38
38
from test .support import ALWAYS_EQ , LARGEST , SMALLEST
39
-
39
+ from test . support import warnings_helper
40
40
41
41
def tearDownModule ():
42
- asyncio .set_event_loop_policy (None )
42
+ asyncio ._set_event_loop_policy (None )
43
43
44
44
45
45
def broken_unix_getsockname ():
@@ -2764,13 +2764,17 @@ def test_get_event_loop_policy(self):
2764
2764
self .assertIs (policy , asyncio .get_event_loop_policy ())
2765
2765
2766
2766
def test_set_event_loop_policy (self ):
2767
- self .assertRaises (
2768
- TypeError , asyncio .set_event_loop_policy , object ())
2767
+ with self .assertWarnsRegex (
2768
+ DeprecationWarning , "'set_event_loop_policy' is deprecated" ):
2769
+ self .assertRaises (
2770
+ TypeError , asyncio .set_event_loop_policy , object ())
2769
2771
2770
2772
old_policy = asyncio .get_event_loop_policy ()
2771
2773
2772
2774
policy = asyncio .DefaultEventLoopPolicy ()
2773
- asyncio .set_event_loop_policy (policy )
2775
+ with self .assertWarnsRegex (
2776
+ DeprecationWarning , "'set_event_loop_policy' is deprecated" ):
2777
+ asyncio .set_event_loop_policy (policy )
2774
2778
self .assertIs (policy , asyncio .get_event_loop_policy ())
2775
2779
self .assertIsNot (policy , old_policy )
2776
2780
@@ -2857,7 +2861,7 @@ def get_event_loop(self):
2857
2861
2858
2862
old_policy = asyncio .get_event_loop_policy ()
2859
2863
try :
2860
- asyncio .set_event_loop_policy (Policy ())
2864
+ asyncio ._set_event_loop_policy (Policy ())
2861
2865
loop = asyncio .new_event_loop ()
2862
2866
2863
2867
with self .assertRaises (TestError ):
@@ -2885,7 +2889,7 @@ async def func():
2885
2889
asyncio .get_event_loop ()
2886
2890
2887
2891
finally :
2888
- asyncio .set_event_loop_policy (old_policy )
2892
+ asyncio ._set_event_loop_policy (old_policy )
2889
2893
if loop is not None :
2890
2894
loop .close ()
2891
2895
@@ -2897,7 +2901,7 @@ async def func():
2897
2901
def test_get_event_loop_returns_running_loop2 (self ):
2898
2902
old_policy = asyncio .get_event_loop_policy ()
2899
2903
try :
2900
- asyncio .set_event_loop_policy (asyncio .DefaultEventLoopPolicy ())
2904
+ asyncio ._set_event_loop_policy (asyncio .DefaultEventLoopPolicy ())
2901
2905
loop = asyncio .new_event_loop ()
2902
2906
self .addCleanup (loop .close )
2903
2907
@@ -2923,7 +2927,7 @@ async def func():
2923
2927
asyncio .get_event_loop ()
2924
2928
2925
2929
finally :
2926
- asyncio .set_event_loop_policy (old_policy )
2930
+ asyncio ._set_event_loop_policy (old_policy )
2927
2931
if loop is not None :
2928
2932
loop .close ()
2929
2933
0 commit comments