summaryrefslogtreecommitdiffstats
path: root/Programs/_testembed.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-09-26 00:22:35 (GMT)
committerGitHub <noreply@github.com>2019-09-26 00:22:35 (GMT)
commit8bf39b606ef7b02c0279a80789f3c4824b0da5e9 (patch)
tree03064cc01948ed71ddf760e951436507f621d306 /Programs/_testembed.c
parentdf69e75edcc08475bc9a57a5a76df8a45bfc3c34 (diff)
downloadcpython-8bf39b606ef7b02c0279a80789f3c4824b0da5e9.zip
cpython-8bf39b606ef7b02c0279a80789f3c4824b0da5e9.tar.gz
cpython-8bf39b606ef7b02c0279a80789f3c4824b0da5e9.tar.bz2
bpo-38234: Add test_init_setpath_config() to test_embed (GH-16402)
* Add test_embed.test_init_setpath_config(): test Py_SetPath() with PyConfig. * test_init_setpath() and test_init_setpythonhome() no longer call Py_SetProgramName(), but use the default program name. * _PyPathConfig: isolated, site_import and base_executable fields are now only available on Windows. * If executable is set explicitly in the configuration, ignore calculated base_executable: _PyConfig_InitPathConfig() copies executable to base_executable. * Complete path config documentation.
Diffstat (limited to 'Programs/_testembed.c')
-rw-r--r--Programs/_testembed.c52
1 files changed, 25 insertions, 27 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index ed07606..14fca24 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -1425,8 +1425,6 @@ fail:
static int test_init_setpath(void)
{
- Py_SetProgramName(PROGRAM_NAME);
-
char *env = getenv("TESTPATH");
if (!env) {
fprintf(stderr, "missing TESTPATH env var\n");
@@ -1448,23 +1446,35 @@ static int test_init_setpath(void)
}
-static int mysetenv(const char *name, const char *value)
+static int test_init_setpath_config(void)
{
- size_t len = strlen(name) + 1 + strlen(value) + 1;
- char *env = PyMem_RawMalloc(len);
- if (env == NULL) {
- fprintf(stderr, "out of memory\n");
- return -1;
+ char *env = getenv("TESTPATH");
+ if (!env) {
+ fprintf(stderr, "missing TESTPATH env var\n");
+ return 1;
}
- strcpy(env, name);
- strcat(env, "=");
- strcat(env, value);
+ wchar_t *path = Py_DecodeLocale(env, NULL);
+ if (path == NULL) {
+ fprintf(stderr, "failed to decode TESTPATH\n");
+ return 1;
+ }
+ Py_SetPath(path);
+ PyMem_RawFree(path);
+ putenv("TESTPATH=");
- putenv(env);
+ PyStatus status;
+ PyConfig config;
- /* Don't call PyMem_RawFree(env), but leak env memory block:
- putenv() does not copy the string. */
+ status = PyConfig_InitPythonConfig(&config);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
+ config_set_string(&config, &config.program_name, L"conf_program_name");
+ config_set_string(&config, &config.executable, L"conf_executable");
+ init_from_config_clear(&config);
+ dump_config();
+ Py_Finalize();
return 0;
}
@@ -1485,19 +1495,6 @@ static int test_init_setpythonhome(void)
PyMem_RawFree(home);
putenv("TESTHOME=");
- char *path = getenv("TESTPATH");
- if (!path) {
- fprintf(stderr, "missing TESTPATH env var\n");
- return 1;
- }
-
- if (mysetenv("PYTHONPATH", path) < 0) {
- return 1;
- }
- putenv("TESTPATH=");
-
- Py_SetProgramName(PROGRAM_NAME);
-
Py_Initialize();
dump_config();
Py_Finalize();
@@ -1642,6 +1639,7 @@ static struct TestCase TestCases[] = {
{"test_init_main", test_init_main},
{"test_init_sys_add", test_init_sys_add},
{"test_init_setpath", test_init_setpath},
+ {"test_init_setpath_config", test_init_setpath_config},
{"test_init_setpythonhome", test_init_setpythonhome},
{"test_run_main", test_run_main},