summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cmd_line.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-28 18:09:45 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-28 18:09:45 (GMT)
commit39a73a4cfaac3cdd9592840ee3f6007593609789 (patch)
treee1595661b4da810b8874a3e578f32abcc398611b /Lib/test/test_cmd_line.py
parent31b798d3c8592c84d36c7c9134a0bcbcb39dd92e (diff)
parent11942a58a190a235f69e8fb193d08a4fca2bcf3c (diff)
downloadcpython-39a73a4cfaac3cdd9592840ee3f6007593609789.zip
cpython-39a73a4cfaac3cdd9592840ee3f6007593609789.tar.gz
cpython-39a73a4cfaac3cdd9592840ee3f6007593609789.tar.bz2
Issue #7111: Python can now be run without a stdin, stdout or stderr stream.
It was already the case with Python 2. However, the corresponding sys module entries are now set to None (instead of an unusable file object).
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r--Lib/test/test_cmd_line.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 52e715c..70dfb17 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -285,6 +285,45 @@ class CmdLineTest(unittest.TestCase):
rc, out, err = assert_python_ok('-c', code)
self.assertEqual(b'', err)
+ # Issue #7111: Python should work without standard streams
+
+ @unittest.skipIf(os.name != 'posix', "test needs POSIX semantics")
+ def _test_no_stdio(self, streams):
+ code = """if 1:
+ import os, sys
+ for i, s in enumerate({streams}):
+ if getattr(sys, s) is not None:
+ os._exit(i + 1)
+ os._exit(42)""".format(streams=streams)
+ def preexec():
+ if 'stdin' in streams:
+ os.close(0)
+ if 'stdout' in streams:
+ os.close(1)
+ if 'stderr' in streams:
+ os.close(2)
+ p = subprocess.Popen(
+ [sys.executable, "-E", "-c", code],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ preexec_fn=preexec)
+ out, err = p.communicate()
+ self.assertEqual(test.support.strip_python_stderr(err), b'')
+ self.assertEqual(p.returncode, 42)
+
+ def test_no_stdin(self):
+ self._test_no_stdio(['stdin'])
+
+ def test_no_stdout(self):
+ self._test_no_stdio(['stdout'])
+
+ def test_no_stderr(self):
+ self._test_no_stdio(['stderr'])
+
+ def test_no_std_streams(self):
+ self._test_no_stdio(['stdin', 'stdout', 'stderr'])
+
def test_main():
test.support.run_unittest(CmdLineTest)