From: Ben Darnell Date: Sat, 20 Oct 2018 14:38:35 +0000 (-0400) Subject: ci: Enable warnings-as-errors earlier X-Git-Tag: v6.0.0b1~24^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2519%2Fhead;p=thirdparty%2Ftornado.git ci: Enable warnings-as-errors earlier This catches import-time warnings in more modules, including a warning about invalid escape sequences that is now an error on nightly python. --- diff --git a/.travis.yml b/.travis.yml index 4362c45ec..37cb82933 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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. @@ -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 @@ -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 diff --git a/tornado/httputil.py b/tornado/httputil.py index cb5142d54..ec94b1b9d 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -100,7 +100,7 @@ class _NormalizedHeaderCache(dict): _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, diff --git a/tornado/test/runtests.py b/tornado/test/runtests.py index 83711cc80..dab76a283 100644 --- a/tornado/test/runtests.py +++ b/tornado/test/runtests.py @@ -7,6 +7,7 @@ import operator import textwrap import sys import unittest +import warnings from tornado.httpclient import AsyncHTTPClient from tornado.httpserver import HTTPServer @@ -111,14 +112,11 @@ class CountingStderr(io.IOBase): 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. diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 87738ba3c..e6ec9ad09 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -427,7 +427,7 @@ class AuthRedirectTest(WebTestCase): 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"], diff --git a/tornado/util.py b/tornado/util.py index c4c019961..db0be6c8a 100644 --- a/tornado/util.py +++ b/tornado/util.py @@ -217,7 +217,7 @@ _re_unescape_pattern = re.compile(r"\\(.)", re.DOTALL) 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 diff --git a/tornado/web.py b/tornado/web.py index a9d28a600..6089aaaad 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1956,7 +1956,7 @@ class _ApplicationRouter(ReversibleRuleRouter): 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:: diff --git a/tox.ini b/tox.ini index 03d4d040d..f20bb4f8a 100644 --- a/tox.ini +++ b/tox.ini @@ -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