Skip to content

Commit

Permalink
ci: Enable warnings-as-errors earlier
Browse files Browse the repository at this point in the history
This catches import-time warnings in more modules, including a warning
about invalid escape sequences that is now an error on nightly python.
  • Loading branch information
bdarnell committed Oct 20, 2018
1 parent f4ab48d commit 6dceb64
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Expand Up @@ -43,7 +43,8 @@ install:
#- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then travis_retry pip install pycares; fi
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then travis_retry pip install pycurl; fi
# Twisted is flaky on pypy (TODO: still? this note is quite old)
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then travis_retry pip install Twisted; fi
# It also sometimes has problems on nightly.
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* && $TRAVIS_PYTHON_VERSION != 'nightly' ]]; then travis_retry pip install Twisted; fi
# Ideally we'd run the lint stuff on the latest Python
# version supported. But Python 3.7 requires slower-to-start VMs,
# so we run it on 3.6 to minimize total CI run time.
Expand Down Expand Up @@ -83,6 +84,8 @@ script:
# run it with nightly cpython. Coverage is very slow on pypy.
- if [[ $TRAVIS_PYTHON_VERSION != nightly && $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then export RUN_COVERAGE=1; fi
- if [[ "$RUN_COVERAGE" == 1 ]]; then export TARGET="-m coverage run $TARGET"; fi
# See comments in tox.ini
- export PYTHONWARNINGS=error,ignore:::site
- python -bb $TARGET
- python -O $TARGET
- LANG=C python $TARGET
Expand All @@ -92,6 +95,7 @@ script:
# make coverage reports for Codecov to find
- if [[ "$RUN_COVERAGE" == 1 ]]; then coverage xml; fi
- export TORNADO_EXTENSION=0
- unset PYTHONWARNINGS
- if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]]; then (cd ../docs && mkdir sphinx-out && sphinx-build -E -n -W -b html . sphinx-out); fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]]; then (cd ../docs && mkdir sphinx-doctest-out && sphinx-build -E -n -b doctest . sphinx-out); fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then (cd .. && flake8); fi
Expand Down
2 changes: 1 addition & 1 deletion tornado/httputil.py
Expand Up @@ -100,7 +100,7 @@ def __missing__(self, key: str) -> str:
_normalized_headers = _NormalizedHeaderCache(1000)


class HTTPHeaders(collections.MutableMapping):
class HTTPHeaders(collections.abc.MutableMapping):
"""A dictionary that maintains ``Http-Header-Case`` for all keys.
Supports multiple values per key via a pair of new methods,
Expand Down
14 changes: 6 additions & 8 deletions tornado/test/runtests.py
Expand Up @@ -7,6 +7,7 @@
import textwrap
import sys
import unittest
import warnings

from tornado.httpclient import AsyncHTTPClient
from tornado.httpserver import HTTPServer
Expand Down Expand Up @@ -111,14 +112,11 @@ def flush(self):


def main():
# The -W command-line option does not work in a virtualenv with
# python 3 (as of virtualenv 1.7), so configure warnings
# programmatically instead.
import warnings

# Be strict about most warnings. This also turns on warnings that are
# ignored by default, including DeprecationWarnings and
# python 3.2's ResourceWarnings.
# Be strict about most warnings (This is set in our test running
# scripts to catch import-time warnings, but set it again here to
# be sure). This also turns on warnings that are ignored by
# default, including DeprecationWarnings and python 3.2's
# ResourceWarnings.
warnings.filterwarnings("error")
# setuptools sometimes gives ImportWarnings about things that are on
# sys.path even if they're not being used.
Expand Down
2 changes: 1 addition & 1 deletion tornado/test/web_test.py
Expand Up @@ -427,7 +427,7 @@ def test_absolute_auth_redirect(self):
self.assertEqual(response.code, 302)
self.assertTrue(
re.match(
"http://example.com/login\?next=http%3A%2F%2F127.0.0.1%3A[0-9]+%2Fabsolute",
r"http://example.com/login\?next=http%3A%2F%2F127.0.0.1%3A[0-9]+%2Fabsolute",
response.headers["Location"],
),
response.headers["Location"],
Expand Down
2 changes: 1 addition & 1 deletion tornado/util.py
Expand Up @@ -217,7 +217,7 @@ def _re_unescape_replacement(match: Match[str]) -> str:


def re_unescape(s: str) -> str:
"""Unescape a string escaped by `re.escape`.
r"""Unescape a string escaped by `re.escape`.
May raise ``ValueError`` for regular expressions which could not
have been produced by `re.escape` (for example, strings containing
Expand Down
2 changes: 1 addition & 1 deletion tornado/web.py
Expand Up @@ -1956,7 +1956,7 @@ def get_target_delegate(


class Application(ReversibleRouter):
"""A collection of request handlers that make up a web application.
r"""A collection of request handlers that make up a web application.
Instances of this class are callable and can be passed directly to
HTTPServer to serve the application::
Expand Down
12 changes: 12 additions & 0 deletions tox.ini
Expand Up @@ -86,6 +86,18 @@ commands =
# py3*: -b turns on an extra warning when calling
# str(bytes), and -bb makes it an error.
-bb \
# Treat warnings as errors by default. We have a whitelist of
# allowed warnings in runtests.py, but we want to be strict
# about any import-time warnings before that setup code is
# reached. Note that syntax warnings are only reported in
# -opt builds because regular builds reuse pycs created
# during sdist installation (and it doesn't seem to be
# possible to set environment variables during that phase of
# tox).
"-Werror" \
# Virtualenv hits a deprecation warning very early which we must
# suppress here.
"-Wignore:::site" \
# Python's optimized mode disables the assert statement, so
# run the tests in this mode to ensure we haven't fallen into
# the trap of relying on an assertion's side effects or using
Expand Down

0 comments on commit 6dceb64

Please sign in to comment.