Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a7fe31c

Browse filesBrowse files
committed
add support.set_event_loop_policy for setting the event loop policy in tests
1 parent 43cbdb2 commit a7fe31c
Copy full SHA for a7fe31c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner

44 files changed

+86
-64
lines changed

‎Lib/test/libregrtest/save_env.py

Copy file name to clipboardExpand all lines: Lib/test/libregrtest/save_env.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def get_asyncio_events__event_loop_policy(self):
9797
return support.maybe_get_event_loop_policy()
9898
def restore_asyncio_events__event_loop_policy(self, policy):
9999
asyncio = self.get_module('asyncio')
100-
asyncio.set_event_loop_policy(policy)
100+
support.set_event_loop_policy(policy)
101101

102102
def get_sys_argv(self):
103103
return id(sys.argv), sys.argv, sys.argv[:]

‎Lib/test/support/__init__.py

Copy file name to clipboardExpand all lines: Lib/test/support/__init__.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,13 @@ def maybe_get_event_loop_policy():
20892089
import asyncio.events
20902090
return asyncio.events._event_loop_policy
20912091

2092+
def set_event_loop_policy(policy):
2093+
"""Set the global event loop policy ignoring deprecation warnings"""
2094+
import asyncio
2095+
with warnings.catch_warnings():
2096+
warnings.simplefilter("ignore", DeprecationWarning)
2097+
asyncio.set_event_loop_policy(policy)
2098+
20922099
# Helpers for testing hashing.
20932100
NHASHBITS = sys.hash_info.width # number of bits in hash() result
20942101
assert NHASHBITS in (32, 64)

‎Lib/test/test_asyncgen.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncgen.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def setUp(self):
429429
def tearDown(self):
430430
self.loop.close()
431431
self.loop = None
432-
asyncio.set_event_loop_policy(None)
432+
support.set_event_loop_policy(None)
433433

434434
def check_async_iterator_anext(self, ait_class):
435435
with self.subTest(anext="pure-Python"):

‎Lib/test/test_asyncio/test_base_events.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_base_events.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
def tearDownModule():
27-
asyncio.set_event_loop_policy(None)
27+
support.set_event_loop_policy(None)
2828

2929

3030
def mock_socket_module():

‎Lib/test/test_asyncio/test_buffered_proto.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_buffered_proto.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import unittest
33

44
from test.test_asyncio import functional as func_tests
5+
from test import support
56

67

78
def tearDownModule():
8-
asyncio.set_event_loop_policy(None)
9+
support.set_event_loop_policy(None)
910

1011

1112
class ReceiveStuffProto(asyncio.BufferedProtocol):

‎Lib/test/test_asyncio/test_context.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_context.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import asyncio
22
import decimal
33
import unittest
4+
from test import support
45

56

67
def tearDownModule():
7-
asyncio.set_event_loop_policy(None)
8+
support.set_event_loop_policy(None)
89

910

1011
@unittest.skipUnless(decimal.HAVE_CONTEXTVAR, "decimal is built with a thread-local context")

‎Lib/test/test_asyncio/test_eager_task_factory.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_eager_task_factory.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
from asyncio import tasks
99
from test.test_asyncio import utils as test_utils
1010
from test.support.script_helper import assert_python_ok
11+
from test import support
1112

1213
MOCK_ANY = mock.ANY
1314

1415

1516
def tearDownModule():
16-
asyncio.set_event_loop_policy(None)
17+
support.set_event_loop_policy(None)
1718

1819

1920
class EagerTaskFactoryLoopTests:

‎Lib/test/test_asyncio/test_events.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_events.py
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040

4141
def tearDownModule():
42-
asyncio.set_event_loop_policy(None)
42+
support.set_event_loop_policy(None)
4343

4444

4545
def broken_unix_getsockname():
@@ -2684,8 +2684,9 @@ def test_get_event_loop_policy(self):
26842684
self.assertIs(policy, asyncio.get_event_loop_policy())
26852685

26862686
def test_set_event_loop_policy(self):
2687-
self.assertRaises(
2688-
TypeError, asyncio.set_event_loop_policy, object())
2687+
with self.assertWarns(DeprecationWarning):
2688+
self.assertRaises(
2689+
TypeError, asyncio.set_event_loop_policy, object())
26892690

26902691
old_policy = asyncio.get_event_loop_policy()
26912692

@@ -2790,7 +2791,8 @@ def get_event_loop(self):
27902791

