forked from orbit-oss/flask
use ruff linter and formatter
This commit is contained in:
parent
14232513fd
commit
54e05a2824
26 changed files with 99 additions and 132 deletions
|
|
@ -196,17 +196,14 @@ def test_clean_pop(app):
|
|||
|
||||
@app.teardown_request
|
||||
def teardown_req(error=None):
|
||||
1 / 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
@app.teardown_appcontext
|
||||
def teardown_app(error=None):
|
||||
called.append("TEARDOWN")
|
||||
|
||||
try:
|
||||
with app.test_request_context():
|
||||
called.append(flask.current_app.name)
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
with app.app_context():
|
||||
called.append(flask.current_app.name)
|
||||
|
||||
assert called == ["flask_test", "TEARDOWN"]
|
||||
assert not flask.current_app
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
from flask import Module
|
||||
|
||||
|
||||
mod = Module(__name__, "foo", subdomain="foo")
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ from werkzeug.routing import RequestRedirect
|
|||
|
||||
import flask
|
||||
|
||||
|
||||
require_cpython_gc = pytest.mark.skipif(
|
||||
python_implementation() != "CPython",
|
||||
reason="Requires CPython GC behavior",
|
||||
|
|
@ -190,7 +189,8 @@ def test_url_mapping(app, client):
|
|||
|
||||
|
||||
def test_werkzeug_routing(app, client):
|
||||
from werkzeug.routing import Submount, Rule
|
||||
from werkzeug.routing import Rule
|
||||
from werkzeug.routing import Submount
|
||||
|
||||
app.url_map.add(
|
||||
Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])
|
||||
|
|
@ -210,7 +210,8 @@ def test_werkzeug_routing(app, client):
|
|||
|
||||
|
||||
def test_endpoint_decorator(app, client):
|
||||
from werkzeug.routing import Submount, Rule
|
||||
from werkzeug.routing import Rule
|
||||
from werkzeug.routing import Submount
|
||||
|
||||
app.url_map.add(
|
||||
Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])
|
||||
|
|
@ -431,9 +432,9 @@ def test_session_special_types(app, client):
|
|||
client.get("/")
|
||||
s = flask.session
|
||||
assert s["t"] == (1, 2, 3)
|
||||
assert type(s["b"]) is bytes
|
||||
assert type(s["b"]) is bytes # noqa: E721
|
||||
assert s["b"] == b"\xff"
|
||||
assert type(s["m"]) is Markup
|
||||
assert type(s["m"]) is Markup # noqa: E721
|
||||
assert s["m"] == Markup("<html>")
|
||||
assert s["u"] == the_uuid
|
||||
assert s["d"] == now
|
||||
|
|
@ -784,7 +785,7 @@ def test_teardown_request_handler_error(app, client):
|
|||
|
||||
@app.route("/")
|
||||
def fails():
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
rv = client.get("/")
|
||||
assert rv.status_code == 500
|
||||
|
|
@ -851,7 +852,7 @@ def test_error_handling(app, client):
|
|||
|
||||
@app.route("/error")
|
||||
def error():
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
@app.route("/forbidden")
|
||||
def error2():
|
||||
|
|
@ -877,7 +878,7 @@ def test_error_handling_processing(app, client):
|
|||
|
||||
@app.route("/")
|
||||
def broken_func():
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
@app.after_request
|
||||
def after_request(resp):
|
||||
|
|
@ -1047,12 +1048,13 @@ def test_error_handler_after_processor_error(app, client):
|
|||
@app.before_request
|
||||
def before_request():
|
||||
if _trigger == "before":
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
@app.after_request
|
||||
def after_request(response):
|
||||
if _trigger == "after":
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
return response
|
||||
|
||||
@app.route("/")
|
||||
|
|
@ -1507,7 +1509,7 @@ def test_exception_propagation(app, client, key):
|
|||
|
||||
@app.route("/")
|
||||
def index():
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
if key is not None:
|
||||
app.config[key] = True
|
||||
|
|
|
|||
|
|
@ -634,10 +634,11 @@ 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( # noqa: E731
|
||||
"{% if notanswer %}{{ notanswer }} is not the answer. {% endif %}"
|
||||
"{% if answer %}{{ answer }} is the answer.{% endif %}"
|
||||
)
|
||||
def template_string():
|
||||
return flask.render_template_string(
|
||||
"{% if notanswer %}{{ notanswer }} is not the answer. {% endif %}"
|
||||
"{% if answer %}{{ answer }} is the answer.{% endif %}"
|
||||
)
|
||||
|
||||
# App global context processor
|
||||
@answer_bp.app_context_processor
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ def test_request_exception_signal():
|
|||
|
||||
@app.route("/")
|
||||
def index():
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
def record(sender, exception):
|
||||
recorded.append(exception)
|
||||
|
|
@ -169,7 +169,7 @@ def test_appcontext_tearing_down_signal(app, client):
|
|||
|
||||
@app.route("/")
|
||||
def index():
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
flask.appcontext_tearing_down.connect(record_teardown, app)
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ def test_test_client_context_binding(app, client):
|
|||
|
||||
@app.route("/other")
|
||||
def other():
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
with client:
|
||||
resp = client.get("/")
|
||||
|
|
@ -227,18 +227,15 @@ def test_test_client_context_binding(app, client):
|
|||
assert resp.data == b"Hello World!"
|
||||
assert resp.status_code == 200
|
||||
|
||||
with client:
|
||||
resp = client.get("/other")
|
||||
assert not hasattr(flask.g, "value")
|
||||
assert b"Internal Server Error" in resp.data
|
||||
assert resp.status_code == 500
|
||||
flask.g.value = 23
|
||||
|
||||
try:
|
||||
flask.g.value
|
||||
except (AttributeError, RuntimeError):
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("some kind of exception expected")
|
||||
with pytest.raises(RuntimeError):
|
||||
flask.g.value # noqa: B018
|
||||
|
||||
|
||||
def test_reuse_client(client):
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@ def test_method_based_view(app):
|
|||
def test_view_patching(app):
|
||||
class Index(flask.views.MethodView):
|
||||
def get(self):
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
def post(self):
|
||||
1 // 0
|
||||
raise ZeroDivisionError
|
||||
|
||||
class Other(Index):
|
||||
def get(self):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import typing as t
|
||||
|
||||
from flask import Flask
|
||||
from flask import Response
|
||||
|
||||
|
|
@ -29,10 +27,10 @@ async def before_async() -> None:
|
|||
|
||||
|
||||
@app.teardown_appcontext
|
||||
def teardown_sync(exc: t.Optional[BaseException]) -> None:
|
||||
def teardown_sync(exc: BaseException | None) -> None:
|
||||
...
|
||||
|
||||
|
||||
@app.teardown_appcontext
|
||||
async def teardown_async(exc: t.Optional[BaseException]) -> None:
|
||||
async def teardown_async(exc: BaseException | None) -> None:
|
||||
...
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@ def hello_json() -> Response:
|
|||
|
||||
|
||||
@app.route("/json/dict")
|
||||
def hello_json_dict() -> t.Dict[str, t.Any]:
|
||||
def hello_json_dict() -> dict[str, t.Any]:
|
||||
return {"response": "Hello, World!"}
|
||||
|
||||
|
||||
@app.route("/json/dict")
|
||||
def hello_json_list() -> t.List[t.Any]:
|
||||
def hello_json_list() -> list[t.Any]:
|
||||
return [{"message": "Hello"}, {"message": "World"}]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue