From: Pierce Lopez Date: Wed, 3 Jan 2018 05:20:33 +0000 (-0500) Subject: style fix: wrap or ignore long lines in remaining tests X-Git-Tag: v5.0.0~20^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2237%2Fhead;p=thirdparty%2Ftornado.git style fix: wrap or ignore long lines in remaining tests --- diff --git a/tornado/test/auth_test.py b/tornado/test/auth_test.py index 400fc4f45..d79c365a8 100644 --- a/tornado/test/auth_test.py +++ b/tornado/test/auth_test.py @@ -5,7 +5,11 @@ from __future__ import absolute_import, division, print_function -from tornado.auth import OpenIdMixin, OAuthMixin, OAuth2Mixin, TwitterMixin, AuthError, GoogleOAuth2Mixin, FacebookGraphMixin + +from tornado.auth import ( + AuthError, OpenIdMixin, OAuthMixin, OAuth2Mixin, + GoogleOAuth2Mixin, FacebookGraphMixin, TwitterMixin, +) from tornado.concurrent import Future from tornado.escape import json_decode from tornado import gen @@ -294,10 +298,14 @@ class AuthTest(AsyncHTTPTestCase): ('/facebook/client/login', FacebookClientLoginHandler, dict(test=self)), ('/twitter/client/login', TwitterClientLoginHandler, dict(test=self)), - ('/twitter/client/login_gen_engine', TwitterClientLoginGenEngineHandler, dict(test=self)), - ('/twitter/client/login_gen_coroutine', TwitterClientLoginGenCoroutineHandler, dict(test=self)), - ('/twitter/client/show_user', TwitterClientShowUserHandler, dict(test=self)), - ('/twitter/client/show_user_future', TwitterClientShowUserFutureHandler, dict(test=self)), + ('/twitter/client/login_gen_engine', + TwitterClientLoginGenEngineHandler, dict(test=self)), + ('/twitter/client/login_gen_coroutine', + TwitterClientLoginGenCoroutineHandler, dict(test=self)), + ('/twitter/client/show_user', + TwitterClientShowUserHandler, dict(test=self)), + ('/twitter/client/show_user_future', + TwitterClientShowUserFutureHandler, dict(test=self)), # simulated servers ('/openid/server/authenticate', OpenIdServerAuthenticateHandler), @@ -308,7 +316,8 @@ class AuthTest(AsyncHTTPTestCase): ('/facebook/server/me', FacebookServerMeHandler), ('/twitter/server/access_token', TwitterServerAccessTokenHandler), (r'/twitter/api/users/show/(.*)\.json', TwitterServerShowUserHandler), - (r'/twitter/api/account/verify_credentials\.json', TwitterServerVerifyCredentialsHandler), + (r'/twitter/api/account/verify_credentials\.json', + TwitterServerVerifyCredentialsHandler), ], http_client=self.http_client, twitter_consumer_key='test_twitter_consumer_key', @@ -323,7 +332,10 @@ class AuthTest(AsyncHTTPTestCase): '/openid/server/authenticate?' in response.headers['Location']) def test_openid_get_user(self): - response = self.fetch('/openid/client/login?openid.mode=blah&openid.ns.ax=http://openid.net/srv/ax/1.0&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.value.email=foo@example.com') + response = self.fetch('/openid/client/login?openid.mode=blah' + '&openid.ns.ax=http://openid.net/srv/ax/1.0' + '&openid.ax.type.email=http://axschema.org/contact/email' + '&openid.ax.value.email=foo@example.com') response.rethrow() parsed = json_decode(response.body) self.assertEqual(parsed["email"], "foo@example.com") diff --git a/tornado/test/escape_test.py b/tornado/test/escape_test.py index 5ae75d002..70aa4bdd6 100644 --- a/tornado/test/escape_test.py +++ b/tornado/test/escape_test.py @@ -4,7 +4,10 @@ from __future__ import absolute_import, division, print_function import tornado.escape -from tornado.escape import utf8, xhtml_escape, xhtml_unescape, url_escape, url_unescape, to_unicode, json_decode, json_encode, squeeze, recursive_unicode +from tornado.escape import ( + utf8, xhtml_escape, xhtml_unescape, url_escape, url_unescape, + to_unicode, json_decode, json_encode, squeeze, recursive_unicode, +) from tornado.util import unicode_type from tornado.test.util import unittest @@ -15,18 +18,18 @@ linkify_tests = [ u'hello http://world.com/!'), ("hello http://world.com/with?param=true&stuff=yes", {}, - u'hello http://world.com/with?param=true&stuff=yes'), + u'hello http://world.com/with?param=true&stuff=yes'), # noqa: E501 # an opened paren followed by many chars killed Gruber's regex ("http://url.com/w(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", {}, - u'http://url.com/w(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), + u'http://url.com/w(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), # noqa: E501 # as did too many dots at the end ("http://url.com/withmany.......................................", {}, - u'http://url.com/withmany.......................................'), + u'http://url.com/withmany.......................................'), # noqa: E501 ("http://url.com/withmany((((((((((((((((((((((((((((((((((a)", {}, - u'http://url.com/withmany((((((((((((((((((((((((((((((((((a)'), + u'http://url.com/withmany((((((((((((((((((((((((((((((((((a)'), # noqa: E501 # some examples from http://daringfireball.net/2009/11/liberal_regex_for_matching_urls # plus a fex extras (such as multiple parentheses). @@ -43,10 +46,10 @@ linkify_tests = [ u'http://foo.com/blah_blah_(wikipedia)'), ("http://foo.com/blah_(blah)_(wikipedia)_blah", {}, - u'http://foo.com/blah_(blah)_(wikipedia)_blah'), + u'http://foo.com/blah_(blah)_(wikipedia)_blah'), # noqa: E501 ("(Something like http://foo.com/blah_blah_(wikipedia))", {}, - u'(Something like http://foo.com/blah_blah_(wikipedia))'), + u'(Something like http://foo.com/blah_blah_(wikipedia))'), # noqa: E501 ("http://foo.com/blah_blah.", {}, u'http://foo.com/blah_blah.'), @@ -75,7 +78,7 @@ linkify_tests = [ u'rdar:/1234'), ("http://userid:password@example.com:8080", {}, - u'http://userid:password@example.com:8080'), + u'http://userid:password@example.com:8080'), # noqa: E501 ("http://userid@example.com", {}, u'http://userid@example.com'), @@ -88,7 +91,8 @@ linkify_tests = [ ("message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e", {"permitted_protocols": ["http", "message"]}, - u'message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e'), + u'' + u'message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e'), (u"http://\u27a1.ws/\u4a39", {}, u'http://\u27a1.ws/\u4a39'), @@ -105,11 +109,13 @@ linkify_tests = [ ("A http://reallylong.com/link/that/exceedsthelenglimit.html", {"require_protocol": True, "shorten": True}, - u'A http://reallylong.com/link...'), + u'A http://reallylong.com/link...'), # noqa: E501 ("A http://reallylongdomainnamethatwillbetoolong.com/hi!", {"shorten": True}, - u'A http://reallylongdomainnametha...!'), + u'A http://reallylongdomainnametha...!'), # noqa: E501 ("A file:///passwords.txt and http://web.com link", {}, u'A file:///passwords.txt and http://web.com link'), @@ -120,15 +126,16 @@ linkify_tests = [ ("www.external-link.com", {"extra_params": 'rel="nofollow" class="external"'}, - u'www.external-link.com'), + u'www.external-link.com'), # noqa: E501 ("www.external-link.com and www.internal-link.com/blogs extra", - {"extra_params": lambda href: 'class="internal"' if href.startswith("http://www.internal-link.com") else 'rel="nofollow" class="external"'}, - u'www.external-link.com and www.internal-link.com/blogs extra'), + {"extra_params": lambda href: 'class="internal"' if href.startswith("http://www.internal-link.com") else 'rel="nofollow" class="external"'}, # noqa: E501 + u'www.external-link.com' # noqa: E501 + u' and www.internal-link.com/blogs extra'), # noqa: E501 ("www.external-link.com", {"extra_params": lambda href: ' rel="nofollow" class="external" '}, - u'www.external-link.com'), + u'www.external-link.com'), # noqa: E501 ] @@ -230,7 +237,8 @@ class EscapeTestCase(unittest.TestCase): self.assertRaises(UnicodeDecodeError, json_encode, b"\xe9") def test_squeeze(self): - self.assertEqual(squeeze(u'sequences of whitespace chars'), u'sequences of whitespace chars') + self.assertEqual(squeeze(u'sequences of whitespace chars'), + u'sequences of whitespace chars') def test_recursive_unicode(self): tests = { diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index 476035d0b..d19d9930b 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -16,7 +16,7 @@ from tornado.ioloop import IOLoop from tornado.log import app_log from tornado import stack_context from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, ExpectLog, gen_test -from tornado.test.util import unittest, skipOnTravis, skipBefore33, skipBefore35, skipNotCPython, exec_test +from tornado.test.util import unittest, skipOnTravis, skipBefore33, skipBefore35, skipNotCPython, exec_test # noqa: E501 from tornado.web import Application, RequestHandler, asynchronous, HTTPError from tornado import gen diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index 3b0524940..aa9d831d7 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -2,19 +2,21 @@ from __future__ import absolute_import, division, print_function + from tornado import netutil from tornado.escape import json_decode, json_encode, utf8, _unicode, recursive_unicode, native_str from tornado import gen from tornado.http1connection import HTTP1Connection from tornado.httpserver import HTTPServer -from tornado.httputil import HTTPHeaders, HTTPMessageDelegate, HTTPServerConnectionDelegate, ResponseStartLine +from tornado.httputil import HTTPHeaders, HTTPMessageDelegate, HTTPServerConnectionDelegate, ResponseStartLine # noqa: E501 from tornado.iostream import IOStream from tornado.log import gen_log from tornado.netutil import ssl_options_to_context from tornado.simple_httpclient import SimpleAsyncHTTPClient -from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, ExpectLog, gen_test +from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, ExpectLog, gen_test # noqa: E501 from tornado.test.util import unittest, skipOnTravis from tornado.web import Application, RequestHandler, asynchronous, stream_request_body + from contextlib import closing import datetime import gzip diff --git a/tornado/test/httputil_test.py b/tornado/test/httputil_test.py index 1521ca03e..8abb07a93 100644 --- a/tornado/test/httputil_test.py +++ b/tornado/test/httputil_test.py @@ -3,8 +3,13 @@ from __future__ import absolute_import, division, print_function -from tornado.httputil import url_concat, parse_multipart_form_data, HTTPHeaders, format_timestamp, HTTPServerRequest, parse_request_start_line, parse_cookie, qs_to_qsl, PY3 + +from tornado.httputil import ( + url_concat, parse_multipart_form_data, HTTPHeaders, format_timestamp, + HTTPServerRequest, parse_request_start_line, parse_cookie, qs_to_qsl, +) from tornado.escape import utf8, native_str +from tornado.util import PY3 from tornado.log import gen_log from tornado.testing import ExpectLog from tornado.test.util import unittest @@ -443,7 +448,8 @@ class ParseCookieTest(unittest.TestCase): """ Test cases copied from Python's Lib/test/test_http_cookies.py """ - self.assertEqual(parse_cookie('chips=ahoy; vienna=finger'), {'chips': 'ahoy', 'vienna': 'finger'}) + self.assertEqual(parse_cookie('chips=ahoy; vienna=finger'), + {'chips': 'ahoy', 'vienna': 'finger'}) # Here parse_cookie() differs from Python's cookie parsing in that it # treats all semicolons as delimiters, even within quotes. self.assertEqual( @@ -455,11 +461,13 @@ class ParseCookieTest(unittest.TestCase): # Cookies with ':' character in their name. self.assertEqual(parse_cookie('key:term=value:term'), {'key:term': 'value:term'}) # Cookies with '[' and ']'. - self.assertEqual(parse_cookie('a=b; c=[; d=r; f=h'), {'a': 'b', 'c': '[', 'd': 'r', 'f': 'h'}) + self.assertEqual(parse_cookie('a=b; c=[; d=r; f=h'), + {'a': 'b', 'c': '[', 'd': 'r', 'f': 'h'}) def test_cookie_edgecases(self): # Cookies that RFC6265 allows. - self.assertEqual(parse_cookie('a=b; Domain=example.com'), {'a': 'b', 'Domain': 'example.com'}) + self.assertEqual(parse_cookie('a=b; Domain=example.com'), + {'a': 'b', 'Domain': 'example.com'}) # parse_cookie() has historically kept only the last cookie with the # same name. self.assertEqual(parse_cookie('a=b; h=i; a=c'), {'a': 'c', 'h': 'i'}) @@ -471,15 +479,18 @@ class ParseCookieTest(unittest.TestCase): """ # Chunks without an equals sign appear as unnamed values per # https://bugzilla.mozilla.org/show_bug.cgi?id=169091 - self.assertIn('django_language', parse_cookie('abc=def; unnamed; django_language=en').keys()) + self.assertIn('django_language', + parse_cookie('abc=def; unnamed; django_language=en').keys()) # Even a double quote may be an unamed value. self.assertEqual(parse_cookie('a=b; "; c=d'), {'a': 'b', '': '"', 'c': 'd'}) # Spaces in names and values, and an equals sign in values. self.assertEqual(parse_cookie('a b c=d e = f; gh=i'), {'a b c': 'd e = f', 'gh': 'i'}) # More characters the spec forbids. - self.assertEqual(parse_cookie('a b,c<>@:/[]?{}=d " =e,f g'), {'a b,c<>@:/[]?{}': 'd " =e,f g'}) + self.assertEqual(parse_cookie('a b,c<>@:/[]?{}=d " =e,f g'), + {'a b,c<>@:/[]?{}': 'd " =e,f g'}) # Unicode characters. The spec only allows ASCII. - self.assertEqual(parse_cookie('saint=André Bessette'), {'saint': native_str('André Bessette')}) + self.assertEqual(parse_cookie('saint=André Bessette'), + {'saint': native_str('André Bessette')}) # Browsers don't send extra whitespace or semicolons in Cookie headers, # but parse_cookie() should parse whitespace the same way # document.cookie parses whitespace. diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index 8aef35208..bdc5ee14f 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -8,7 +8,7 @@ from tornado.log import gen_log, app_log from tornado.netutil import ssl_wrap_socket from tornado.stack_context import NullContext from tornado.tcpserver import TCPServer -from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, bind_unused_port, ExpectLog, gen_test +from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, bind_unused_port, ExpectLog, gen_test # noqa: E501 from tornado.test.util import unittest, skipIfNonUnix, refusing_port, skipPypy3V58 from tornado.web import RequestHandler, Application import errno diff --git a/tornado/test/locale_test.py b/tornado/test/locale_test.py index d548ffb86..7f8d94626 100644 --- a/tornado/test/locale_test.py +++ b/tornado/test/locale_test.py @@ -89,16 +89,17 @@ class EnglishTest(unittest.TestCase): self.assertEqual(locale.format_date(date, full_format=True), 'April 28, 2013 at 6:35 pm') - self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(seconds=2), full_format=False), + now = datetime.datetime.utcnow() + + self.assertEqual(locale.format_date(now - datetime.timedelta(seconds=2), full_format=False), '2 seconds ago') - self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(minutes=2), full_format=False), + self.assertEqual(locale.format_date(now - datetime.timedelta(minutes=2), full_format=False), '2 minutes ago') - self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(hours=2), full_format=False), + self.assertEqual(locale.format_date(now - datetime.timedelta(hours=2), full_format=False), '2 hours ago') - now = datetime.datetime.utcnow() - self.assertEqual(locale.format_date(now - datetime.timedelta(days=1), full_format=False, shorter=True), - 'yesterday') + self.assertEqual(locale.format_date(now - datetime.timedelta(days=1), + full_format=False, shorter=True), 'yesterday') date = now - datetime.timedelta(days=2) self.assertEqual(locale.format_date(date, full_format=False, shorter=True), diff --git a/tornado/test/log_test.py b/tornado/test/log_test.py index 888964e7b..0565d5668 100644 --- a/tornado/test/log_test.py +++ b/tornado/test/log_test.py @@ -42,7 +42,8 @@ def ignore_bytes_warning(): class LogFormatterTest(unittest.TestCase): # Matches the output of a single logging call (which may be multiple lines # if a traceback was included, so we use the DOTALL option) - LINE_RE = re.compile(b"(?s)\x01\\[E [0-9]{6} [0-9]{2}:[0-9]{2}:[0-9]{2} log_test:[0-9]+\\]\x02 (.*)") + LINE_RE = re.compile( + b"(?s)\x01\\[E [0-9]{6} [0-9]{2}:[0-9]{2}:[0-9]{2} log_test:[0-9]+\\]\x02 (.*)") def setUp(self): self.formatter = LogFormatter(color=False) diff --git a/tornado/test/netutil_test.py b/tornado/test/netutil_test.py index fd284dad6..00fc6eaf4 100644 --- a/tornado/test/netutil_test.py +++ b/tornado/test/netutil_test.py @@ -8,7 +8,9 @@ from subprocess import Popen import sys import time -from tornado.netutil import BlockingResolver, OverrideResolver, ThreadedResolver, is_valid_ip, bind_sockets +from tornado.netutil import ( + BlockingResolver, OverrideResolver, ThreadedResolver, is_valid_ip, bind_sockets +) from tornado.stack_context import ExceptionStackContext from tornado.testing import AsyncTestCase, gen_test, bind_unused_port from tornado.test.util import unittest, skipIfNoNetwork diff --git a/tornado/test/routing_test.py b/tornado/test/routing_test.py index 846f348de..ca097eb8e 100644 --- a/tornado/test/routing_test.py +++ b/tornado/test/routing_test.py @@ -13,7 +13,7 @@ from __future__ import absolute_import, division, print_function -from tornado.httputil import HTTPHeaders, HTTPMessageDelegate, HTTPServerConnectionDelegate, ResponseStartLine +from tornado.httputil import HTTPHeaders, HTTPMessageDelegate, HTTPServerConnectionDelegate, ResponseStartLine # noqa: E501 from tornado.routing import HostMatches, PathMatches, ReversibleRouter, Router, Rule, RuleRouter from tornado.testing import AsyncHTTPTestCase from tornado.web import Application, HTTPError, RequestHandler @@ -29,7 +29,9 @@ class BasicRouter(Router): def finish(self): self.connection.write_headers( - ResponseStartLine("HTTP/1.1", 200, "OK"), HTTPHeaders({"Content-Length": "2"}), b"OK" + ResponseStartLine("HTTP/1.1", 200, "OK"), + HTTPHeaders({"Content-Length": "2"}), + b"OK" ) self.connection.finish() @@ -179,7 +181,8 @@ class RuleRouterTest(AsyncHTTPTestCase): app.add_handlers(".*", [ (HostMatches("www.example.com"), [ - (PathMatches("/first_handler"), "tornado.test.routing_test.SecondHandler", {}, "second_handler") + (PathMatches("/first_handler"), + "tornado.test.routing_test.SecondHandler", {}, "second_handler") ]), Rule(PathMatches("/.*handler"), router), Rule(PathMatches("/first_handler"), FirstHandler, name="first_handler"),