diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-10-06 14:11:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-06 14:11:51 (GMT) |
commit | 49a45f6cd80605998eb50fd95ca4b5531674e290 (patch) | |
tree | f0ab5dc47b0e7188ad0d0e5c075a137832153b37 | |
parent | 88223f15d792159bb2ab26923cb21bee910a4565 (diff) | |
download | cpython-49a45f6cd80605998eb50fd95ca4b5531674e290.zip cpython-49a45f6cd80605998eb50fd95ca4b5531674e290.tar.gz cpython-49a45f6cd80605998eb50fd95ca4b5531674e290.tar.bz2 |
[3.11] gh-110184: Fix subprocess test_pipesize_default() (GH-110465) (#110472)
gh-110184: Fix subprocess test_pipesize_default() (GH-110465)
For proc.stdin, get the size of the read end of the test pipe.
Use subprocess context manager ("with proc:").
(cherry picked from commit d023d4166b255023dac448305270350030101481)
Co-authored-by: Victor Stinner <vstinner@python.org>
-rw-r--r-- | Lib/test/test_subprocess.py | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 3142026..b7b16e2 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -747,31 +747,36 @@ class ProcessTestCase(BaseTestCase): @unittest.skipUnless(fcntl and hasattr(fcntl, 'F_GETPIPE_SZ'), 'fcntl.F_GETPIPE_SZ required for test.') def test_pipesize_default(self): - p = subprocess.Popen( + proc = subprocess.Popen( [sys.executable, "-c", 'import sys; sys.stdin.read(); sys.stdout.write("out"); ' 'sys.stderr.write("error!")'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, pipesize=-1) - try: - fp_r, fp_w = os.pipe() + + with proc: try: - default_pipesize = fcntl.fcntl(fp_w, fcntl.F_GETPIPE_SZ) - for fifo in [p.stdin, p.stdout, p.stderr]: - self.assertEqual( - fcntl.fcntl(fifo.fileno(), fcntl.F_GETPIPE_SZ), - default_pipesize) + fp_r, fp_w = os.pipe() + try: + default_read_pipesize = fcntl.fcntl(fp_r, fcntl.F_GETPIPE_SZ) + default_write_pipesize = fcntl.fcntl(fp_w, fcntl.F_GETPIPE_SZ) + 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: - os.close(fp_r) - 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() + proc.kill() def test_env(self): newenv = os.environ.copy() |