summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2024-12-24 12:00:26 (GMT)
committerGitHub <noreply@github.com>2024-12-24 12:00:26 (GMT)
commita391d80f4bf5a3cf5aa95340ca848b9a0294778d (patch)
tree1d09810b45471e2aabafe01e8f9016bccdae3e99 /Lib/test
parent3f6a618e49b1c8c12a7bc0c26e846735e108dc97 (diff)
downloadcpython-a391d80f4bf5a3cf5aa95340ca848b9a0294778d.zip
cpython-a391d80f4bf5a3cf5aa95340ca848b9a0294778d.tar.gz
cpython-a391d80f4bf5a3cf5aa95340ca848b9a0294778d.tar.bz2
gh-127949: deprecate asyncio policy classes (#128216)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_events.py34
-rw-r--r--Lib/test/test_asyncio/test_runners.py2
-rw-r--r--Lib/test/test_asyncio/test_windows_events.py18
3 files changed, 35 insertions, 19 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index d43f66c..c626670 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -2695,14 +2695,26 @@ class AbstractEventLoopTests(unittest.TestCase):
class PolicyTests(unittest.TestCase):
+ def test_abstract_event_loop_policy_deprecation(self):
+ with self.assertWarnsRegex(
+ DeprecationWarning, "'asyncio.AbstractEventLoopPolicy' is deprecated"):
+ policy = asyncio.AbstractEventLoopPolicy()
+ self.assertIsInstance(policy, asyncio.AbstractEventLoopPolicy)
+
+ def test_default_event_loop_policy_deprecation(self):
+ with self.assertWarnsRegex(
+ DeprecationWarning, "'asyncio.DefaultEventLoopPolicy' is deprecated"):
+ policy = asyncio.DefaultEventLoopPolicy()
+ self.assertIsInstance(policy, asyncio.DefaultEventLoopPolicy)
+
def test_event_loop_policy(self):
- policy = asyncio.AbstractEventLoopPolicy()
+ policy = asyncio._AbstractEventLoopPolicy()
self.assertRaises(NotImplementedError, policy.get_event_loop)
self.assertRaises(NotImplementedError, policy.set_event_loop, object())
self.assertRaises(NotImplementedError, policy.new_event_loop)
def test_get_event_loop(self):
- policy = asyncio.DefaultEventLoopPolicy()
+ policy = asyncio._DefaultEventLoopPolicy()
self.assertIsNone(policy._local._loop)
with self.assertRaises(RuntimeError):
@@ -2710,7 +2722,7 @@ class PolicyTests(unittest.TestCase):
self.assertIsNone(policy._local._loop)
def test_get_event_loop_does_not_call_set_event_loop(self):
- policy = asyncio.DefaultEventLoopPolicy()
+ policy = asyncio._DefaultEventLoopPolicy()
with mock.patch.object(
policy, "set_event_loop",
@@ -2722,7 +2734,7 @@ class PolicyTests(unittest.TestCase):
m_set_event_loop.assert_not_called()
def test_get_event_loop_after_set_none(self):
- policy = asyncio.DefaultEventLoopPolicy()
+ policy = asyncio._DefaultEventLoopPolicy()
policy.set_event_loop(None)
self.assertRaises(RuntimeError, policy.get_event_loop)
@@ -2730,7 +2742,7 @@ class PolicyTests(unittest.TestCase):
def test_get_event_loop_thread(self, m_current_thread):
def f():
- policy = asyncio.DefaultEventLoopPolicy()
+ policy = asyncio._DefaultEventLoopPolicy()
self.assertRaises(RuntimeError, policy.get_event_loop)
th = threading.Thread(target=f)
@@ -2738,14 +2750,14 @@ class PolicyTests(unittest.TestCase):
th.join()
def test_new_event_loop(self):
- policy = asyncio.DefaultEventLoopPolicy()
+ policy = asyncio._DefaultEventLoopPolicy()
loop = policy.new_event_loop()
self.assertIsInstance(loop, asyncio.AbstractEventLoop)
loop.close()
def test_set_event_loop(self):
- policy = asyncio.DefaultEventLoopPolicy()
+ policy = asyncio._DefaultEventLoopPolicy()
old_loop = policy.new_event_loop()
policy.set_event_loop(old_loop)
@@ -2762,7 +2774,7 @@ class PolicyTests(unittest.TestCase):
with self.assertWarnsRegex(
DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
policy = asyncio.get_event_loop_policy()
- self.assertIsInstance(policy, asyncio.AbstractEventLoopPolicy)
+ self.assertIsInstance(policy, asyncio._AbstractEventLoopPolicy)
self.assertIs(policy, asyncio.get_event_loop_policy())
def test_set_event_loop_policy(self):
@@ -2775,7 +2787,7 @@ class PolicyTests(unittest.TestCase):
DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
old_policy = asyncio.get_event_loop_policy()
- policy = asyncio.DefaultEventLoopPolicy()
+ policy = asyncio._DefaultEventLoopPolicy()
with self.assertWarnsRegex(
DeprecationWarning, "'asyncio.set_event_loop_policy' is deprecated"):
asyncio.set_event_loop_policy(policy)
@@ -2862,7 +2874,7 @@ class GetEventLoopTestsMixin:
class TestError(Exception):
pass
- class Policy(asyncio.DefaultEventLoopPolicy):
+ class Policy(asyncio._DefaultEventLoopPolicy):
def get_event_loop(self):
raise TestError
@@ -2908,7 +2920,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)
diff --git a/Lib/test/test_asyncio/test_runners.py b/Lib/test/test_asyncio/test_runners.py
index e1f82f7..21f277b 100644
--- a/Lib/test/test_asyncio/test_runners.py
+++ b/Lib/test/test_asyncio/test_runners.py
@@ -19,7 +19,7 @@ def interrupt_self():
_thread.interrupt_main()
-class TestPolicy(asyncio.AbstractEventLoopPolicy):
+class TestPolicy(asyncio._AbstractEventLoopPolicy):
def __init__(self, loop_factory):
self.loop_factory = loop_factory
diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py
index 28b05d2..69e9905 100644
--- a/Lib/test/test_asyncio/test_windows_events.py
+++ b/Lib/test/test_asyncio/test_windows_events.py
@@ -328,14 +328,15 @@ class WinPolicyTests(WindowsEventsTestCase):
def test_selector_win_policy(self):
async def main():
- self.assertIsInstance(
- asyncio.get_running_loop(),
- asyncio.SelectorEventLoop)
+ self.assertIsInstance(asyncio.get_running_loop(), asyncio.SelectorEventLoop)
old_policy = asyncio._get_event_loop_policy()
try:
- asyncio._set_event_loop_policy(
- asyncio.WindowsSelectorEventLoopPolicy())
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ "'asyncio.WindowsSelectorEventLoopPolicy' is deprecated",
+ ):
+ asyncio._set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())
finally:
asyncio._set_event_loop_policy(old_policy)
@@ -348,8 +349,11 @@ class WinPolicyTests(WindowsEventsTestCase):
old_policy = asyncio._get_event_loop_policy()
try:
- asyncio._set_event_loop_policy(
- asyncio.WindowsProactorEventLoopPolicy())
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ "'asyncio.WindowsProactorEventLoopPolicy' is deprecated",
+ ):
+ asyncio._set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
asyncio.run(main())
finally:
asyncio._set_event_loop_policy(old_policy)