summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2024-12-18 12:34:20 (GMT)
committerGitHub <noreply@github.com>2024-12-18 12:34:20 (GMT)
commitdbd08fb60d1c434ebb6009d28d2b97f90e011032 (patch)
tree4919c52b32f03506b99c9f73f05c8acd2098a2ff /Lib/test
parentbad3cdefa840ff099e5e08cf88dcf6dfed7d37b8 (diff)
downloadcpython-dbd08fb60d1c434ebb6009d28d2b97f90e011032.zip
cpython-dbd08fb60d1c434ebb6009d28d2b97f90e011032.tar.gz
cpython-dbd08fb60d1c434ebb6009d28d2b97f90e011032.tar.bz2
gh-127949: deprecate `asyncio.get_event_loop_policy` (#128053)
This deprecates `asyncio.get_event_loop_policy` and will be removed in Python 3.16.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_events.py29
-rw-r--r--Lib/test/test_asyncio/test_runners.py6
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py3
-rw-r--r--Lib/test/test_asyncio/test_windows_events.py4
-rw-r--r--Lib/test/test_contextlib_async.py2
-rw-r--r--Lib/test/test_unittest/test_async_case.py2
6 files changed, 26 insertions, 20 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 50df1b6..d43f66c 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -2397,7 +2397,7 @@ class HandleTests(test_utils.TestCase):
self.assertRegex(repr(h), regex)
def test_handle_source_traceback(self):
- loop = asyncio.get_event_loop_policy().new_event_loop()
+ loop = asyncio.new_event_loop()
loop.set_debug(True)
self.set_event_loop(loop)
@@ -2759,24 +2759,31 @@ class PolicyTests(unittest.TestCase):
old_loop.close()
def test_get_event_loop_policy(self):
- policy = asyncio.get_event_loop_policy()
- self.assertIsInstance(policy, asyncio.AbstractEventLoopPolicy)
- self.assertIs(policy, asyncio.get_event_loop_policy())
+ with self.assertWarnsRegex(
+ DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
+ policy = asyncio.get_event_loop_policy()
+ self.assertIsInstance(policy, asyncio.AbstractEventLoopPolicy)
+ self.assertIs(policy, asyncio.get_event_loop_policy())
def test_set_event_loop_policy(self):
with self.assertWarnsRegex(
- DeprecationWarning, "'set_event_loop_policy' is deprecated"):
+ DeprecationWarning, "'asyncio.set_event_loop_policy' is deprecated"):
self.assertRaises(
TypeError, asyncio.set_event_loop_policy, object())
- old_policy = asyncio.get_event_loop_policy()
+ with self.assertWarnsRegex(
+ DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
+ old_policy = asyncio.get_event_loop_policy()
policy = asyncio.DefaultEventLoopPolicy()
with self.assertWarnsRegex(
- DeprecationWarning, "'set_event_loop_policy' is deprecated"):
+ DeprecationWarning, "'asyncio.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)
+
+ with self.assertWarnsRegex(
+ DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
+ self.assertIs(policy, asyncio.get_event_loop_policy())
+ self.assertIsNot(policy, old_policy)
class GetEventLoopTestsMixin:
@@ -2859,7 +2866,7 @@ class GetEventLoopTestsMixin:
def get_event_loop(self):
raise TestError
- old_policy = asyncio.get_event_loop_policy()
+ old_policy = asyncio._get_event_loop_policy()
try:
asyncio._set_event_loop_policy(Policy())
loop = asyncio.new_event_loop()
@@ -2899,7 +2906,7 @@ class GetEventLoopTestsMixin:
self.assertIs(asyncio._get_running_loop(), None)
def test_get_event_loop_returns_running_loop2(self):
- old_policy = asyncio.get_event_loop_policy()
+ old_policy = asyncio._get_event_loop_policy()
try:
asyncio._set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
loop = asyncio.new_event_loop()
diff --git a/Lib/test/test_asyncio/test_runners.py b/Lib/test/test_asyncio/test_runners.py
index f9afccc..e1f82f7 100644
--- a/Lib/test/test_asyncio/test_runners.py
+++ b/Lib/test/test_asyncio/test_runners.py
@@ -64,7 +64,7 @@ class BaseTest(unittest.TestCase):
asyncio._set_event_loop_policy(policy)
def tearDown(self):
- policy = asyncio.get_event_loop_policy()
+ policy = asyncio._get_event_loop_policy()
if policy.loop is not None:
self.assertTrue(policy.loop.is_closed())
self.assertTrue(policy.loop.shutdown_ag_run)
@@ -208,7 +208,7 @@ class RunTests(BaseTest):
await asyncio.sleep(0)
return 42
- policy = asyncio.get_event_loop_policy()
+ policy = asyncio._get_event_loop_policy()
policy.set_event_loop = mock.Mock()
asyncio.run(main())
self.assertTrue(policy.set_event_loop.called)
@@ -495,7 +495,7 @@ class RunnerTests(BaseTest):
async def coro():
pass
- policy = asyncio.get_event_loop_policy()
+ policy = asyncio._get_event_loop_policy()
policy.set_event_loop = mock.Mock()
runner = asyncio.Runner()
runner.run(coro())
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index 467e964..57decaf 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -886,8 +886,7 @@ if sys.platform != 'win32':
def setUp(self):
super().setUp()
- policy = asyncio.get_event_loop_policy()
- self.loop = policy.new_event_loop()
+ self.loop = asyncio.new_event_loop()
self.set_event_loop(self.loop)
def test_watcher_implementation(self):
diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py
index 26ca5f9..28b05d2 100644
--- a/Lib/test/test_asyncio/test_windows_events.py
+++ b/Lib/test/test_asyncio/test_windows_events.py
@@ -332,7 +332,7 @@ class WinPolicyTests(WindowsEventsTestCase):
asyncio.get_running_loop(),
asyncio.SelectorEventLoop)
- old_policy = asyncio.get_event_loop_policy()
+ old_policy = asyncio._get_event_loop_policy()
try:
asyncio._set_event_loop_policy(
asyncio.WindowsSelectorEventLoopPolicy())
@@ -346,7 +346,7 @@ class WinPolicyTests(WindowsEventsTestCase):
asyncio.get_running_loop(),
asyncio.ProactorEventLoop)
- old_policy = asyncio.get_event_loop_policy()
+ old_policy = asyncio._get_event_loop_policy()
try:
asyncio._set_event_loop_policy(
asyncio.WindowsProactorEventLoopPolicy())
diff --git a/Lib/test/test_contextlib_async.py b/Lib/test/test_contextlib_async.py
index d8ee575..88dcdad 100644
--- a/Lib/test/test_contextlib_async.py
+++ b/Lib/test/test_contextlib_async.py
@@ -496,7 +496,7 @@ class TestAsyncExitStack(TestBaseExitStack, unittest.IsolatedAsyncioTestCase):
class SyncAsyncExitStack(AsyncExitStack):
@staticmethod
def run_coroutine(coro):
- loop = asyncio.get_event_loop_policy().get_event_loop()
+ loop = asyncio.new_event_loop()
t = loop.create_task(coro)
t.add_done_callback(lambda f: loop.stop())
loop.run_forever()
diff --git a/Lib/test/test_unittest/test_async_case.py b/Lib/test/test_unittest/test_async_case.py
index 664ca5e..993e6bf 100644
--- a/Lib/test/test_unittest/test_async_case.py
+++ b/Lib/test/test_unittest/test_async_case.py
@@ -480,7 +480,7 @@ class TestAsyncCase(unittest.TestCase):
class TestCase1(unittest.IsolatedAsyncioTestCase):
def setUp(self):
- asyncio.get_event_loop_policy().get_event_loop()
+ asyncio._get_event_loop_policy().get_event_loop()
async def test_demo1(self):
pass