diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-10-13 17:08:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 17:08:19 (GMT) |
commit | db2b6a20cd35781b2f5e798e880e57e6cf9b97aa (patch) | |
tree | 316124de83275184a817e1d543f9b8200c785466 /Lib | |
parent | 1c831353816ff699b54e804047a7242a09e98f5b (diff) | |
download | cpython-db2b6a20cd35781b2f5e798e880e57e6cf9b97aa.zip cpython-db2b6a20cd35781b2f5e798e880e57e6cf9b97aa.tar.gz cpython-db2b6a20cd35781b2f5e798e880e57e6cf9b97aa.tar.bz2 |
bpo-45445: Fail if an invalid X-option is provided in the command line (GH-28823)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_audit.py | 4 | ||||
-rw-r--r-- | Lib/test/test_cmd_line.py | 13 | ||||
-rw-r--r-- | Lib/test/test_embed.py | 23 |
3 files changed, 25 insertions, 15 deletions
diff --git a/Lib/test/test_audit.py b/Lib/test/test_audit.py index c5ce263..d99b3b7 100644 --- a/Lib/test/test_audit.py +++ b/Lib/test/test_audit.py @@ -18,7 +18,7 @@ AUDIT_TESTS_PY = support.findfile("audit-tests.py") class AuditTest(unittest.TestCase): def do_test(self, *args): with subprocess.Popen( - [sys.executable, "-X utf8", AUDIT_TESTS_PY, *args], + [sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args], encoding="utf-8", stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -32,7 +32,7 @@ class AuditTest(unittest.TestCase): def run_python(self, *args): events = [] with subprocess.Popen( - [sys.executable, "-X utf8", AUDIT_TESTS_PY, *args], + [sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args], encoding="utf-8", stdout=subprocess.PIPE, stderr=subprocess.PIPE, diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index d93e98f..1dc8c45 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -83,8 +83,17 @@ class CmdLineTest(unittest.TestCase): opts = get_xoptions() self.assertEqual(opts, {}) - opts = get_xoptions('-Xa', '-Xb=c,d=e') - self.assertEqual(opts, {'a': True, 'b': 'c,d=e'}) + opts = get_xoptions('-Xno_debug_ranges', '-Xdev=1234') + self.assertEqual(opts, {'no_debug_ranges': True, 'dev': '1234'}) + + @unittest.skipIf(interpreter_requires_environment(), + 'Cannot run -E tests when PYTHON env vars are required.') + def test_unknown_xoptions(self): + rc, out, err = assert_python_failure('-X', 'blech') + self.assertIn(b'Unknown value for option -X', err) + msg = b'Fatal Python error: Unknown value for option -X' + self.assertEqual(err.splitlines().count(msg), 1) + self.assertEqual(b'', out) def test_showrefcount(self): def run_python(*args): diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 31c5c3e..41e0920 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -273,7 +273,7 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase): "test_pre_initialization_sys_options", env=env) expected_output = ( "sys.warnoptions: ['once', 'module', 'default']\n" - "sys._xoptions: {'not_an_option': '1', 'also_not_an_option': '2'}\n" + "sys._xoptions: {'dev': '2', 'utf8': '1'}\n" "warnings.filters[:3]: ['default', 'module', 'once']\n" ) self.assertIn(expected_output, out) @@ -820,15 +820,14 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'argv': ['-c', 'arg2'], 'orig_argv': ['python3', '-W', 'cmdline_warnoption', - '-X', 'cmdline_xoption', + '-X', 'dev', '-c', 'pass', 'arg2'], 'parse_argv': 2, 'xoptions': [ - 'config_xoption1=3', - 'config_xoption2=', - 'config_xoption3', - 'cmdline_xoption', + 'dev=3', + 'utf8', + 'dev', ], 'warnoptions': [ 'cmdline_warnoption', @@ -1046,9 +1045,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): config = { 'faulthandler': 1, 'xoptions': [ - 'config_xoption', - 'cmdline_xoption', - 'sysadd_xoption', + 'dev', + 'utf8', 'faulthandler', ], 'warnoptions': [ @@ -1058,9 +1056,12 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): ], 'orig_argv': ['python3', '-W', 'ignore:::cmdline_warnoption', - '-X', 'cmdline_xoption'], + '-X', 'utf8'], } - self.check_all_configs("test_init_sys_add", config, api=API_PYTHON) + preconfig = {'utf8_mode': 1} + self.check_all_configs("test_init_sys_add", config, + expected_preconfig=preconfig, + api=API_PYTHON) def test_init_run_main(self): code = ('import _testinternalcapi, json; ' |