From: Gregory P. Smith Date: Thu, 5 Feb 2015 01:16:30 +0000 (-0800) Subject: Make the stdlib test suite helper test.script_helper._assert_python no longer X-Git-Tag: v3.5.0a1~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7c60eb85d8e44216719dae0e4d8d1f90f24d00ad;p=python Make the stdlib test suite helper test.script_helper._assert_python no longer pass -I or -E to the child process by default when the environment is required for the child process interpreter to function properly. --- 7c60eb85d8e44216719dae0e4d8d1f90f24d00ad diff --cc Lib/test/script_helper.py index 619752ea89,8c599d1b04..5531a34b62 --- a/Lib/test/script_helper.py +++ b/Lib/test/script_helper.py @@@ -52,6 -52,7 +52,7 @@@ def interpreter_requires_environment() # Executing the interpreter in a subprocess def _assert_python(expected_success, *args, **env_vars): - env_required = _interpreter_requires_environment() ++ env_required = interpreter_requires_environment() if '__isolated' in env_vars: isolated = env_vars.pop('__isolated') else: diff --cc Lib/test/test_script_helper.py index a10e80122c,7540e2e99b..74333c9db8 --- a/Lib/test/test_script_helper.py +++ b/Lib/test/test_script_helper.py @@@ -33,9 -33,42 +33,42 @@@ class TestScriptHelper(unittest.TestCas self.assertIn('import sys; sys.exit(0)', error_msg, msg='unexpected command line.') + @mock.patch('subprocess.Popen') + def test_assert_python_isolated_when_env_not_required(self, mock_popen): + with mock.patch.object(script_helper, - '_interpreter_requires_environment', ++ 'interpreter_requires_environment', + return_value=False) as mock_ire_func: + mock_popen.side_effect = RuntimeError('bail out of unittest') + try: + script_helper._assert_python(True, '-c', 'None') + except RuntimeError as err: + self.assertEqual('bail out of unittest', err.args[0]) + self.assertEqual(1, mock_popen.call_count) + self.assertEqual(1, mock_ire_func.call_count) + popen_command = mock_popen.call_args[0][0] + self.assertEqual(sys.executable, popen_command[0]) + self.assertIn('None', popen_command) + self.assertIn('-I', popen_command) + self.assertNotIn('-E', popen_command) # -I overrides this + + @mock.patch('subprocess.Popen') + def test_assert_python_not_isolated_when_env_is_required(self, mock_popen): + """Ensure that -I is not passed when the environment is required.""" + with mock.patch.object(script_helper, - '_interpreter_requires_environment', ++ 'interpreter_requires_environment', + return_value=True) as mock_ire_func: + mock_popen.side_effect = RuntimeError('bail out of unittest') + try: + script_helper._assert_python(True, '-c', 'None') + except RuntimeError as err: + self.assertEqual('bail out of unittest', err.args[0]) + popen_command = mock_popen.call_args[0][0] + self.assertNotIn('-I', popen_command) + self.assertNotIn('-E', popen_command) + class TestScriptHelperEnvironment(unittest.TestCase): - """Code coverage for _interpreter_requires_environment().""" + """Code coverage for interpreter_requires_environment().""" def setUp(self): self.assertTrue(