remove more compat code

This commit is contained in:
David Lord 2020-04-04 09:25:54 -07:00
parent 662c245795
commit 57d628ca74
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
9 changed files with 37 additions and 89 deletions

View file

@ -91,12 +91,7 @@ def test_provide_automatic_options_kwarg(app, client):
assert rv.status_code == 405
assert sorted(rv.allow) == ["GET", "HEAD"]
# Older versions of Werkzeug.test.Client don't have an options method
if hasattr(client, "options"):
rv = client.options("/")
else:
rv = client.open("/", method="OPTIONS")
rv = client.open("/", method="OPTIONS")
assert rv.status_code == 405
rv = client.head("/")
@ -109,11 +104,7 @@ def test_provide_automatic_options_kwarg(app, client):
assert rv.status_code == 405
assert sorted(rv.allow) == ["GET", "HEAD", "POST"]
if hasattr(client, "options"):
rv = client.options("/more")
else:
rv = client.open("/more", method="OPTIONS")
rv = client.open("/more", method="OPTIONS")
assert rv.status_code == 405

View file

@ -589,16 +589,11 @@ def test_run_cert_import(monkeypatch):
with pytest.raises(click.BadParameter):
run_command.make_context("run", ["--cert", "not_here"])
# not an SSLContext
if sys.version_info >= (2, 7, 9):
with pytest.raises(click.BadParameter):
run_command.make_context("run", ["--cert", "flask"])
with pytest.raises(click.BadParameter):
run_command.make_context("run", ["--cert", "flask"])
# SSLContext
if sys.version_info < (2, 7, 9):
ssl_context = object()
else:
ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
monkeypatch.setitem(sys.modules, "ssl_context", ssl_context)
ctx = run_command.make_context("run", ["--cert", "ssl_context"])

View file

@ -92,7 +92,6 @@ class TestJSON(object):
)
def test_detect_encoding(self, value, encoding):
data = json.dumps(value).encode(encoding)
assert json.detect_encoding(data) == encoding
assert json.loads(data) == value
@pytest.mark.parametrize("debug", (True, False))
@ -679,8 +678,6 @@ class TestSendfile(object):
"%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt",
),
(u"Vögel.txt", "Vogel.txt", "V%C3%B6gel.txt"),
# Native string not marked as Unicode on Python 2
("tést.txt", "test.txt", "t%C3%A9st.txt"),
# ":/" are not safe in filename* value
(u"те:/ст", '":/"', "%D1%82%D0%B5%3A%2F%D1%81%D1%82"),
),

View file

@ -9,7 +9,7 @@
:license: BSD-3-Clause
"""
import gc
import sys
import platform
import threading
import pytest
@ -44,6 +44,7 @@ class assert_no_leak(object):
gc.enable()
@pytest.mark.skipif(platform.python_implementation() == "PyPy", reason="CPython only")
def test_memory_consumption():
app = flask.Flask(__name__)
@ -60,11 +61,9 @@ def test_memory_consumption():
# Trigger caches
fire()
# This test only works on CPython 2.7.
if sys.version_info >= (2, 7) and not hasattr(sys, "pypy_translation_info"):
with assert_no_leak():
for _x in range(10):
fire()
with assert_no_leak():
for _x in range(10):
fire()
def test_safe_join_toplevel_pardir():

View file

@ -285,10 +285,6 @@ def test_session_dynamic_cookie_name():
def test_bad_environ_raises_bad_request():
app = flask.Flask(__name__)
# We cannot use app.test_client() for the Unicode-rich Host header,
# because werkzeug enforces latin1 on Python 2.
# However it works when actually passed to the server.
from flask.testing import EnvironBuilder
builder = EnvironBuilder(app)
@ -309,10 +305,6 @@ def test_environ_for_valid_idna_completes():
def index():
return "Hello World!"
# We cannot use app.test_client() for the Unicode-rich Host header,
# because werkzeug enforces latin1 on Python 2.
# However it works when actually passed to the server.
from flask.testing import EnvironBuilder
builder = EnvironBuilder(app)

View file

@ -169,12 +169,10 @@ def test_redirect_keep_session(app, client, app_ctx):
rv = client.get("/")
assert rv.data == b"index"
assert flask.session.get("data") == "foo"
rv = client.post("/", data={}, follow_redirects=True)
assert rv.data == b"foo"
# This support requires a new Werkzeug version
if not hasattr(client, "redirect_client"):
assert flask.session.get("data") == "foo"
assert flask.session.get("data") == "foo"
rv = client.get("/getsession")
assert rv.data == b"foo"