summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-10-15 23:09:30 (GMT)
committerGitHub <noreply@github.com>2022-10-15 23:09:30 (GMT)
commit660f10248ba321e7783c07f3801991275e2aee1e (patch)
tree7c1c2ba0839fc2e653117e1d26af7810f3e28cdc /Lib/test
parentbb56dead336357153a0c3b8cc9d9d6856d2c5a03 (diff)
downloadcpython-660f10248ba321e7783c07f3801991275e2aee1e.zip
cpython-660f10248ba321e7783c07f3801991275e2aee1e.tar.gz
cpython-660f10248ba321e7783c07f3801991275e2aee1e.tar.bz2
GH-94597: Deprecate child watcher getters and setters (#98215)
This is the next step for deprecating child watchers. Until we've removed the API completely we have to use it, so this PR is mostly suppressing a lot of warnings when using the API internally. Once the child watcher API is totally removed, the two child watcher implementations we actually use and need (Pidfd and Thread) will be turned into internal helpers.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_events.py16
-rw-r--r--Lib/test/test_asyncio/test_streams.py8
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py29
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py21
-rw-r--r--Lib/test/test_asyncio/utils.py6
5 files changed, 52 insertions, 28 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 98b55de..cabe75f 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -2058,11 +2058,13 @@ else:
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
watcher = asyncio.SafeChildWatcher()
- watcher.attach_loop(self.loop)
- asyncio.set_child_watcher(watcher)
+ watcher.attach_loop(self.loop)
+ asyncio.set_child_watcher(watcher)
def tearDown(self):
- asyncio.set_child_watcher(None)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ asyncio.set_child_watcher(None)
super().tearDown()
@@ -2657,13 +2659,15 @@ class GetEventLoopTestsMixin:
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
watcher = asyncio.SafeChildWatcher()
- watcher.attach_loop(self.loop)
- asyncio.set_child_watcher(watcher)
+ watcher.attach_loop(self.loop)
+ asyncio.set_child_watcher(watcher)
def tearDown(self):
try:
if sys.platform != 'win32':
- asyncio.set_child_watcher(None)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ asyncio.set_child_watcher(None)
super().tearDown()
finally:
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index 8fb9313..01d5407 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -797,7 +797,9 @@ os.close(fd)
watcher = asyncio.SafeChildWatcher()
watcher.attach_loop(self.loop)
try:
- asyncio.set_child_watcher(watcher)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ asyncio.set_child_watcher(watcher)
create = asyncio.create_subprocess_exec(
*args,
pass_fds={wfd},
@@ -805,7 +807,9 @@ os.close(fd)
proc = self.loop.run_until_complete(create)
self.loop.run_until_complete(proc.wait())
finally:
- asyncio.set_child_watcher(None)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ asyncio.set_child_watcher(None)
os.close(wfd)
data = self.loop.run_until_complete(reader.read(-1))
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index 64df1b1..8e55115 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -582,7 +582,9 @@ class SubprocessMixin:
# manually to avoid a warning when the watcher is detached.
if (sys.platform != 'win32' and
isinstance(self, SubprocessFastWatcherTests)):
- asyncio.get_child_watcher()._callbacks.clear()
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ asyncio.get_child_watcher()._callbacks.clear()
async def _test_popen_error(self, stdin):
if sys.platform == 'win32':
@@ -696,13 +698,17 @@ if sys.platform != 'win32':
watcher = self._get_watcher()
watcher.attach_loop(self.loop)
- policy.set_child_watcher(watcher)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ policy.set_child_watcher(watcher)
def tearDown(self):
super().tearDown()
policy = asyncio.get_event_loop_policy()
- watcher = policy.get_child_watcher()
- policy.set_child_watcher(None)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ watcher = policy.get_child_watcher()
+ policy.set_child_watcher(None)
watcher.attach_loop(None)
watcher.close()
@@ -752,7 +758,9 @@ if sys.platform != 'win32':
)
async def execute():
- asyncio.set_child_watcher(watcher)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ asyncio.set_child_watcher(watcher)
with self.assertRaises(RuntimeError):
await subprocess.create_subprocess_exec(
@@ -761,7 +769,9 @@ if sys.platform != 'win32':
watcher.add_child_handler.assert_not_called()
with asyncio.Runner(loop_factory=asyncio.new_event_loop) as runner:
- self.assertIsNone(runner.run(execute()))
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ self.assertIsNone(runner.run(execute()))
self.assertListEqual(watcher.mock_calls, [
mock.call.__enter__(),
mock.call.__enter__().is_active(),
@@ -788,15 +798,16 @@ if sys.platform != 'win32':
with self.assertRaises(RuntimeError):
asyncio.get_event_loop_policy().get_event_loop()
return await asyncio.to_thread(asyncio.run, in_thread())
-
- asyncio.set_child_watcher(asyncio.PidfdChildWatcher())
+ with self.assertWarns(DeprecationWarning):
+ asyncio.set_child_watcher(asyncio.PidfdChildWatcher())
try:
with asyncio.Runner(loop_factory=asyncio.new_event_loop) as runner:
returncode, stdout = runner.run(main())
self.assertEqual(returncode, 0)
self.assertEqual(stdout, b'some data')
finally:
- asyncio.set_child_watcher(None)
+ with self.assertWarns(DeprecationWarning):
+ asyncio.set_child_watcher(None)
else:
# Windows
class SubprocessProactorTests(SubprocessMixin, test_utils.TestCase):
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 025da0f..d806ed4 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -1709,33 +1709,36 @@ class PolicyTests(unittest.TestCase):
self.assertIsNone(policy._watcher)
unix_events.can_use_pidfd = mock.Mock()
unix_events.can_use_pidfd.return_value = False
- watcher = policy.get_child_watcher()
+ with self.assertWarns(DeprecationWarning):
+ watcher = policy.get_child_watcher()
self.assertIsInstance(watcher, asyncio.ThreadedChildWatcher)
self.assertIs(policy._watcher, watcher)
-
- self.assertIs(watcher, policy.get_child_watcher())
+ with self.assertWarns(DeprecationWarning):
+ self.assertIs(watcher, policy.get_child_watcher())
policy = self.create_policy()
self.assertIsNone(policy._watcher)
unix_events.can_use_pidfd = mock.Mock()
unix_events.can_use_pidfd.return_value = True
- watcher = policy.get_child_watcher()
+ with self.assertWarns(DeprecationWarning):
+ watcher = policy.get_child_watcher()
self.assertIsInstance(watcher, asyncio.PidfdChildWatcher)
self.assertIs(policy._watcher, watcher)
-
- self.assertIs(watcher, policy.get_child_watcher())
+ with self.assertWarns(DeprecationWarning):
+ self.assertIs(watcher, policy.get_child_watcher())
def test_get_child_watcher_after_set(self):
policy = self.create_policy()
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
watcher = asyncio.FastChildWatcher()
+ policy.set_child_watcher(watcher)
- policy.set_child_watcher(watcher)
self.assertIs(policy._watcher, watcher)
- self.assertIs(watcher, policy.get_child_watcher())
+ with self.assertWarns(DeprecationWarning):
+ self.assertIs(watcher, policy.get_child_watcher())
def test_get_child_watcher_thread(self):
@@ -1769,7 +1772,7 @@ class PolicyTests(unittest.TestCase):
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
watcher = asyncio.SafeChildWatcher()
- policy.set_child_watcher(watcher)
+ policy.set_child_watcher(watcher)
watcher.attach_loop(loop)
self.assertIs(watcher._loop, loop)
diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py
index 96be5a1..5b9c86e 100644
--- a/Lib/test/test_asyncio/utils.py
+++ b/Lib/test/test_asyncio/utils.py
@@ -14,7 +14,7 @@ import sys
import threading
import unittest
import weakref
-
+import warnings
from unittest import mock
from http.server import HTTPServer
@@ -544,7 +544,9 @@ class TestCase(unittest.TestCase):
policy = support.maybe_get_event_loop_policy()
if policy is not None:
try:
- watcher = policy.get_child_watcher()
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ watcher = policy.get_child_watcher()
except NotImplementedError:
# watcher is not implemented by EventLoopPolicy, e.g. Windows
pass