Skip to content

Commit

Permalink
Add test_initconfig_exit()
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Mar 14, 2024
1 parent 65e49ac commit f5b24f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,9 @@ def test_initconfig_api(self):
self.check_all_configs("test_initconfig_api", config, preconfig,
api=API_PYTHON)

def test_initconfig_exit(self):
self.run_embedded_interpreter("test_initconfig_exit")

def test_get_argc_argv(self):
self.run_embedded_interpreter("test_get_argc_argv")
# ignore output
Expand Down
28 changes: 28 additions & 0 deletions Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,33 @@ static int test_initconfig_api(void)
}


static int test_initconfig_exit(void)
{
PyInitConfig *config = PyInitConfig_Python_New();
if (config == NULL) {
printf("Init allocation error\n");
return 1;
}

wchar_t *argv[] = {PROGRAM_NAME, L"--help"};
assert(PyInitConfig_SetWStrList(config, "argv",
Py_ARRAY_LENGTH(argv), argv) == 0);

assert(Py_InitializeFromInitConfig(config) < 0);

int exitcode;
assert(PyInitConfig_GetExitCode(config, &exitcode) == 1);
assert(exitcode == 0);

const char *err_msg;
assert(PyInitConfig_GetError(config, &err_msg) == 1);
assert(strcmp(err_msg, "exit code 0") == 0);

PyInitConfig_Free(config);
return 0;
}


static void configure_init_main(PyConfig *config)
{
wchar_t* argv[] = {
Expand Down Expand Up @@ -2258,6 +2285,7 @@ static struct TestCase TestCases[] = {
{"test_init_warnoptions", test_init_warnoptions},
{"test_init_set_config", test_init_set_config},
{"test_initconfig_api", test_initconfig_api},
{"test_initconfig_exit", test_initconfig_exit},
{"test_run_main", test_run_main},
{"test_run_main_loop", test_run_main_loop},
{"test_get_argc_argv", test_get_argc_argv},
Expand Down

0 comments on commit f5b24f2

Please sign in to comment.