bpo-36763: Add test for _PyCoreConfig_SetString() (GH-13275)

test_embed: add test_init_read_set() to test newly added APIs: test
module_search_paths and executable.
This commit is contained in:
Victor Stinner 2019-05-14 22:01:51 +02:00 • committed by GitHub
parent e883091abf
commit 91c99873d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 7 deletions

View file

@ -1,4 +1,10 @@
/* FIXME: PEP 587 makes these functions public */
#ifndef Py_BUILD_CORE_MODULE
# define Py_BUILD_CORE_MODULE
#endif
#include <Python.h>
#include "pycore_coreconfig.h" /* FIXME: PEP 587 makes these functions public */
#include "pythread.h"
#include <inttypes.h>
#include <stdio.h>
@ -679,6 +685,47 @@ static int test_init_dev_mode(void)
}
static int test_init_read_set(void)
{
_PyInitError err;
_PyCoreConfig config = _PyCoreConfig_INIT;
err = _PyCoreConfig_DecodeLocale(&config.program_name, "./init_read_set");
if (_Py_INIT_FAILED(err)) {
goto fail;
}
err = _PyCoreConfig_Read(&config);
if (_Py_INIT_FAILED(err)) {
goto fail;
}
if (_PyWstrList_Append(&config.module_search_paths,
L"init_read_set_path") < 0) {
err = _Py_INIT_NO_MEMORY();
goto fail;
}
/* override executable computed by _PyCoreConfig_Read() */
err = _PyCoreConfig_SetString(&config.executable, L"my_executable");
if (_Py_INIT_FAILED(err)) {
goto fail;
}
err = _Py_InitializeFromConfig(&config);
_PyCoreConfig_Clear(&config);
if (_Py_INIT_FAILED(err)) {
goto fail;
}
dump_config();
Py_Finalize();
return 0;
fail:
_Py_ExitInitError(err);
}
static int test_run_main(void)
{
_PyCoreConfig config = _PyCoreConfig_INIT;
@ -736,6 +783,7 @@ static struct TestCase TestCases[] = {
{ "init_isolated", test_init_isolated },
{ "preinit_isolated1", test_preinit_isolated1 },
{ "preinit_isolated2", test_preinit_isolated2 },
{ "init_read_set", test_init_read_set },
{ "run_main", test_run_main },
{ NULL, NULL }
};