forked from orbit-oss/flask
address flake8 issues
This commit is contained in:
parent
549fed29ea
commit
b46f5942a5
23 changed files with 86 additions and 89 deletions
|
|
@ -1 +1 @@
|
|||
from hello import app
|
||||
from hello import app # noqa: F401
|
||||
|
|
|
|||
|
|
@ -163,7 +163,8 @@ def test_url_mapping(app, client):
|
|||
app.add_url_rule("/", "index", index)
|
||||
app.add_url_rule("/more", "more", more, methods=["GET", "POST"])
|
||||
|
||||
# Issue 1288: Test that automatic options are not added when non-uppercase 'options' in methods
|
||||
# Issue 1288: Test that automatic options are not added
|
||||
# when non-uppercase 'options' in methods
|
||||
app.add_url_rule("/options", "options", options, methods=["options"])
|
||||
|
||||
assert client.get("/").data == b"GET"
|
||||
|
|
@ -779,7 +780,7 @@ def test_teardown_request_handler_error(app, client):
|
|||
# exception.
|
||||
try:
|
||||
raise TypeError()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@app.teardown_request
|
||||
|
|
@ -791,7 +792,7 @@ def test_teardown_request_handler_error(app, client):
|
|||
# exception.
|
||||
try:
|
||||
raise TypeError()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@app.route("/")
|
||||
|
|
@ -963,7 +964,7 @@ def test_http_error_subclass_handling(app, client):
|
|||
return "banana"
|
||||
|
||||
@app.errorhandler(403)
|
||||
def handle_forbidden_subclass(e):
|
||||
def handle_403(e):
|
||||
assert not isinstance(e, ForbiddenSubclass)
|
||||
assert isinstance(e, Forbidden)
|
||||
return "apple"
|
||||
|
|
@ -1065,12 +1066,12 @@ def test_error_handler_after_processor_error(app, client):
|
|||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
if trigger == "before":
|
||||
if _trigger == "before":
|
||||
1 // 0
|
||||
|
||||
@app.after_request
|
||||
def after_request(response):
|
||||
if trigger == "after":
|
||||
if _trigger == "after":
|
||||
1 // 0
|
||||
return response
|
||||
|
||||
|
|
@ -1082,7 +1083,7 @@ def test_error_handler_after_processor_error(app, client):
|
|||
def internal_server_error(e):
|
||||
return "Hello Server Error", 500
|
||||
|
||||
for trigger in "before", "after":
|
||||
for _trigger in "before", "after":
|
||||
rv = client.get("/")
|
||||
assert rv.status_code == 500
|
||||
assert rv.data == b"Hello Server Error"
|
||||
|
|
@ -1459,10 +1460,12 @@ def test_static_route_with_host_matching():
|
|||
# Providing static_host without host_matching=True should error.
|
||||
with pytest.raises(Exception):
|
||||
flask.Flask(__name__, static_host="example.com")
|
||||
# Providing host_matching=True with static_folder but without static_host should error.
|
||||
# Providing host_matching=True with static_folder
|
||||
# but without static_host should error.
|
||||
with pytest.raises(Exception):
|
||||
flask.Flask(__name__, host_matching=True)
|
||||
# Providing host_matching=True without static_host but with static_folder=None should not error.
|
||||
# Providing host_matching=True without static_host
|
||||
# but with static_folder=None should not error.
|
||||
flask.Flask(__name__, host_matching=True, static_folder=None)
|
||||
|
||||
|
||||
|
|
@ -1574,12 +1577,12 @@ def test_max_content_length(app, client):
|
|||
@app.before_request
|
||||
def always_first():
|
||||
flask.request.form["myfile"]
|
||||
assert False
|
||||
AssertionError()
|
||||
|
||||
@app.route("/accept", methods=["POST"])
|
||||
def accept_file():
|
||||
flask.request.form["myfile"]
|
||||
assert False
|
||||
AssertionError()
|
||||
|
||||
@app.errorhandler(413)
|
||||
def catcher(error):
|
||||
|
|
@ -1765,7 +1768,7 @@ def test_preserve_only_once(app, client):
|
|||
def fail_func():
|
||||
1 // 0
|
||||
|
||||
for x in range(3):
|
||||
for _x in range(3):
|
||||
with pytest.raises(ZeroDivisionError):
|
||||
client.get("/fail")
|
||||
|
||||
|
|
|
|||
|
|
@ -705,7 +705,7 @@ def test_add_template_test_with_name_and_template(app, client):
|
|||
def test_context_processing(app, client):
|
||||
answer_bp = flask.Blueprint("answer_bp", __name__)
|
||||
|
||||
template_string = lambda: flask.render_template_string(
|
||||
template_string = lambda: flask.render_template_string( # noqa: E731
|
||||
"{% if notanswer %}{{ notanswer }} is not the answer. {% endif %}"
|
||||
"{% if answer %}{{ answer }} is the answer.{% endif %}"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ def test_cli_name(test_apps):
|
|||
|
||||
|
||||
def test_find_best_app(test_apps):
|
||||
"""Test if `find_best_app` behaves as expected with different combinations of input."""
|
||||
"""Test if `find_best_app` behaves as expected with different combinations of input.""" # noqa: B950
|
||||
script_info = ScriptInfo()
|
||||
|
||||
class Module:
|
||||
|
|
|
|||
|
|
@ -76,39 +76,32 @@ def test_config_from_class():
|
|||
common_object_test(app)
|
||||
|
||||
|
||||
def test_config_from_envvar():
|
||||
env = os.environ
|
||||
try:
|
||||
os.environ = {}
|
||||
app = flask.Flask(__name__)
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
app.config.from_envvar("FOO_SETTINGS")
|
||||
def test_config_from_envvar(monkeypatch):
|
||||
monkeypatch.setattr("os.environ", {})
|
||||
app = flask.Flask(__name__)
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
app.config.from_envvar("FOO_SETTINGS")
|
||||
assert "'FOO_SETTINGS' is not set" in str(e.value)
|
||||
assert not app.config.from_envvar("FOO_SETTINGS", silent=True)
|
||||
assert not app.config.from_envvar("FOO_SETTINGS", silent=True)
|
||||
|
||||
os.environ = {"FOO_SETTINGS": __file__.rsplit(".", 1)[0] + ".py"}
|
||||
assert app.config.from_envvar("FOO_SETTINGS")
|
||||
common_object_test(app)
|
||||
finally:
|
||||
os.environ = env
|
||||
monkeypatch.setattr(
|
||||
"os.environ", {"FOO_SETTINGS": __file__.rsplit(".", 1)[0] + ".py"}
|
||||
)
|
||||
assert app.config.from_envvar("FOO_SETTINGS")
|
||||
common_object_test(app)
|
||||
|
||||
|
||||
def test_config_from_envvar_missing():
|
||||
env = os.environ
|
||||
try:
|
||||
os.environ = {"FOO_SETTINGS": "missing.cfg"}
|
||||
with pytest.raises(IOError) as e:
|
||||
app = flask.Flask(__name__)
|
||||
app.config.from_envvar("FOO_SETTINGS")
|
||||
msg = str(e.value)
|
||||
assert msg.startswith(
|
||||
"[Errno 2] Unable to load configuration "
|
||||
"file (No such file or directory):"
|
||||
)
|
||||
assert msg.endswith("missing.cfg'")
|
||||
assert not app.config.from_envvar("FOO_SETTINGS", silent=True)
|
||||
finally:
|
||||
os.environ = env
|
||||
def test_config_from_envvar_missing(monkeypatch):
|
||||
monkeypatch.setattr("os.environ", {"FOO_SETTINGS": "missing.cfg"})
|
||||
with pytest.raises(IOError) as e:
|
||||
app = flask.Flask(__name__)
|
||||
app.config.from_envvar("FOO_SETTINGS")
|
||||
msg = str(e.value)
|
||||
assert msg.startswith(
|
||||
"[Errno 2] Unable to load configuration " "file (No such file or directory):"
|
||||
)
|
||||
assert msg.endswith("missing.cfg'")
|
||||
assert not app.config.from_envvar("FOO_SETTINGS", silent=True)
|
||||
|
||||
|
||||
def test_config_missing():
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ class TestJSON(object):
|
|||
|
||||
def test_jsonify_arrays(self, app, client):
|
||||
"""Test jsonify of lists and args unpacking."""
|
||||
l = [
|
||||
a_list = [
|
||||
0,
|
||||
42,
|
||||
3.14,
|
||||
|
|
@ -196,16 +196,16 @@ class TestJSON(object):
|
|||
|
||||
@app.route("/args_unpack")
|
||||
def return_args_unpack():
|
||||
return flask.jsonify(*l)
|
||||
return flask.jsonify(*a_list)
|
||||
|
||||
@app.route("/array")
|
||||
def return_array():
|
||||
return flask.jsonify(l)
|
||||
return flask.jsonify(a_list)
|
||||
|
||||
for url in "/args_unpack", "/array":
|
||||
rv = client.get(url)
|
||||
assert rv.mimetype == "application/json"
|
||||
assert flask.json.loads(rv.data) == l
|
||||
assert flask.json.loads(rv.data) == a_list
|
||||
|
||||
def test_jsonify_date_types(self, app, client):
|
||||
"""Test jsonify with datetime.date and datetime.datetime types."""
|
||||
|
|
@ -278,7 +278,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):
|
||||
class X(object): # noqa: B903, for Python2 compatibility
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
|
|
@ -313,7 +313,7 @@ class TestJSON(object):
|
|||
assert rv.data == b'"<42>"'
|
||||
|
||||
def test_blueprint_json_customization(self, app, client):
|
||||
class X(object):
|
||||
class X(object): # noqa: B903, for Python2 compatibility
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
|
|
@ -352,6 +352,9 @@ class TestJSON(object):
|
|||
)
|
||||
assert rv.data == b'"<42>"'
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not has_encoding("euc-kr"), reason="The euc-kr encoding is required."
|
||||
)
|
||||
def test_modified_url_encoding(self, app, client):
|
||||
class ModifiedRequest(flask.Request):
|
||||
url_charset = "euc-kr"
|
||||
|
|
@ -367,13 +370,10 @@ class TestJSON(object):
|
|||
assert rv.status_code == 200
|
||||
assert rv.data == u"정상처리".encode("utf-8")
|
||||
|
||||
if not has_encoding("euc-kr"):
|
||||
test_modified_url_encoding = None
|
||||
|
||||
def test_json_key_sorting(self, app, client):
|
||||
app.debug = True
|
||||
|
||||
assert app.config["JSON_SORT_KEYS"] == True
|
||||
assert app.config["JSON_SORT_KEYS"]
|
||||
d = dict.fromkeys(range(20), "foo")
|
||||
|
||||
@app.route("/")
|
||||
|
|
@ -858,7 +858,7 @@ class TestNoImports(object):
|
|||
try:
|
||||
flask.Flask("importerror")
|
||||
except NotImplementedError:
|
||||
assert False, "Flask(import_name) is importing import_name."
|
||||
AssertionError("Flask(import_name) is importing import_name.")
|
||||
|
||||
|
||||
class TestStreaming(object):
|
||||
|
|
|
|||
|
|
@ -140,4 +140,4 @@ def test_meta_path_loader_without_is_package(request, modules_tmpdir):
|
|||
request.addfinalizer(sys.meta_path.pop)
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
import unimportable
|
||||
import unimportable # noqa: F401
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ def test_duplicate_tag():
|
|||
|
||||
|
||||
def test_custom_tag():
|
||||
class Foo(object):
|
||||
class Foo(object): # noqa: B903, for Python2 compatibility
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ def test_memory_consumption():
|
|||
# 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):
|
||||
for _x in range(10):
|
||||
fire()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -191,7 +191,6 @@ class TestGreenletContextCopying(object):
|
|||
@app.route("/")
|
||||
def index():
|
||||
flask.session["fizz"] = "buzz"
|
||||
reqctx = flask._request_ctx_stack.top.copy()
|
||||
|
||||
@flask.copy_current_request_context
|
||||
def g():
|
||||
|
|
@ -228,7 +227,7 @@ def test_session_error_pops_context():
|
|||
@app.route("/")
|
||||
def index():
|
||||
# shouldn't get here
|
||||
assert False
|
||||
AssertionError()
|
||||
|
||||
response = app.test_client().get("/")
|
||||
assert response.status_code == 500
|
||||
|
|
|
|||
|
|
@ -398,12 +398,12 @@ def test_templates_auto_reload_debug_run(app, monkeypatch):
|
|||
monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)
|
||||
|
||||
app.run()
|
||||
assert app.templates_auto_reload == False
|
||||
assert app.jinja_env.auto_reload == False
|
||||
assert not app.templates_auto_reload
|
||||
assert not app.jinja_env.auto_reload
|
||||
|
||||
app.run(debug=True)
|
||||
assert app.templates_auto_reload == True
|
||||
assert app.jinja_env.auto_reload == True
|
||||
assert app.templates_auto_reload
|
||||
assert app.jinja_env.auto_reload
|
||||
|
||||
|
||||
def test_template_loader_debugging(test_apps, monkeypatch):
|
||||
|
|
@ -412,7 +412,7 @@ def test_template_loader_debugging(test_apps, monkeypatch):
|
|||
called = []
|
||||
|
||||
class _TestHandler(logging.Handler):
|
||||
def handle(x, record):
|
||||
def handle(self, record):
|
||||
called.append(True)
|
||||
text = str(record.msg)
|
||||
assert '1: trying loader of application "blueprintapp"' in text
|
||||
|
|
|
|||
|
|
@ -211,13 +211,13 @@ def test_session_transactions_no_null_sessions():
|
|||
|
||||
with app.test_client() as c:
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
with c.session_transaction() as sess:
|
||||
with c.session_transaction():
|
||||
pass
|
||||
assert "Session backend did not open a session" in str(e.value)
|
||||
|
||||
|
||||
def test_session_transactions_keep_context(app, client, req_ctx):
|
||||
rv = client.get("/")
|
||||
client.get("/")
|
||||
req = flask.request._get_current_object()
|
||||
assert req is not None
|
||||
with client.session_transaction():
|
||||
|
|
@ -227,7 +227,7 @@ def test_session_transactions_keep_context(app, client, req_ctx):
|
|||
def test_session_transaction_needs_cookies(app):
|
||||
c = app.test_client(use_cookies=False)
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
with c.session_transaction() as s:
|
||||
with c.session_transaction():
|
||||
pass
|
||||
assert "cookies" in str(e.value)
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ def test_default_error_handler():
|
|||
return "bp-default"
|
||||
|
||||
@bp.errorhandler(Forbidden)
|
||||
def bp_exception_handler(e):
|
||||
def bp_forbidden_handler(e):
|
||||
assert isinstance(e, Forbidden)
|
||||
return "bp-forbidden"
|
||||
|
||||
|
|
@ -164,13 +164,13 @@ def test_default_error_handler():
|
|||
app = flask.Flask(__name__)
|
||||
|
||||
@app.errorhandler(HTTPException)
|
||||
def catchall_errorhandler(e):
|
||||
def catchall_exception_handler(e):
|
||||
assert isinstance(e, HTTPException)
|
||||
assert isinstance(e, NotFound)
|
||||
return "default"
|
||||
|
||||
@app.errorhandler(Forbidden)
|
||||
def catchall_errorhandler(e):
|
||||
def catchall_forbidden_handler(e):
|
||||
assert isinstance(e, Forbidden)
|
||||
return "forbidden"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue