Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def run_embedded_interpreter(self, *args, env=None):
return out, err

def run_repeated_init_and_subinterpreters(self):
out, err = self.run_embedded_interpreter("repeated_init_and_subinterpreters")
out, err = self.run_embedded_interpreter("test_repeated_init_and_subinterpreters")
self.assertEqual(err, "")

# The output from _testembed looks like this:
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_subinterps_distinct_state(self):
def test_forced_io_encoding(self):
# Checks forced configuration of embedded interpreter IO streams
env = dict(os.environ, PYTHONIOENCODING="utf-8:surrogateescape")
out, err = self.run_embedded_interpreter("forced_io_encoding", env=env)
out, err = self.run_embedded_interpreter("test_forced_io_encoding", env=env)
if support.verbose > 1:
print()
print(out)
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_pre_initialization_api(self):
is initialized (via Py_Initialize()).
"""
env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path))
out, err = self.run_embedded_interpreter("pre_initialization_api", env=env)
out, err = self.run_embedded_interpreter("test_pre_initialization_api", env=env)
if MS_WINDOWS:
expected_path = self.test_exe
else:
Expand All @@ -234,7 +234,7 @@ def test_pre_initialization_sys_options(self):
"""
env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path))
out, err = self.run_embedded_interpreter(
"pre_initialization_sys_options", env=env)
"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"
Expand All @@ -249,7 +249,7 @@ def test_bpo20891(self):
calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
call PyEval_InitThreads() for us in this case.
"""
out, err = self.run_embedded_interpreter("bpo20891")
out, err = self.run_embedded_interpreter("test_bpo20891")
self.assertEqual(out, '')
self.assertEqual(err, '')

Expand All @@ -258,20 +258,20 @@ def test_initialize_twice(self):
bpo-33932: Calling Py_Initialize() twice should do nothing (and not
crash!).
"""
out, err = self.run_embedded_interpreter("initialize_twice")
out, err = self.run_embedded_interpreter("test_initialize_twice")
self.assertEqual(out, '')
self.assertEqual(err, '')

def test_initialize_pymain(self):
"""
bpo-34008: Calling Py_Main() after Py_Initialize() must not fail.
"""
out, err = self.run_embedded_interpreter("initialize_pymain")
out, err = self.run_embedded_interpreter("test_initialize_pymain")
self.assertEqual(out.rstrip(), "Py_Main() after Py_Initialize: sys.argv=['-c', 'arg2']")
self.assertEqual(err, '')

def test_run_main(self):
out, err = self.run_embedded_interpreter("run_main")
out, err = self.run_embedded_interpreter("test_run_main")
self.assertEqual(out.rstrip(), "_Py_RunMain(): sys.argv=['-c', 'arg2']")
self.assertEqual(err, '')