27912792
old_policy = asyncio.get_event_loop_policy()
27922793
try:
2793-
asyncio.set_event_loop_policy(Policy())
2794+
with self.assertWarns(DeprecationWarning):
2795+
asyncio.set_event_loop_policy(Policy())
27942796
loop = asyncio.new_event_loop()
27952797

27962798
with self.assertRaises(TestError):
@@ -2818,7 +2820,7 @@ async def func():
28182820
asyncio.get_event_loop()
28192821

28202822
finally:
2821-
asyncio.set_event_loop_policy(old_policy)
2823+
support.set_event_loop_policy(old_policy)
28222824
if loop is not None:
28232825
loop.close()
28242826

@@ -2830,7 +2832,8 @@ async def func():
28302832
def test_get_event_loop_returns_running_loop2(self):
28312833
old_policy = asyncio.get_event_loop_policy()
28322834
try:
2833-
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
2835+
with self.assertWarns(DeprecationWarning):
2836+
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
28342837
loop = asyncio.new_event_loop()
28352838
self.addCleanup(loop.close)
28362839

@@ -2861,7 +2864,7 @@ async def func():
28612864
asyncio.get_event_loop()
28622865

28632866
finally:
2864-
asyncio.set_event_loop_policy(old_policy)
2867+
support.set_event_loop_policy(old_policy)
28652868
if loop is not None:
28662869
loop.close()
28672870

‎Lib/test/test_asyncio/test_futures.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_futures.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
def tearDownModule():
19-
asyncio.set_event_loop_policy(None)
19+
support.set_event_loop_policy(None)
2020

2121

2222
def _fakefunc(f):

‎Lib/test/test_asyncio/test_futures2.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_futures2.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def tearDownModule():
10-
asyncio.set_event_loop_policy(None)
10+
support.set_event_loop_policy(None)
1111

1212

1313
class FutureTests:

‎Lib/test/test_asyncio/test_locks.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_locks.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import asyncio
88
import collections
9+
from test import support
910

1011
STR_RGX_REPR = (
1112
r'^<(?P<class>.*?) object at (?P<address>.*?)'
@@ -20,7 +21,7 @@
2021

2122

2223
def tearDownModule():
23-
asyncio.set_event_loop_policy(None)
24+
support.set_event_loop_policy(None)
2425

2526

2627
class LockTests(unittest.IsolatedAsyncioTestCase):

‎Lib/test/test_asyncio/test_pep492.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_pep492.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
import asyncio
1010
from test.test_asyncio import utils as test_utils
11+
from test import support
1112

1213

1314
def tearDownModule():
14-
asyncio.set_event_loop_policy(None)
15+
support.set_event_loop_policy(None)
1516

1617

1718
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine

‎Lib/test/test_asyncio/test_proactor_events.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_proactor_events.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
from test.support import os_helper
1616
from test.support import socket_helper
1717
from test.test_asyncio import utils as test_utils
18+
from test import support
1819

1920

2021
def tearDownModule():
21-
asyncio.set_event_loop_policy(None)
22+
support.set_event_loop_policy(None)
2223

2324

2425
def close_transport(transport):

‎Lib/test/test_asyncio/test_protocols.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_protocols.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from unittest import mock
33

44
import asyncio
5+
from test import support
56

67

78
def tearDownModule():
89
# not needed for the test file but added for uniformness with all other
910
# asyncio test files for the sake of unified cleanup
10-
asyncio.set_event_loop_policy(None)
11+
support.set_event_loop_policy(None)
1112

1213

1314
class ProtocolsAbsTests(unittest.TestCase):

‎Lib/test/test_asyncio/test_queues.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_queues.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import asyncio
44
import unittest
55
from types import GenericAlias
6+
from test import support
67

78

89
def tearDownModule():
9-
asyncio.set_event_loop_policy(None)
10+
support.set_event_loop_policy(None)
1011

1112

1213
class QueueBasicTests(unittest.IsolatedAsyncioTestCase):

‎Lib/test/test_asyncio/test_runners.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_runners.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def tearDownModule():
14-
asyncio.set_event_loop_policy(None)
14+
support.set_event_loop_policy(None)
1515

1616

1717
def interrupt_self():
@@ -60,15 +60,15 @@ def setUp(self):
6060
super().setUp()
6161

6262
policy = TestPolicy(self.new_loop)
63-
asyncio.set_event_loop_policy(policy)
63+
support.set_event_loop_policy(policy)
6464

6565
def tearDown(self):
6666
policy = asyncio.get_event_loop_policy()
6767
if policy.loop is not None:
6868
self.assertTrue(policy.loop.is_closed())
6969
self.assertTrue(policy.loop.shutdown_ag_run)
7070

71-
asyncio.set_event_loop_policy(None)
71+
support.set_event_loop_policy(None)
7272
super().tearDown()
7373

7474

@@ -258,7 +258,7 @@ def new_event_loop():
258258
loop.set_task_factory(Task)
259259
return loop
260260

261-
asyncio.set_event_loop_policy(TestPolicy(new_event_loop))
261+
support.set_event_loop_policy(TestPolicy(new_event_loop))
262262
with self.assertRaises(asyncio.CancelledError):
263263
asyncio.run(main())
264264

‎Lib/test/test_asyncio/test_selector_events.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_selector_events.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
_SelectorSocketTransport,
2020
_SelectorTransport)
2121
from test.test_asyncio import utils as test_utils
22+
from test import support
2223

