diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-11-13 18:59:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-13 18:59:26 (GMT) |
commit | 00b137c72f90fbc39a6cd7e48b37c58d19977180 (patch) | |
tree | 445883d4e7861725c81f7d067b1d0aea17dd0698 /Lib/test | |
parent | f966e5397ed8f5c42c185223fc9b4d750a678d02 (diff) | |
download | cpython-00b137c72f90fbc39a6cd7e48b37c58d19977180.zip cpython-00b137c72f90fbc39a6cd7e48b37c58d19977180.tar.gz cpython-00b137c72f90fbc39a6cd7e48b37c58d19977180.tar.bz2 |
bpo-35233: Fix _PyMainInterpreterConfig_Copy() (GH-10519)
* Fix _PyMainInterpreterConfig_Copy():
copy 'install_signal_handlers' attribute
* Add _PyMainInterpreterConfig_AsDict()
* Add unit tests on the main interpreter configuration
to test_embed.InitConfigTests
* test.pythoninfo: log also main_config
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/pythoninfo.py | 22 | ||||
-rw-r--r-- | Lib/test/test_embed.py | 42 |
2 files changed, 52 insertions, 12 deletions
diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py index 21763d5..2b5d6e2 100644 --- a/Lib/test/pythoninfo.py +++ b/Lib/test/pythoninfo.py @@ -534,15 +534,25 @@ def collect_gdbm(info_add): info_add('gdbm.GDBM_VERSION', '.'.join(map(str, _GDBM_VERSION))) -def collect_get_coreconfig(info_add): +def collect_get_config(info_add): + # Dump _PyCoreConfig and _PyMainInterpreterConfig try: from _testcapi import get_coreconfig except ImportError: - return + pass + else: + config = get_coreconfig() + for key in sorted(config): + info_add('core_config[%s]' % key, repr(config[key])) - config = get_coreconfig() - for key in sorted(config): - info_add('coreconfig[%s]' % key, repr(config[key])) + try: + from _testcapi import get_mainconfig + except ImportError: + pass + else: + config = get_mainconfig() + for key in sorted(config): + info_add('main_config[%s]' % key, repr(config[key])) def collect_info(info): @@ -573,7 +583,7 @@ def collect_info(info): collect_resource, collect_cc, collect_gdbm, - collect_get_coreconfig, + collect_get_config, # Collecting from tests should be last as they have side effects. collect_test_socket, diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 80233a5..cd10376 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -255,9 +255,11 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase): class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): maxDiff = 4096 + CORE_CONFIG_REGEX = re.compile(r"^core_config\[([^]]*)\] = (.*)$") + MAIN_CONFIG_REGEX = re.compile(r"^main_config\[([^]]*)\] = (.*)$") UTF8_MODE_ERRORS = ('surrogatepass' if sys.platform == 'win32' else 'surrogateescape') - DEFAULT_CONFIG = { + DEFAULT_CORE_CONFIG = { 'install_signal_handlers': 1, 'use_environment': 1, 'use_hash_seed': 0, @@ -338,7 +340,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): return out.split() def check_config(self, testname, expected): - expected = dict(self.DEFAULT_CONFIG, **expected) + expected = dict(self.DEFAULT_CORE_CONFIG, **expected) env = dict(os.environ) for key in list(env): @@ -367,11 +369,39 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): out, err = self.run_embedded_interpreter(testname, env=env) # Ignore err - config = {} + core_config = {} + main_config = {} for line in out.splitlines(): - key, value = line.split(' = ', 1) - config[key] = value - self.assertEqual(config, expected) + match = self.CORE_CONFIG_REGEX.match(line) + if match is not None: + key = match.group(1) + value = match.group(2) + core_config[key] = value + else: + match = self.MAIN_CONFIG_REGEX.match(line) + if match is None: + raise ValueError(f"failed to parse line {line!r}") + key = match.group(1) + value = match.group(2) + main_config[key] = value + self.assertEqual(core_config, expected) + + pycache_prefix = core_config['pycache_prefix'] + if pycache_prefix != NULL_STR: + pycache_prefix = repr(pycache_prefix) + else: + pycache_prefix = "NULL" + expected_main = { + 'install_signal_handlers': core_config['install_signal_handlers'], + 'argv': '[]', + 'prefix': repr(sys.prefix), + 'base_prefix': repr(sys.base_prefix), + 'base_exec_prefix': repr(sys.base_exec_prefix), + 'warnoptions': '[]', + 'xoptions': '{}', + 'pycache_prefix': pycache_prefix, + } + self.assertEqual(main_config, expected_main) def test_init_default_config(self): self.check_config("init_default_config", {}) |