summaryrefslogtreecommitdiffstats
path: root/Programs/_testembed.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-14 20:01:51 (GMT)
committerGitHub <noreply@github.com>2019-05-14 20:01:51 (GMT)
commit91c99873d115b9796377d5056785f2abc987520f (patch)
treefa85c56756bcbb79abacbab186cd8db89bdec89f /Programs/_testembed.c
parente883091abf7ca84a88e956fe5202e75c53bd4128 (diff)
downloadcpython-91c99873d115b9796377d5056785f2abc987520f.zip
cpython-91c99873d115b9796377d5056785f2abc987520f.tar.gz
cpython-91c99873d115b9796377d5056785f2abc987520f.tar.bz2
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.
Diffstat (limited to 'Programs/_testembed.c')
-rw-r--r--Programs/_testembed.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index b125947..73b37c5 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -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 }
};