2324
MOCK_ANY = mock.ANY
2425

2526

2627
def tearDownModule():
27-
asyncio.set_event_loop_policy(None)
28+
support.set_event_loop_policy(None)
2829

2930

3031
class TestBaseSelectorEventLoop(BaseSelectorEventLoop):

‎Lib/test/test_asyncio/test_sendfile.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_sendfile.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
def tearDownModule():
25-
asyncio.set_event_loop_policy(None)
25+
support.set_event_loop_policy(None)
2626

2727

2828
class MySendfileProto(asyncio.Protocol):

‎Lib/test/test_asyncio/test_server.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_server.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
from test.support import socket_helper
77
from test.test_asyncio import utils as test_utils
88
from test.test_asyncio import functional as func_tests
9+
from test import support
910

1011

1112
def tearDownModule():
12-
asyncio.set_event_loop_policy(None)
13+
support.set_event_loop_policy(None)
1314

1415

1516
class BaseStartServer(func_tests.FunctionalTestCaseMixin):

‎Lib/test/test_asyncio/test_sock_lowlevel.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_sock_lowlevel.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
def tearDownModule():
18-
asyncio.set_event_loop_policy(None)
18+
support.set_event_loop_policy(None)
1919

2020

2121
class MyProto(asyncio.Protocol):

‎Lib/test/test_asyncio/test_ssl.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_ssl.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
def tearDownModule():
28-
asyncio.set_event_loop_policy(None)
28+
support.set_event_loop_policy(None)
2929

3030

3131
class MyBaseProto(asyncio.Protocol):

‎Lib/test/test_asyncio/test_sslproto.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_sslproto.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
def tearDownModule():
24-
asyncio.set_event_loop_policy(None)
24+
support.set_event_loop_policy(None)
2525

2626

2727
@unittest.skipIf(ssl is None, 'No ssl module')

‎Lib/test/test_asyncio/test_streams.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_streams.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818

1919
import asyncio
2020
from test.test_asyncio import utils as test_utils
21+
from test import support
2122

2223

2324
def tearDownModule():
24-
asyncio.set_event_loop_policy(None)
25+
support.set_event_loop_policy(None)
2526

2627

2728
class StreamTests(test_utils.TestCase):

‎Lib/test/test_asyncio/test_subprocess.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_subprocess.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
def tearDownModule():
38-
asyncio.set_event_loop_policy(None)
38+
support.set_event_loop_policy(None)
3939

4040

4141
class TestSubprocessTransport(base_subprocess.BaseSubprocessTransport):

‎Lib/test/test_asyncio/test_taskgroups.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_taskgroups.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import contextlib
88
from asyncio import taskgroups
99
import unittest
10+
from test import support
1011

1112

1213
# To prevent a warning "test altered the execution environment"
1314
def tearDownModule():
14-
asyncio.set_event_loop_policy(None)
15+
support.set_event_loop_policy(None)
1516

1617

1718
class MyExc(Exception):

‎Lib/test/test_asyncio/test_tasks.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_tasks.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
def tearDownModule():
25-
asyncio.set_event_loop_policy(None)
25+
support.set_event_loop_policy(None)
2626

2727

2828
async def coroutine_function():

‎Lib/test/test_asyncio/test_threads.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_threads.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def tearDownModule():
11-
asyncio.set_event_loop_policy(None)
11+
support.set_event_loop_policy(None)
1212

1313

1414
class ToThreadTests(unittest.IsolatedAsyncioTestCase):

‎Lib/test/test_asyncio/test_timeouts.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_timeouts.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def tearDownModule():
10-
asyncio.set_event_loop_policy(None)
10+
support.set_event_loop_policy(None)
1111

1212

1313
class TimeoutTests(unittest.IsolatedAsyncioTestCase):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.