Expand Down Expand Up @@ -632,13 +632,13 @@ def check_config(self, testname, expected_config=None,
self.check_global_config(config)

def test_init_default_config(self):
self.check_config("init_initialize_config", api=API_COMPAT)
self.check_config("test_init_initialize_config", api=API_COMPAT)

def test_preinit_compat_config(self):
self.check_config("preinit_compat_config", api=API_COMPAT)
self.check_config("test_preinit_compat_config", api=API_COMPAT)

def test_init_compat_config(self):
self.check_config("init_compat_config", api=API_COMPAT)
self.check_config("test_init_compat_config", api=API_COMPAT)

def test_init_global_config(self):
preconfig = {
Expand All @@ -660,7 +660,7 @@ def test_init_global_config(self):
'user_site_directory': 0,
'pathconfig_warnings': 0,
}
self.check_config("init_global_config", config, preconfig,
self.check_config("test_init_global_config", config, preconfig,
api=API_COMPAT)

def test_init_from_config(self):
Expand Down Expand Up @@ -705,7 +705,7 @@ def test_init_from_config(self):
'check_hash_pycs_mode': 'always',
'pathconfig_warnings': 0,
}
self.check_config("init_from_config", config, preconfig,
self.check_config("test_init_from_config", config, preconfig,
api=API_COMPAT)

def test_init_env(self):
Expand All @@ -732,23 +732,23 @@ def test_init_env(self):
'faulthandler': 1,
'warnoptions': ['EnvVar'],
}
self.check_config("init_env", config, preconfig,
self.check_config("test_init_env", config, preconfig,
api=API_COMPAT)

def test_init_env_dev_mode(self):
preconfig = dict(allocator=PYMEM_ALLOCATOR_DEBUG)
config = dict(dev_mode=1,
faulthandler=1,
warnoptions=['default'])
self.check_config("init_env_dev_mode", config, preconfig,
self.check_config("test_init_env_dev_mode", config, preconfig,
api=API_COMPAT)

def test_init_env_dev_mode_alloc(self):
preconfig = dict(allocator=PYMEM_ALLOCATOR_MALLOC)
config = dict(dev_mode=1,
faulthandler=1,
warnoptions=['default'])
self.check_config("init_env_dev_mode_alloc", config, preconfig,
self.check_config("test_init_env_dev_mode_alloc", config, preconfig,
api=API_COMPAT)

def test_init_dev_mode(self):
Expand All @@ -760,7 +760,7 @@ def test_init_dev_mode(self):
'dev_mode': 1,
'warnoptions': ['default'],
}
self.check_config("init_dev_mode", config, preconfig,
self.check_config("test_init_dev_mode", config, preconfig,
api=API_PYTHON)

def test_preinit_parse_argv(self):
Expand All @@ -777,7 +777,7 @@ def test_preinit_parse_argv(self):
'warnoptions': ['default'],
'xoptions': ['dev'],
}
self.check_config("preinit_parse_argv", config, preconfig,
self.check_config("test_preinit_parse_argv", config, preconfig,
api=API_PYTHON)

def test_preinit_dont_parse_argv(self):
Expand All @@ -790,7 +790,7 @@ def test_preinit_dont_parse_argv(self):
"-X", "dev", "-X", "utf8", "script.py"],
'isolated': 0,
}
self.check_config("preinit_dont_parse_argv", config, preconfig,
self.check_config("test_preinit_dont_parse_argv", config, preconfig,
api=API_ISOLATED)

def test_init_isolated_flag(self):
Expand All @@ -799,7 +799,7 @@ def test_init_isolated_flag(self):
'use_environment': 0,
'user_site_directory': 0,
}
self.check_config("init_isolated_flag", config, api=API_PYTHON)
self.check_config("test_init_isolated_flag", config, api=API_PYTHON)

def test_preinit_isolated1(self):
# _PyPreConfig.isolated=1, _PyCoreConfig.isolated not set
Expand All @@ -808,7 +808,7 @@ def test_preinit_isolated1(self):
'use_environment': 0,
'user_site_directory': 0,
}
self.check_config("preinit_isolated1", config, api=API_COMPAT)
self.check_config("test_preinit_isolated1", config, api=API_COMPAT)

def test_preinit_isolated2(self):
# _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1
Expand All @@ -817,32 +817,35 @@ def test_preinit_isolated2(self):
'use_environment': 0,
'user_site_directory': 0,
}
self.check_config("preinit_isolated2", config, api=API_COMPAT)
self.check_config("test_preinit_isolated2", config, api=API_COMPAT)

def test_preinit_isolated_config(self):
self.check_config("preinit_isolated_config", api=API_ISOLATED)
self.check_config("test_preinit_isolated_config", api=API_ISOLATED)

def test_init_isolated_config(self):
self.check_config("init_isolated_config", api=API_ISOLATED)
self.check_config("test_init_isolated_config", api=API_ISOLATED)

def test_preinit_python_config(self):
self.check_config("test_preinit_python_config", api=API_PYTHON)

def test_init_python_config(self):
self.check_config("init_python_config", api=API_PYTHON)
self.check_config("test_init_python_config", api=API_PYTHON)

def test_init_dont_configure_locale(self):
# _PyPreConfig.configure_locale=0
preconfig = {
'configure_locale': 0,
'coerce_c_locale': 0,
}
self.check_config("init_dont_configure_locale", {}, preconfig,
self.check_config("test_init_dont_configure_locale", {}, preconfig,
api=API_PYTHON)

def test_init_read_set(self):
core_config = {
'program_name': './init_read_set',
'executable': 'my_executable',
}
self.check_config("init_read_set", core_config,
self.check_config("test_init_read_set", core_config,
api=API_PYTHON,
add_path="init_read_set_path")

Expand All @@ -855,7 +858,7 @@ def test_init_run_main(self):
'run_command': code + '\n',
'parse_argv': 1,
}
self.check_config("init_run_main", core_config, api=API_PYTHON)
self.check_config("test_init_run_main", core_config, api=API_PYTHON)

def test_init_main(self):
code = ('import _testinternalcapi, json; '
Expand All @@ -867,7 +870,7 @@ def test_init_main(self):
'parse_argv': 1,
'_init_main': 0,
}
self.check_config("init_main", core_config,
self.check_config("test_init_main", core_config,
api=API_PYTHON,
stderr="Run Python code before _Py_InitializeMain")

Expand All @@ -879,7 +882,7 @@ def test_init_parse_argv(self):
'run_command': 'pass\n',
'use_environment': 0,
}
self.check_config("init_parse_argv", core_config, api=API_PYTHON)
self.check_config("test_init_parse_argv", core_config, api=API_PYTHON)

def test_init_dont_parse_argv(self):
pre_config = {
Expand All @@ -890,7 +893,7 @@ def test_init_dont_parse_argv(self):
'argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'],
'program_name': './argv0',
}
self.check_config("init_dont_parse_argv", core_config, pre_config,
self.check_config("test_init_dont_parse_argv", core_config, pre_config,
api=API_PYTHON)


Expand Down
66 changes: 33 additions & 33 deletions Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,39 +1243,39 @@ struct TestCase
};

