apply pyupgrade

This commit is contained in:
David Lord 2020-04-04 09:43:06 -07:00
parent 57d628ca74
commit 524fd0bc8c
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
54 changed files with 169 additions and 230 deletions

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
tests.helpers
~~~~~~~~~~~~~~~~~~~~~~~
@ -38,7 +37,7 @@ def has_encoding(name):
return False
class FakePath(object):
class FakePath:
"""Fake object to represent a ``PathLike object``.
This represents a ``pathlib.Path`` object in python 3.
@ -73,9 +72,9 @@ class FixedOffset(datetime.tzinfo):
return datetime.timedelta()
class TestJSON(object):
class TestJSON:
@pytest.mark.parametrize(
"value", (1, "t", True, False, None, [], [1, 2, 3], {}, {"foo": u"🐍"})
"value", (1, "t", True, False, None, [], [1, 2, 3], {}, {"foo": "🐍"})
)
@pytest.mark.parametrize(
"encoding",
@ -126,12 +125,12 @@ class TestJSON(object):
assert rv.data == b"foo"
@pytest.mark.parametrize(
"test_value,expected", [(True, '"\\u2603"'), (False, u'"\u2603"')]
"test_value,expected", [(True, '"\\u2603"'), (False, '"\u2603"')]
)
def test_json_as_unicode(self, test_value, expected, app, app_ctx):
app.config["JSON_AS_ASCII"] = test_value
rv = flask.json.dumps(u"\N{SNOWMAN}")
rv = flask.json.dumps("\N{SNOWMAN}")
assert rv == expected
def test_json_dump_to_file(self, app, app_ctx):
@ -217,7 +216,7 @@ class TestJSON(object):
)
for i, d in enumerate(test_dates):
url = "/datetest{0}".format(i)
url = f"/datetest{i}"
app.add_url_rule(url, str(i), lambda val=d: flask.jsonify(x=val))
rv = client.get(url)
assert rv.mimetype == "application/json"
@ -262,7 +261,7 @@ class TestJSON(object):
def test_template_escaping(self, app, req_ctx):
render = flask.render_template_string
rv = flask.json.htmlsafe_dumps("</script>")
assert rv == u'"\\u003c/script\\u003e"'
assert rv == '"\\u003c/script\\u003e"'
assert type(rv) is str
rv = render('{{ "</script>"|tojson }}')
assert rv == '"\\u003c/script\\u003e"'
@ -280,7 +279,7 @@ class TestJSON(object):
assert rv == '<a ng-data=\'{"x": ["foo", "bar", "baz\\u0027"]}\'></a>'
def test_json_customization(self, app, client):
class X(object): # noqa: B903, for Python2 compatibility
class X: # noqa: B903, for Python2 compatibility
def __init__(self, val):
self.val = val
@ -315,7 +314,7 @@ class TestJSON(object):
assert rv.data == b'"<42>"'
def test_blueprint_json_customization(self, app, client):
class X(object): # noqa: B903, for Python2 compatibility
class X: # noqa: B903, for Python2 compatibility
def __init__(self, val):
self.val = val
@ -368,9 +367,9 @@ class TestJSON(object):
def index():
return flask.request.args["foo"]
rv = client.get(u"/?foo=정상처리".encode("euc-kr"))
rv = client.get("/?foo=정상처리".encode("euc-kr"))
assert rv.status_code == 200
assert rv.data == u"정상처리".encode("utf-8")
assert rv.data == "정상처리".encode()
def test_json_key_sorting(self, app, client):
app.debug = True
@ -443,7 +442,7 @@ class TestJSON(object):
assert lines == sorted_by_str
class PyBytesIO(object):
class PyBytesIO:
def __init__(self, *args, **kwargs):
self._io = io.BytesIO(*args, **kwargs)
@ -451,7 +450,7 @@ class PyBytesIO(object):
return getattr(self._io, name)
class TestSendfile(object):
class TestSendfile:
def test_send_file_regular(self, app, req_ctx):
rv = flask.send_file("static/index.html")
assert rv.direct_passthrough
@ -516,7 +515,7 @@ class TestSendfile(object):
@pytest.mark.parametrize(
"opener",
[
lambda app: io.StringIO(u"Test"),
lambda app: io.StringIO("Test"),
lambda app: open(os.path.join(app.static_folder, "index.html")),
],
)
@ -673,13 +672,13 @@ class TestSendfile(object):
(
("index.html", "index.html", False),
(
u"Ñandúpingüino.txt",
"Ñandúpingüino.txt",
'"Nandu/pinguino.txt"',
"%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt",
),
(u"Vögel.txt", "Vogel.txt", "V%C3%B6gel.txt"),
("Vögel.txt", "Vogel.txt", "V%C3%B6gel.txt"),
# ":/" are not safe in filename* value
(u"те:/ст", '":/"', "%D1%82%D0%B5%3A%2F%D1%81%D1%82"),
("те:/ст", '":/"', "%D1%82%D0%B5%3A%2F%D1%81%D1%82"),
),
)
def test_attachment_filename_encoding(self, filename, ascii, utf8):
@ -775,7 +774,7 @@ class TestSendfile(object):
flask.send_from_directory("static", "bad\x00")
class TestUrlFor(object):
class TestUrlFor:
def test_url_for_with_anchor(self, app, req_ctx):
@app.route("/")
def index():
@ -834,7 +833,7 @@ class TestUrlFor(object):
assert flask.url_for("myview", _method="POST") == "/myview/create"
class TestNoImports(object):
class TestNoImports:
"""Test Flasks are created without import.
Avoiding ``__import__`` helps create Flask instances where there are errors
@ -853,7 +852,7 @@ class TestNoImports(object):
AssertionError("Flask(import_name) is importing import_name.")
class TestStreaming(object):
class TestStreaming:
def test_streaming_with_context(self, app, client):
@app.route("/")
def index():
@ -884,7 +883,7 @@ class TestStreaming(object):
def test_streaming_with_context_and_custom_close(self, app, client):
called = []
class Wrapper(object):
class Wrapper:
def __init__(self, gen):
self._gen = gen
@ -927,7 +926,7 @@ class TestStreaming(object):
assert rv.data == b"flask"
class TestSafeJoin(object):
class TestSafeJoin:
def test_safe_join(self):
# Valid combinations of *args and expected joined paths.
passing = (
@ -968,7 +967,7 @@ class TestSafeJoin(object):
print(flask.safe_join(*args))
class TestHelpers(object):
class TestHelpers:
@pytest.mark.parametrize(
"debug, expected_flag, expected_default_flag",
[