diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-16 15:38:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-16 15:38:16 (GMT) |
commit | 9ef5dcaa0b3c7c7ba28dbb3ec0c9507d9d05e3a9 (patch) | |
tree | 56b9b45660cc83960c2752e22ee47090632ebb09 /Lib | |
parent | ae239f6b0626e926613a4a1dbafa323bd41fec32 (diff) | |
download | cpython-9ef5dcaa0b3c7c7ba28dbb3ec0c9507d9d05e3a9.zip cpython-9ef5dcaa0b3c7c7ba28dbb3ec0c9507d9d05e3a9.tar.gz cpython-9ef5dcaa0b3c7c7ba28dbb3ec0c9507d9d05e3a9.tar.bz2 |
bpo-36763: Add _Py_InitializeMain() (GH-13362)
* Add a private _Py_InitializeMain() function.
* Add again _PyCoreConfig._init_main.
* _Py_InitializeFromConfig() now uses _init_main to decide
if _Py_InitializeMainInterpreter() should be called.
* _PyCoreConfig: rename _frozen to pathconfig_warnings, its value is
now the opposite of Py_FrozenFlag.
* Add an unit test for _init_main=0 and _Py_InitializeMain().
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_embed.py | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 3fabe5f..c3c1a3e 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -343,7 +343,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): '_install_importlib': 1, 'check_hash_pycs_mode': 'default', - '_frozen': 0, + 'pathconfig_warnings': 1, + '_init_main': 1, } if MS_WINDOWS: DEFAULT_PRE_CONFIG.update({ @@ -371,7 +372,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): ('Py_DontWriteBytecodeFlag', 'write_bytecode', True), ('Py_FileSystemDefaultEncodeErrors', 'filesystem_errors'), ('Py_FileSystemDefaultEncoding', 'filesystem_encoding'), - ('Py_FrozenFlag', '_frozen'), + ('Py_FrozenFlag', 'pathconfig_warnings', True), ('Py_IgnoreEnvironmentFlag', 'use_environment', True), ('Py_InspectFlag', 'inspect'), ('Py_InteractiveFlag', 'interactive'), @@ -500,7 +501,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): self.assertEqual(config['global_config'], expected) - def check_config(self, testname, expected_config, expected_preconfig, add_path=None): + def check_config(self, testname, expected_config, expected_preconfig, + add_path=None, stderr=None): env = dict(os.environ) # Remove PYTHON* environment variables to get deterministic environment for key in list(env): @@ -511,19 +513,22 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): env['PYTHONCOERCECLOCALE'] = '0' env['PYTHONUTF8'] = '0' - out, err = self.run_embedded_interpreter(testname, env=env) - # Ignore err - try: - config = json.loads(out) - except json.JSONDecodeError: - self.fail(f"fail to decode stdout: {out!r}") - expected_preconfig = dict(self.DEFAULT_PRE_CONFIG, **expected_preconfig) expected_config = self.get_expected_config(expected_config, env, add_path) for key in self.COPY_PRE_CONFIG: if key not in expected_preconfig: expected_preconfig[key] = expected_config[key] + out, err = self.run_embedded_interpreter(testname, env=env) + if stderr is None and not expected_config['verbose']: + stderr = "" + if stderr is not None: + self.assertEqual(err.rstrip(), stderr) + try: + config = json.loads(out) + except json.JSONDecodeError: + self.fail(f"fail to decode stdout: {out!r}") + self.check_pre_config(config, expected_preconfig) self.check_core_config(config, expected_config) self.check_global_config(config) @@ -689,7 +694,19 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): self.check_config("init_read_set", core_config, preconfig, add_path="init_read_set_path") - def test_run_main_config(self): + def test_init_run_main(self): + preconfig = {} + code = ('import _testinternalcapi, json; ' + 'print(json.dumps(_testinternalcapi.get_configs()))') + core_config = { + 'argv': ['-c', 'arg2'], + 'program': 'python3', + 'program_name': './python3', + 'run_command': code + '\n', + } + self.check_config("init_run_main", core_config, preconfig) + + def test_init_main(self): preconfig = {} code = ('import _testinternalcapi, json; ' 'print(json.dumps(_testinternalcapi.get_configs()))') @@ -698,8 +715,10 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'program': 'python3', 'program_name': './python3', 'run_command': code + '\n', + '_init_main': 0, } - self.check_config("run_main_config", core_config, preconfig) + self.check_config("init_main", core_config, preconfig, + stderr="Run Python code before _Py_InitializeMain") def test_init_dont_parse_argv(self): core_config = { |