Skip to content

Commit

Permalink
pythongh-90522: add test
Browse files Browse the repository at this point in the history
Subprocess opening /dev/stdin fails if it is a socketpair.
  • Loading branch information
tifv authored and xopham committed Oct 13, 2022
1 parent a0a38c1 commit 0ac3aed
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,26 @@ async def empty_error():
self.assertEqual(output, None)
self.assertEqual(exitcode, 0)

@unittest.skipIf(sys.platform != 'linux', "Don't have /dev/stdin")
def test_devstdin_input(self):

async def devstdin_input(message):
code = 'file = open("/dev/stdin"); data = file.read(); print(len(data))'
proc = await asyncio.create_subprocess_exec(
sys.executable, '-c', code,
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
close_fds=False,
)
stdout, stderr = await proc.communicate(message)
exitcode = await proc.wait()
return (stdout, exitcode)

output, exitcode = self.loop.run_until_complete(devstdin_input(b'abc'))
self.assertEqual(output.rstrip(), b'3')
self.assertEqual(exitcode, 0)

def test_cancel_process_wait(self):
# Issue #23140: cancel Process.wait()

Expand Down

0 comments on commit 0ac3aed

Please sign in to comment.