mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-110184: Fix subprocess test_pipesize_default() (#110465)
For proc.stdin, get the size of the read end of the test pipe. Use subprocess context manager ("with proc:").
This commit is contained in:
parent
a4baa9e8ac
commit
d023d4166b
1 changed files with 23 additions and 18 deletions
|
@ -749,31 +749,36 @@ class ProcessTestCase(BaseTestCase):
|
||||||
@unittest.skipUnless(fcntl and hasattr(fcntl, 'F_GETPIPE_SZ'),
|
@unittest.skipUnless(fcntl and hasattr(fcntl, 'F_GETPIPE_SZ'),
|
||||||
'fcntl.F_GETPIPE_SZ required for test.')
|
'fcntl.F_GETPIPE_SZ required for test.')
|
||||||
def test_pipesize_default(self):
|
def test_pipesize_default(self):
|
||||||
p = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
[sys.executable, "-c",
|
[sys.executable, "-c",
|
||||||
'import sys; sys.stdin.read(); sys.stdout.write("out"); '
|
'import sys; sys.stdin.read(); sys.stdout.write("out"); '
|
||||||
'sys.stderr.write("error!")'],
|
'sys.stderr.write("error!")'],
|
||||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE, pipesize=-1)
|
stderr=subprocess.PIPE, pipesize=-1)
|
||||||
try:
|
|
||||||
fp_r, fp_w = os.pipe()
|
with proc:
|
||||||
try:
|
try:
|
||||||
default_pipesize = fcntl.fcntl(fp_w, fcntl.F_GETPIPE_SZ)
|
fp_r, fp_w = os.pipe()
|
||||||
for fifo in [p.stdin, p.stdout, p.stderr]:
|
try:
|
||||||
self.assertEqual(
|
default_read_pipesize = fcntl.fcntl(fp_r, fcntl.F_GETPIPE_SZ)
|
||||||
fcntl.fcntl(fifo.fileno(), fcntl.F_GETPIPE_SZ),
|
default_write_pipesize = fcntl.fcntl(fp_w, fcntl.F_GETPIPE_SZ)
|
||||||
default_pipesize)
|
finally:
|
||||||
|
os.close(fp_r)
|
||||||
|
os.close(fp_w)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
fcntl.fcntl(proc.stdin.fileno(), fcntl.F_GETPIPE_SZ),
|
||||||
|
default_read_pipesize)
|
||||||
|
self.assertEqual(
|
||||||
|
fcntl.fcntl(proc.stdout.fileno(), fcntl.F_GETPIPE_SZ),
|
||||||
|
default_write_pipesize)
|
||||||
|
self.assertEqual(
|
||||||
|
fcntl.fcntl(proc.stderr.fileno(), fcntl.F_GETPIPE_SZ),
|
||||||
|
default_write_pipesize)
|
||||||
|
# On other platforms we cannot test the pipe size (yet). But above
|
||||||
|
# code using pipesize=-1 should not crash.
|
||||||
finally:
|
finally:
|
||||||
os.close(fp_r)
|
proc.kill()
|
||||||
os.close(fp_w)
|
|
||||||
# On other platforms we cannot test the pipe size (yet). But above
|
|
||||||
# code using pipesize=-1 should not crash.
|
|
||||||
p.stdin.close()
|
|
||||||
p.stdout.close()
|
|
||||||
p.stderr.close()
|
|
||||||
finally:
|
|
||||||
p.kill()
|
|
||||||
p.wait()
|
|
||||||
|
|
||||||
def test_env(self):
|
def test_env(self):
|
||||||
newenv = os.environ.copy()
|
newenv = os.environ.copy()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue