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 !1
parent 0d53a6d1
...@@ -217,26 +217,27 @@ def test_pymain(): ...@@ -217,26 +217,27 @@ def test_pymain():
# -W <opt> # -W <opt>
_ = pyout(['-Werror', '-Whello', '-W', 'ignore::DeprecationWarning', _ = pyout(['-Werror', '-Whello', '-W', 'ignore::DeprecationWarning',
'testprog/print_warnings_setup.py'], cwd=here) 'testprog/print_warnings_setup.py'], cwd=here)
if PY2: assert re.match(
# py2 threading, which is imported after gpython startup, adds ignore br"sys\.warnoptions: \['error', 'hello', 'ignore::DeprecationWarning'\]\n\n"
# for sys.exc_clear br"warnings\.filters:\n"
_ = grepv(r'ignore:sys.exc_clear:DeprecationWarning:threading:*', _) br"(- [^\n]+\n)*" # Additional filters added by automatically imported modules
assert _.startswith( br"- ignore::DeprecationWarning::\*\n"
b"sys.warnoptions: ['error', 'hello', 'ignore::DeprecationWarning']\n\n" + \ br"- error::Warning::\*\n"
b"warnings.filters:\n" + \ br"(- [^\n]+\n)*", # Remaining filters
b"- ignore::DeprecationWarning::*\n" + \ _,
b"- error::Warning::*\n"), _ )
# $PYTHONWARNINGS # $PYTHONWARNINGS
_ = pyout(['testprog/print_warnings_setup.py'], cwd=here, _ = pyout(['testprog/print_warnings_setup.py'], cwd=here,
envadj={'PYTHONWARNINGS': 'ignore,world,error::SyntaxWarning'}) envadj={'PYTHONWARNINGS': 'ignore,world,error::SyntaxWarning'})
if PY2: assert re.match(
# see ^^^ br"sys\.warnoptions: \['ignore', 'world', 'error::SyntaxWarning'\]\n\n"
_ = grepv(r'ignore:sys.exc_clear:DeprecationWarning:threading:*', _) br"warnings\.filters:\n"
assert _.startswith( br"(- [^\n]+\n)*" # Additional filters added by automatically imported modules
b"sys.warnoptions: ['ignore', 'world', 'error::SyntaxWarning']\n\n" + \ br"- error::SyntaxWarning::\*\n"
b"warnings.filters:\n" + \ br"- ignore::Warning::\*\n"
b"- error::SyntaxWarning::*\n" + \ br"(- [^\n]+\n)*", # Remaining filters
b"- ignore::Warning::*\n"), _ _,
)
def test_pymain_print_function_future(): 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