summaryrefslogtreecommitdiff
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py40
1 files changed, 18 insertions, 22 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 70b54f4155..7c79365f41 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -23,6 +23,7 @@ import threading
import gc
import textwrap
import json
+import pathlib
from test.support.os_helper import FakePath
try:
@@ -1442,28 +1443,23 @@ class ProcessTestCase(BaseTestCase):
p.communicate(b"x" * 2**20)
def test_repr(self):
- # Run a command that waits for user input, to check the repr() of
- # a Proc object while and after the sub-process runs.
- code = 'import sys; input(); sys.exit(57)'
- cmd = [sys.executable, '-c', code]
- result = "<Popen: returncode: {}"
-
- with subprocess.Popen(
- cmd, stdin=subprocess.PIPE, universal_newlines=True) as proc:
- self.assertIsNone(proc.returncode)
- self.assertTrue(
- repr(proc).startswith(result.format(proc.returncode)) and
- repr(proc).endswith('>')
- )
-
- proc.communicate(input='exit...\n')
- proc.wait()
-
- self.assertIsNotNone(proc.returncode)
- self.assertTrue(
- repr(proc).startswith(result.format(proc.returncode)) and
- repr(proc).endswith('>')
- )
+ path_cmd = pathlib.Path("my-tool.py")
+ pathlib_cls = path_cmd.__class__.__name__
+
+ cases = [
+ ("ls", True, 123, "<Popen: returncode: 123 args: 'ls'>"),
+ ('a' * 100, True, 0,
+ "<Popen: returncode: 0 args: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...>"),
+ (["ls"], False, None, "<Popen: returncode: None args: ['ls']>"),
+ (["ls", '--my-opts', 'a' * 100], False, None,
+ "<Popen: returncode: None args: ['ls', '--my-opts', 'aaaaaaaaaaaaaaaaaaaaaaaa...>"),
+ (path_cmd, False, 7, f"<Popen: returncode: 7 args: {pathlib_cls}('my-tool.py')>")
+ ]
+ with unittest.mock.patch.object(subprocess.Popen, '_execute_child'):
+ for cmd, shell, code, sx in cases:
+ p = subprocess.Popen(cmd, shell=shell)
+ p.returncode = code
+ self.assertEqual(repr(p), sx)
def test_communicate_epipe_only_stdin(self):
# Issue 10963: communicate() should hide EPIPE