diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-09-29 23:58:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-29 23:58:57 (GMT) |
commit | c9ed9e6fc76323ed537fb79d4232bcd27d82c57e (patch) | |
tree | 32a06498ac936f1d1fded02332c6b5026b59032b /Programs/_testembed.c | |
parent | 19cd5951ec4480c7cfcbcc379b36902312cfb8b8 (diff) | |
download | cpython-c9ed9e6fc76323ed537fb79d4232bcd27d82c57e.zip cpython-c9ed9e6fc76323ed537fb79d4232bcd27d82c57e.tar.gz cpython-c9ed9e6fc76323ed537fb79d4232bcd27d82c57e.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().
(cherry picked from commit fb4ae152a9930f0e00cae8b2807f534058cf341a)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
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}, |