Skip to content

Commit 0ac3aed

Browse files
tifvxopham
authored andcommitted
gh-90522: add test
Subprocess opening /dev/stdin fails if it is a socketpair.
1 parent a0a38c1 commit 0ac3aed

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Lib/test/test_asyncio/test_subprocess.py

+20
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,26 @@ async def empty_error():
401401
self.assertEqual(output, None)
402402
self.assertEqual(exitcode, 0)
403403

404+
@unittest.skipIf(sys.platform != 'linux', "Don't have /dev/stdin")
405+
def test_devstdin_input(self):
406+
407+
async def devstdin_input(message):
408+
code = 'file = open("/dev/stdin"); data = file.read(); print(len(data))'
409+
proc = await asyncio.create_subprocess_exec(
410+
sys.executable, '-c', code,
411+
stdin=asyncio.subprocess.PIPE,
412+
stdout=asyncio.subprocess.PIPE,
413+
stderr=asyncio.subprocess.PIPE,
414+
close_fds=False,
415+
)
416+
stdout, stderr = await proc.communicate(message)
417+
exitcode = await proc.wait()
418+
return (stdout, exitcode)
419+
420+
output, exitcode = self.loop.run_until_complete(devstdin_input(b'abc'))
421+
self.assertEqual(output.rstrip(), b'3')
422+
self.assertEqual(exitcode, 0)
423+
404424
def test_cancel_process_wait(self):
405425
# Issue #23140: cancel Process.wait()
406426

0 commit comments

Comments
 (0)