From cbac93c2293dd2cc6f10b31e91eaa1a502822704 Mon Sep 17 00:00:00 2001 From: Peter Astrand Date: Thu, 3 Mar 2005 20:24:28 +0000 Subject: [PATCH] Added three more testcases: Using communicate with only one of stdin/stdout/stderr redirected. --- Lib/test/test_subprocess.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 52f4d4711d2..e8415cdf80a 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -248,6 +248,29 @@ class ProcessTestCase(unittest.TestCase): env=newenv) self.assertEqual(p.stdout.read(), "orange") + def test_communicate_stdin(self): + p = subprocess.Popen([sys.executable, "-c", + 'import sys; sys.exit(sys.stdin.read() == "pear")'], + stdin=subprocess.PIPE) + p.communicate("pear") + self.assertEqual(p.returncode, 1) + + def test_communicate_stdout(self): + p = subprocess.Popen([sys.executable, "-c", + 'import sys; sys.stdout.write("pineapple")'], + stdout=subprocess.PIPE) + (stdout, stderr) = p.communicate() + self.assertEqual(stdout, "pineapple") + self.assertEqual(stderr, None) + + def test_communicate_stderr(self): + p = subprocess.Popen([sys.executable, "-c", + 'import sys; sys.stderr.write("pineapple")'], + stderr=subprocess.PIPE) + (stdout, stderr) = p.communicate() + self.assertEqual(stdout, None) + self.assertEqual(stderr, "pineapple") + def test_communicate(self): p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' \