summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
authorAndrey Doroschenko <dorosch.github.io@yandex.ru>2019-11-17 14:08:31 (GMT)
committerTal Einat <taleinat+github@gmail.com>2019-11-17 14:08:31 (GMT)
commit645005e947c13c4a0706310a2a46112bf63cadc0 (patch)
tree1df0a27b4be362611a8f4836817961c819d1d277 /Lib/test/test_subprocess.py
parent143a97f64128070386b12a0ee589bdaad5e51f40 (diff)
downloadcpython-645005e947c13c4a0706310a2a46112bf63cadc0.zip
cpython-645005e947c13c4a0706310a2a46112bf63cadc0.tar.gz
cpython-645005e947c13c4a0706310a2a46112bf63cadc0.tar.bz2
bpo-38724: Implement subprocess.Popen.__repr__ (GH-17151)
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 9e96a6d..97dc09c 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1360,6 +1360,30 @@ class ProcessTestCase(BaseTestCase):
self.addCleanup(p.stdin.close)
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('>')
+ )
+
def test_communicate_epipe_only_stdin(self):
# Issue 10963: communicate() should hide EPIPE
p = subprocess.Popen(ZERO_RETURN_CMD,