diff options
author | Gregory P. Smith <greg@krypto.org> | 2020-12-24 20:57:21 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-24 20:57:21 -0800 |
commit | 64abf373444944a240274a9b6d66d1cb01ecfcdd (patch) | |
tree | 7cc3f785fec2389d6dd9b7bd05860e45ee3f459c /Lib/test/test_subprocess.py | |
parent | 8badadec53cbf9dc049c5b54198c5689481e3f3f (diff) | |
download | cpython-64abf373444944a240274a9b6d66d1cb01ecfcdd.tar.gz cpython-64abf373444944a240274a9b6d66d1cb01ecfcdd.zip |
bpo-42388: Fix subprocess.check_output input=None when text=True (GH-23467)
When the modern text= spelling of the universal_newlines= parameter was added
for Python 3.7, check_output's special case around input=None was overlooked.
So it behaved differently with universal_newlines=True vs text=True. This
reconciles the behavior to be consistent and adds a test to guarantee it.
Also clarifies the existing check_output documentation.
Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r-- | Lib/test/test_subprocess.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 2a4c47530e6..70b54f4155a 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -204,6 +204,28 @@ class ProcessTestCase(BaseTestCase): input=b'pear') self.assertIn(b'PEAR', output) + def test_check_output_input_none(self): + """input=None has a legacy meaning of input='' on check_output.""" + output = subprocess.check_output( + [sys.executable, "-c", + "import sys; print('XX' if sys.stdin.read() else '')"], + input=None) + self.assertNotIn(b'XX', output) + + def test_check_output_input_none_text(self): + output = subprocess.check_output( + [sys.executable, "-c", + "import sys; print('XX' if sys.stdin.read() else '')"], + input=None, text=True) + self.assertNotIn('XX', output) + + def test_check_output_input_none_universal_newlines(self): + output = subprocess.check_output( + [sys.executable, "-c", + "import sys; print('XX' if sys.stdin.read() else '')"], + input=None, universal_newlines=True) + self.assertNotIn('XX', output) + def test_check_output_stdout_arg(self): # check_output() refuses to accept 'stdout' argument with self.assertRaises(ValueError) as c: |