aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_asyncio/test_events.py
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2024-12-18 11:35:29 +0530
committerGitHub <noreply@github.com>2024-12-18 11:35:29 +0530
commit5892853fb71acd6530e1e241a9a4bcf71a61fb21 (patch)
treebd17e169dbcf0d0e290b5208886da38baae675b1 /Lib/test/test_asyncio/test_events.py
parent559b0e7013f9cbf42a12fe9c86048d5cbb2f6f22 (diff)
downloadcpython-5892853fb71acd6530e1e241a9a4bcf71a61fb21.tar.gz
cpython-5892853fb71acd6530e1e241a9a4bcf71a61fb21.zip
gh-127949: deprecate `asyncio.set_event_loop_policy` (#128024)
First step towards deprecating the asyncio policy system. This deprecates `asyncio.set_event_loop_policy` and will be removed in Python 3.16.
Diffstat (limited to 'Lib/test/test_asyncio/test_events.py')
-rw-r--r--Lib/test/test_asyncio/test_events.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 2ab638dc527..50df1b6ff9e 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -36,10 +36,10 @@ from test import support
from test.support import socket_helper
from test.support import threading_helper
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
-
+from test.support import warnings_helper
def tearDownModule():
- asyncio.set_event_loop_policy(None)
+ asyncio._set_event_loop_policy(None)
def broken_unix_getsockname():
@@ -2764,13 +2764,17 @@ class PolicyTests(unittest.TestCase):
self.assertIs(policy, asyncio.get_event_loop_policy())
def test_set_event_loop_policy(self):
- self.assertRaises(
- TypeError, asyncio.set_event_loop_policy, object())
+ with self.assertWarnsRegex(
+ DeprecationWarning, "'set_event_loop_policy' is deprecated"):
+ self.assertRaises(
+ TypeError, asyncio.set_event_loop_policy, object())
old_policy = asyncio.get_event_loop_policy()
policy = asyncio.DefaultEventLoopPolicy()
- asyncio.set_event_loop_policy(policy)
+ with self.assertWarnsRegex(
+ DeprecationWarning, "'set_event_loop_policy' is deprecated"):
+ asyncio.set_event_loop_policy(policy)
self.assertIs(policy, asyncio.get_event_loop_policy())
self.assertIsNot(policy, old_policy)
@@ -2857,7 +2861,7 @@ class GetEventLoopTestsMixin:
old_policy = asyncio.get_event_loop_policy()
try:
- asyncio.set_event_loop_policy(Policy())
+ asyncio._set_event_loop_policy(Policy())
loop = asyncio.new_event_loop()
with self.assertRaises(TestError):
@@ -2885,7 +2889,7 @@ class GetEventLoopTestsMixin:
asyncio.get_event_loop()
finally:
- asyncio.set_event_loop_policy(old_policy)
+ asyncio._set_event_loop_policy(old_policy)
if loop is not None:
loop.close()
@@ -2897,7 +2901,7 @@ class GetEventLoopTestsMixin:
def test_get_event_loop_returns_running_loop2(self):
old_policy = asyncio.get_event_loop_policy()
try:
- asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
+ asyncio._set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
loop = asyncio.new_event_loop()
self.addCleanup(loop.close)
@@ -2923,7 +2927,7 @@ class GetEventLoopTestsMixin:
asyncio.get_event_loop()
finally:
- asyncio.set_event_loop_policy(old_policy)
+ asyncio._set_event_loop_policy(old_policy)
if loop is not None:
loop.close()