static struct TestCase TestCases[] = {
{ "forced_io_encoding", test_forced_io_encoding },
{ "repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters },
{ "pre_initialization_api", test_pre_initialization_api },
{ "pre_initialization_sys_options", test_pre_initialization_sys_options },
{ "bpo20891", test_bpo20891 },
{ "initialize_twice", test_initialize_twice },
{ "initialize_pymain", test_initialize_pymain },
{ "init_initialize_config", test_init_initialize_config },
{ "preinit_compat_config", test_preinit_compat_config },
{ "init_compat_config", test_init_compat_config },
{ "init_global_config", test_init_global_config },
{ "init_from_config", test_init_from_config },
{ "init_parse_argv", test_init_parse_argv },
{ "init_dont_parse_argv", test_init_dont_parse_argv },
{ "init_env", test_init_env },
{ "init_env_dev_mode", test_init_env_dev_mode },
{ "init_env_dev_mode_alloc", test_init_env_dev_mode_alloc },
{ "init_dont_configure_locale", test_init_dont_configure_locale },
{ "init_dev_mode", test_init_dev_mode },
{ "init_isolated_flag", test_init_isolated_flag },
{ "preinit_isolated_config", test_preinit_isolated_config },
{ "init_isolated_config", test_init_isolated_config },
{ "preinit_python_config", test_preinit_python_config },
{ "init_python_config", test_init_python_config },
{ "preinit_isolated1", test_preinit_isolated1 },
{ "preinit_isolated2", test_preinit_isolated2 },
{ "preinit_parse_argv", test_preinit_parse_argv },
{ "preinit_dont_parse_argv", test_preinit_dont_parse_argv },
{ "init_read_set", test_init_read_set },
{ "init_run_main", test_init_run_main },
{ "init_main", test_init_main },
{ "run_main", test_run_main },
{ NULL, NULL }
{"test_forced_io_encoding", test_forced_io_encoding},
{"test_repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters},
{"test_pre_initialization_api", test_pre_initialization_api},
{"test_pre_initialization_sys_options", test_pre_initialization_sys_options},
{"test_bpo20891", test_bpo20891},
{"test_initialize_twice", test_initialize_twice},
{"test_initialize_pymain", test_initialize_pymain},
{"test_init_initialize_config", test_init_initialize_config},
{"test_preinit_compat_config", test_preinit_compat_config},
{"test_init_compat_config", test_init_compat_config},
{"test_init_global_config", test_init_global_config},
{"test_init_from_config", test_init_from_config},
{"test_init_parse_argv", test_init_parse_argv},
{"test_init_dont_parse_argv", test_init_dont_parse_argv},
{"test_init_env", test_init_env},
{"test_init_env_dev_mode", test_init_env_dev_mode},
{"test_init_env_dev_mode_alloc", test_init_env_dev_mode_alloc},
{"test_init_dont_configure_locale", test_init_dont_configure_locale},
{"test_init_dev_mode", test_init_dev_mode},
{"test_init_isolated_flag", test_init_isolated_flag},
{"test_preinit_isolated_config", test_preinit_isolated_config},
{"test_init_isolated_config", test_init_isolated_config},
{"test_preinit_python_config", test_preinit_python_config},
{"test_init_python_config", test_init_python_config},
{"test_preinit_isolated1", test_preinit_isolated1},
{"test_preinit_isolated2", test_preinit_isolated2},
{"test_preinit_parse_argv", test_preinit_parse_argv},
{"test_preinit_dont_parse_argv", test_preinit_dont_parse_argv},
{"test_init_read_set", test_init_read_set},
{"test_init_run_main", test_init_run_main},
{"test_init_main", test_init_main},
{"test_run_main", test_run_main},
{NULL, NULL}
};

int main(int argc, char *argv[])
Expand Down
Loading