diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-09-29 23:40:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-29 23:40:17 (GMT) |
commit | fb4ae152a9930f0e00cae8b2807f534058cf341a (patch) | |
tree | 557401018629793ae3de044ca7024384a0e4f3fa /Programs/_testembed.c | |
parent | 58498bc7178608b1ab031994ca09c43889ce3e76 (diff) | |
download | cpython-fb4ae152a9930f0e00cae8b2807f534058cf341a.zip cpython-fb4ae152a9930f0e00cae8b2807f534058cf341a.tar.gz cpython-fb4ae152a9930f0e00cae8b2807f534058cf341a.tar.bz2 |
bpo-38317: Fix PyConfig.warnoptions priority (GH-16478)
Fix warnings options priority: PyConfig.warnoptions has the highest
priority, as stated in the PEP 587.
* Document options order in PyConfig.warnoptions documentation.
* Make PyWideStringList_INIT macro private: replace "Py" prefix
with "_Py".
* test_embed: add test_init_warnoptions().
Diffstat (limited to 'Programs/_testembed.c')
-rw-r--r-- | Programs/_testembed.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c index a375945..c8600d5 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1603,6 +1603,64 @@ static int test_init_setpythonhome(void) } +static int test_init_warnoptions(void) +{ + PyStatus status; + putenv("PYTHONWARNINGS=ignore:::env1,ignore:::env2"); + + PySys_AddWarnOption(L"ignore:::PySys_AddWarnOption1"); + PySys_AddWarnOption(L"ignore:::PySys_AddWarnOption2"); + + PyConfig config; + config.struct_size = sizeof(PyConfig); + + status = PyConfig_InitPythonConfig(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); + } + + config.dev_mode = 1; + config.bytes_warning = 1; + + config_set_program_name(&config); + + status = PyWideStringList_Append(&config.warnoptions, + L"ignore:::PyConfig_BeforeRead"); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); + } + + wchar_t* argv[] = { + L"python3", + L"-Wignore:::cmdline1", + L"-Wignore:::cmdline2"}; + config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); + config.parse_argv = 1; + + status = PyConfig_Read(&config); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); + } + + status = PyWideStringList_Append(&config.warnoptions, + L"ignore:::PyConfig_AfterRead"); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); + } + + status = PyWideStringList_Insert(&config.warnoptions, + 0, L"ignore:::PyConfig_Insert0"); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); + } + + init_from_config_clear(&config); + dump_config(); + Py_Finalize(); + return 0; +} + + static void configure_init_main(PyConfig *config) { wchar_t* argv[] = { @@ -1746,6 +1804,7 @@ static struct TestCase TestCases[] = { {"test_init_setpath", test_init_setpath}, {"test_init_setpath_config", test_init_setpath_config}, {"test_init_setpythonhome", test_init_setpythonhome}, + {"test_init_warnoptions", test_init_warnoptions}, {"test_run_main", test_run_main}, {"test_open_code_hook", test_open_code_hook}, |