]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
ci: Enable warnings-as-errors earlier 2519/head
authorBen Darnell <ben@bendarnell.com>
Sat, 20 Oct 2018 14:38:35 +0000 (10:38 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 20 Oct 2018 16:52:23 +0000 (12:52 -0400)
This catches import-time warnings in more modules, including a warning
about invalid escape sequences that is now an error on nightly python.

.travis.yml
tornado/httputil.py
tornado/test/runtests.py
tornado/test/web_test.py
tornado/util.py
tornado/web.py
tox.ini

index 4362c45ece49dd4ac7d04efbbde18f69ae2e141e..37cb8293380e7c7289b400f2a1ad8b249e4ee8a5 100644 (file)
@@ -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
index cb5142d548e8242651e2f25f34a20bedd8073bee..ec94b1b9db2cedc3afbc91dc1e7f92c54029d966 100644 (file)
@@ -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,
index 83711cc802acf98ac1aaaf7c4773724086276e37..dab76a2831eafd5569e4d01037a9e859209e1b80 100644 (file)
@@ -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.
index 87738ba3c7ba673fb4d83fb6f1d2619e02ac2448..e6ec9ad09b657300dda1df191ee08f6d38d12985 100644 (file)
@@ -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"],
index c4c019961ac2eeeb53e056185af7321698c9d85c..db0be6c8a4f25bc6b855de016e264a0d789fb681 100644 (file)
@@ -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
index a9d28a600afb4f790b1cc01fbc56294c509f587e..6089aaaade5b5aa1c017329d6114d26a8c7f1e9c 100644 (file)
@@ -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 03d4d040df39a353164a12174e8bfa625fb4bf5d..f20bb4f8acdcad9520985f01f8c136306c85b600 100644 (file)
--- 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