mirror of https://github.com/python/cpython.git
gh-95010: Fix asyncio GenericWatcherTests.test_create_subprocess_fails_with_inactive_watcher (GH-95009)
The test was never run, because it was missing the TestCase class.
The test failed because the wrong attribute was patched.
(cherry picked from commit 834bd5dd76
)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
This commit is contained in:
parent
e2e8ec0760
commit
d19b5d8533
|
@ -700,6 +700,32 @@ class SubprocessPidfdWatcherTests(SubprocessWatcherMixin,
|
||||||
test_utils.TestCase):
|
test_utils.TestCase):
|
||||||
Watcher = unix_events.PidfdChildWatcher
|
Watcher = unix_events.PidfdChildWatcher
|
||||||
|
|
||||||
|
|
||||||
|
class GenericWatcherTests(test_utils.TestCase):
|
||||||
|
|
||||||
|
def test_create_subprocess_fails_with_inactive_watcher(self):
|
||||||
|
watcher = mock.create_autospec(
|
||||||
|
asyncio.AbstractChildWatcher,
|
||||||
|
**{"__enter__.return_value.is_active.return_value": False}
|
||||||
|
)
|
||||||
|
|
||||||
|
async def execute():
|
||||||
|
asyncio.set_child_watcher(watcher)
|
||||||
|
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
await subprocess.create_subprocess_exec(
|
||||||
|
os_helper.FakePath(sys.executable), '-c', 'pass')
|
||||||
|
|
||||||
|
watcher.add_child_handler.assert_not_called()
|
||||||
|
|
||||||
|
with asyncio.Runner(loop_factory=asyncio.new_event_loop) as runner:
|
||||||
|
self.assertIsNone(runner.run(execute()))
|
||||||
|
self.assertListEqual(watcher.mock_calls, [
|
||||||
|
mock.call.__enter__(),
|
||||||
|
mock.call.__enter__().is_active(),
|
||||||
|
mock.call.__exit__(RuntimeError, mock.ANY, mock.ANY),
|
||||||
|
])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Windows
|
# Windows
|
||||||
class SubprocessProactorTests(SubprocessMixin, test_utils.TestCase):
|
class SubprocessProactorTests(SubprocessMixin, test_utils.TestCase):
|
||||||
|
@ -710,25 +736,5 @@ def setUp(self):
|
||||||
self.set_event_loop(self.loop)
|
self.set_event_loop(self.loop)
|
||||||
|
|
||||||
|
|
||||||
class GenericWatcherTests:
|
|
||||||
|
|
||||||
def test_create_subprocess_fails_with_inactive_watcher(self):
|
|
||||||
|
|
||||||
async def execute():
|
|
||||||
watcher = mock.create_authspec(asyncio.AbstractChildWatcher)
|
|
||||||
watcher.is_active.return_value = False
|
|
||||||
asyncio.set_child_watcher(watcher)
|
|
||||||
|
|
||||||
with self.assertRaises(RuntimeError):
|
|
||||||
await subprocess.create_subprocess_exec(
|
|
||||||
os_helper.FakePath(sys.executable), '-c', 'pass')
|
|
||||||
|
|
||||||
watcher.add_child_handler.assert_not_called()
|
|
||||||
|
|
||||||
self.assertIsNone(self.loop.run_until_complete(execute()))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue