Commit d10200c8 authored by Carlos Ramos Carreño's avatar Carlos Ramos Carreño Committed by Kirill Smelkov

gpython: tests: Fix test of warning filters.

The tests for gpython's handling of warning filters assumed that
the warnings passed in the command line were located on the top
of the warning filters list.
This is not true in the presence of automatically imported modules
that set warning filters, such as `_distutils_hack`, which
[used to filter deprecation warnings from distutils](https://github.com/pypa/setuptools/commit/5d60ccefb48329b7cedfe6d78fc1cb95683104b6).

We fix it by comparing against a regex which allows extra filters
above or below the ones we set.

--------
kirr: setuptools in between v55 to v60.3.1 was installing 'ignore'
'distutils deprecated' DeprecationWarning filter referenced above.
As the result with such setuptools test_pymain was failing:

    >       assert _.startswith(
                b"sys.warnoptions: ['ignore', 'world', 'error::SyntaxWarning']\n\n" + \
                b"warnings.filters:\n" + \
                b"- error::SyntaxWarning::*\n" + \
                b"- ignore::Warning::*\n"), _
    E       AssertionError: b"sys.warnoptions: ['ignore', 'world', 'error::SyntaxWarning']
    E
    E         warnings.filters:
    E         - ignore:.+ distutils\\b.+ deprec...::PendingDeprecationWarning::*	<-- NOTE
    E         - ignore::ImportWarning::*
    E         - ignore::ResourceWarning::*
    E         - ignore::PEP440Warning::*
    E         "

    ...

Since now we only selectively check for the presence of gpython
should-be installed filters, it is also ok to remove explicit `grep -v
for ignore:sys.exc_clear:DeprecationWarning:threading` on py2.

/reviewed-by @kirr
/reviewed-on kirr/pygolang!1
parent 0d53a6d1
......@@ -217,26 +217,27 @@ def test_pymain():
# -W <opt>
_ = pyout(['-Werror', '-Whello', '-W', 'ignore::DeprecationWarning',
'testprog/print_warnings_setup.py'], cwd=here)
if PY2:
# py2 threading, which is imported after gpython startup, adds ignore
# for sys.exc_clear
_ = grepv(r'ignore:sys.exc_clear:DeprecationWarning:threading:*', _)
assert _.startswith(
b"sys.warnoptions: ['error', 'hello', 'ignore::DeprecationWarning']\n\n" + \
b"warnings.filters:\n" + \
b"- ignore::DeprecationWarning::*\n" + \
b"- error::Warning::*\n"), _
assert re.match(
br"sys\.warnoptions: \['error', 'hello', 'ignore::DeprecationWarning'\]\n\n"
br"warnings\.filters:\n"
br"(- [^\n]+\n)*" # Additional filters added by automatically imported modules
br"- ignore::DeprecationWarning::\*\n"
br"- error::Warning::\*\n"
br"(- [^\n]+\n)*", # Remaining filters
_,
)
# $PYTHONWARNINGS
_ = pyout(['testprog/print_warnings_setup.py'], cwd=here,
envadj={'PYTHONWARNINGS': 'ignore,world,error::SyntaxWarning'})
if PY2:
# see ^^^
_ = grepv(r'ignore:sys.exc_clear:DeprecationWarning:threading:*', _)
assert _.startswith(
b"sys.warnoptions: ['ignore', 'world', 'error::SyntaxWarning']\n\n" + \
b"warnings.filters:\n" + \
b"- error::SyntaxWarning::*\n" + \
b"- ignore::Warning::*\n"), _
assert re.match(
br"sys\.warnoptions: \['ignore', 'world', 'error::SyntaxWarning'\]\n\n"
br"warnings\.filters:\n"
br"(- [^\n]+\n)*" # Additional filters added by automatically imported modules
br"- error::SyntaxWarning::\*\n"
br"- ignore::Warning::\*\n"
br"(- [^\n]+\n)*", # Remaining filters
_,
)
def test_pymain_print_function_future():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment