bpo-36763: InitConfigTests tests all core config by vstinner · Pull Request #13331 · python/cpython
# core config UNTESTED_CORE_CONFIG = ( # FIXME: untested core configuration variables 'dll_path', 'module_search_paths', ) # Mark config which should be get by get_default_config() GET_DEFAULT_CONFIG = object() DEFAULT_PRE_CONFIG = {
'site_import': 1, 'bytes_warning': 0,
configs = _testinternalcapi.get_configs() core_config = configs['core_config'] data = { 'stdio_encoding': sys.stdout.encoding, 'stdio_errors': sys.stdout.errors,
data = json.dumps(data) data = data.encode('utf-8')
# Use -S to not import the site module: get the proper configuration # when test_embed is run from a venv (bpo-35313) args = (sys.executable, '-S', '-c', code) args = [sys.executable, '-S', '-c', code] env = dict(env) if not expected['isolated']: env['PYTHONCOERCECLOCALE'] = '0'
if add_path is not None: expected['module_search_paths'].append(add_path) return expected
def check_pre_config(self, config, expected): pre_config = dict(config['pre_config']) core_config = dict(config['core_config']) self.assertEqual(pre_config, expected)
def check_core_config(self, config, expected, add_path=None): def check_core_config(self, config, expected): core_config = dict(config['core_config']) if add_path is not None: paths = [*expected['module_search_paths'], add_path] if not paths[0]: del paths[0] self.assertEqual(core_config['module_search_paths'], paths) for key in self.UNTESTED_CORE_CONFIG: core_config.pop(key, None) expected.pop(key, None) self.assertEqual(core_config, expected)
def check_global_config(self, config):
self.check_pre_config(config, expected_preconfig) self.check_core_config(config, expected_config, add_path) self.check_core_config(config, expected_config) self.check_global_config(config)
def test_init_default_config(self):
def test_run_main_config(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("run_main_config", core_config, preconfig)
if __name__ == "__main__": unittest.main()