Fix redefined-outer-name
This commit is contained in:
parent
d718ecf6d3
commit
a0e30b60b7
10 changed files with 98 additions and 98 deletions
|
|
@ -67,7 +67,7 @@ html_show_sourcelink = False
|
||||||
|
|
||||||
def github_link(name, rawtext, text, lineno, inliner, options=None, content=None):
|
def github_link(name, rawtext, text, lineno, inliner, options=None, content=None):
|
||||||
app = inliner.document.settings.env.app
|
app = inliner.document.settings.env.app
|
||||||
release = app.config.release
|
app_release = app.config.release
|
||||||
base_url = "https://github.com/pallets/flask/tree/"
|
base_url = "https://github.com/pallets/flask/tree/"
|
||||||
|
|
||||||
if text.endswith(">"):
|
if text.endswith(">"):
|
||||||
|
|
@ -76,10 +76,10 @@ def github_link(name, rawtext, text, lineno, inliner, options=None, content=None
|
||||||
else:
|
else:
|
||||||
words = None
|
words = None
|
||||||
|
|
||||||
if packaging.version.parse(release).is_devrelease:
|
if packaging.version.parse(app_release).is_devrelease:
|
||||||
url = f"{base_url}main/{text}"
|
url = f"{base_url}main/{text}"
|
||||||
else:
|
else:
|
||||||
url = f"{base_url}{release}/{text}"
|
url = f"{base_url}{app_release}/{text}"
|
||||||
|
|
||||||
if words is None:
|
if words is None:
|
||||||
words = url
|
words = url
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,13 @@ bp = Blueprint("tasks", __name__, url_prefix="/tasks")
|
||||||
|
|
||||||
|
|
||||||
@bp.get("/result/<id>")
|
@bp.get("/result/<id>")
|
||||||
def result(id: str) -> dict[str, object]:
|
def get_result(id: str) -> dict[str, object]:
|
||||||
result = AsyncResult(id)
|
async_result = AsyncResult(id)
|
||||||
ready = result.ready()
|
ready = async_result.ready()
|
||||||
return {
|
return {
|
||||||
"ready": ready,
|
"ready": ready,
|
||||||
"successful": result.successful() if ready else None,
|
"successful": async_result.successful() if ready else None,
|
||||||
"value": result.get() if ready else result.result,
|
"value": async_result.get() if ready else async_result.result,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,17 +22,17 @@ def result(id: str) -> dict[str, object]:
|
||||||
def add() -> dict[str, object]:
|
def add() -> dict[str, object]:
|
||||||
a = request.form.get("a", type=int)
|
a = request.form.get("a", type=int)
|
||||||
b = request.form.get("b", type=int)
|
b = request.form.get("b", type=int)
|
||||||
result = tasks.add.delay(a, b)
|
task_result = tasks.add.delay(a, b)
|
||||||
return {"result_id": result.id}
|
return {"result_id": task_result.id}
|
||||||
|
|
||||||
|
|
||||||
@bp.post("/block")
|
@bp.post("/block")
|
||||||
def block() -> dict[str, object]:
|
def block() -> dict[str, object]:
|
||||||
result = tasks.block.delay()
|
task_result = tasks.block.delay()
|
||||||
return {"result_id": result.id}
|
return {"result_id": task_result.id}
|
||||||
|
|
||||||
|
|
||||||
@bp.post("/process")
|
@bp.post("/process")
|
||||||
def process() -> dict[str, object]:
|
def process() -> dict[str, object]:
|
||||||
result = tasks.process.delay(total=request.form.get("total", type=int))
|
task_result = tasks.process.delay(total=request.form.get("total", type=int))
|
||||||
return {"result_id": result.id}
|
return {"result_id": task_result.id}
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ def fixture_app():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client(app):
|
def client(app_):
|
||||||
return app.test_client()
|
return app_.test_client()
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,14 @@ def app():
|
||||||
# create a temporary file to isolate the database for each test
|
# create a temporary file to isolate the database for each test
|
||||||
db_fd, db_path = tempfile.mkstemp()
|
db_fd, db_path = tempfile.mkstemp()
|
||||||
# create the app with common test config
|
# create the app with common test config
|
||||||
app = create_app({"TESTING": True, "DATABASE": db_path})
|
test_app = create_app({"TESTING": True, "DATABASE": db_path})
|
||||||
|
|
||||||
# create the database and load test data
|
# create the database and load test data
|
||||||
with app.app_context():
|
with test_app.app_context():
|
||||||
init_db()
|
init_db()
|
||||||
get_db().executescript(_data_sql)
|
get_db().executescript(_data_sql)
|
||||||
|
|
||||||
yield app
|
yield test_app
|
||||||
|
|
||||||
# close and remove the temporary database
|
# close and remove the temporary database
|
||||||
os.close(db_fd)
|
os.close(db_fd)
|
||||||
|
|
@ -33,20 +33,20 @@ def app():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client(app):
|
def client(app_):
|
||||||
"""A test client for the app."""
|
"""A test client for the app."""
|
||||||
return app.test_client()
|
return app_.test_client()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def runner(app):
|
def runner(app_):
|
||||||
"""A test runner for the app's Click commands."""
|
"""A test runner for the app's Click commands."""
|
||||||
return app.test_cli_runner()
|
return app_.test_cli_runner()
|
||||||
|
|
||||||
|
|
||||||
class AuthActions:
|
class AuthActions:
|
||||||
def __init__(self, client):
|
def __init__(self, client_obj):
|
||||||
self._client = client
|
self._client = client_obj
|
||||||
|
|
||||||
def login(self, username="test", password="test"):
|
def login(self, username="test", password="test"):
|
||||||
return self._client.post(
|
return self._client.post(
|
||||||
|
|
|
||||||
|
|
@ -399,7 +399,7 @@ class Flask(App):
|
||||||
rv.policies["json.dumps_function"] = self.json.dumps
|
rv.policies["json.dumps_function"] = self.json.dumps
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
def create_url_adapter(self, request: Request | None) -> MapAdapter | None:
|
def create_url_adapter(self, request_obj: Request | None) -> MapAdapter | None:
|
||||||
"""Creates a URL adapter for the given request. The URL adapter
|
"""Creates a URL adapter for the given request. The URL adapter
|
||||||
is created at a point where the request context is not yet set
|
is created at a point where the request context is not yet set
|
||||||
up so the request is passed explicitly.
|
up so the request is passed explicitly.
|
||||||
|
|
@ -414,7 +414,7 @@ class Flask(App):
|
||||||
:data:`SERVER_NAME` no longer implicitly enables subdomain
|
:data:`SERVER_NAME` no longer implicitly enables subdomain
|
||||||
matching. Use :attr:`subdomain_matching` instead.
|
matching. Use :attr:`subdomain_matching` instead.
|
||||||
"""
|
"""
|
||||||
if request is not None:
|
if request_obj is not None:
|
||||||
# If subdomain matching is disabled (the default), use the
|
# If subdomain matching is disabled (the default), use the
|
||||||
# default subdomain in all cases. This should be the default
|
# default subdomain in all cases. This should be the default
|
||||||
# in Werkzeug but it currently does not have that feature.
|
# in Werkzeug but it currently does not have that feature.
|
||||||
|
|
@ -424,7 +424,7 @@ class Flask(App):
|
||||||
subdomain = None
|
subdomain = None
|
||||||
|
|
||||||
return self.url_map.bind_to_environ(
|
return self.url_map.bind_to_environ(
|
||||||
request.environ,
|
request_obj.environ,
|
||||||
server_name=self.config["SERVER_NAME"],
|
server_name=self.config["SERVER_NAME"],
|
||||||
subdomain=subdomain,
|
subdomain=subdomain,
|
||||||
)
|
)
|
||||||
|
|
@ -439,7 +439,7 @@ class Flask(App):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def raise_routing_exception(self, request: Request) -> t.NoReturn:
|
def raise_routing_exception(self, req: Request) -> t.NoReturn:
|
||||||
"""Intercept routing exceptions and possibly do something else.
|
"""Intercept routing exceptions and possibly do something else.
|
||||||
|
|
||||||
In debug mode, intercept a routing redirect and replace it with
|
In debug mode, intercept a routing redirect and replace it with
|
||||||
|
|
@ -457,15 +457,15 @@ class Flask(App):
|
||||||
"""
|
"""
|
||||||
if (
|
if (
|
||||||
not self.debug
|
not self.debug
|
||||||
or not isinstance(request.routing_exception, RequestRedirect)
|
or not isinstance(req.routing_exception, RequestRedirect)
|
||||||
or request.routing_exception.code in {307, 308}
|
or req.routing_exception.code in {307, 308}
|
||||||
or request.method in {"GET", "HEAD", "OPTIONS"}
|
or req.method in {"GET", "HEAD", "OPTIONS"}
|
||||||
):
|
):
|
||||||
raise request.routing_exception # type: ignore[misc]
|
raise req.routing_exception # type: ignore[misc]
|
||||||
|
|
||||||
from .debughelpers import FormDataRoutingRedirect
|
from .debughelpers import FormDataRoutingRedirect
|
||||||
|
|
||||||
raise FormDataRoutingRedirect(request)
|
raise FormDataRoutingRedirect(req)
|
||||||
|
|
||||||
def update_template_context(self, context: dict[str, t.Any]) -> None:
|
def update_template_context(self, context: dict[str, t.Any]) -> None:
|
||||||
"""Update the template context with some commonly used variables.
|
"""Update the template context with some commonly used variables.
|
||||||
|
|
|
||||||
|
|
@ -545,7 +545,7 @@ class FlaskGroup(AppGroup):
|
||||||
add_default_commands: bool = True,
|
add_default_commands: bool = True,
|
||||||
create_app: t.Callable[..., Flask] | None = None,
|
create_app: t.Callable[..., Flask] | None = None,
|
||||||
add_version_option: bool = True,
|
add_version_option: bool = True,
|
||||||
load_dotenv: bool = True,
|
load_env_vars: bool = True,
|
||||||
set_debug_flag: bool = True,
|
set_debug_flag: bool = True,
|
||||||
**extra: t.Any,
|
**extra: t.Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
@ -567,7 +567,7 @@ class FlaskGroup(AppGroup):
|
||||||
super().__init__(params=params, **extra)
|
super().__init__(params=params, **extra)
|
||||||
|
|
||||||
self.create_app = create_app
|
self.create_app = create_app
|
||||||
self.load_dotenv = load_dotenv
|
self.load_env_vars = load_env_vars
|
||||||
self.set_debug_flag = set_debug_flag
|
self.set_debug_flag = set_debug_flag
|
||||||
|
|
||||||
if add_default_commands:
|
if add_default_commands:
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,15 @@ def _standard_os_environ():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def _reset_os_environ(monkeypatch, _standard_os_environ):
|
def _reset_os_environ(monkeypatch, standard_os_environ):
|
||||||
"""Reset ``os.environ`` to the standard environ after each test,
|
"""Reset ``os.environ`` to the standard environ after each test,
|
||||||
in case a test changed something without cleaning up.
|
in case a test changed something without cleaning up.
|
||||||
"""
|
"""
|
||||||
monkeypatch._setitem.extend(_standard_os_environ)
|
monkeypatch._setitem.extend(standard_os_environ)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def app():
|
def create_app():
|
||||||
app = Flask("flask_test", root_path=os.path.dirname(__file__))
|
app = Flask("flask_test", root_path=os.path.dirname(__file__))
|
||||||
app.config.update(
|
app.config.update(
|
||||||
TESTING=True,
|
TESTING=True,
|
||||||
|
|
@ -53,14 +53,14 @@ def app():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def app_ctx(app):
|
def app_ctx(flask_app):
|
||||||
with app.app_context() as ctx:
|
with flask_app.app_context() as ctx:
|
||||||
yield ctx
|
yield ctx
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def req_ctx(app):
|
def req_ctx(app_):
|
||||||
with app.test_request_context() as ctx:
|
with app_.test_request_context() as ctx:
|
||||||
yield ctx
|
yield ctx
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -70,8 +70,8 @@ def client(app):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def test_apps(monkeypatch):
|
def test_apps(monkeypatch_):
|
||||||
monkeypatch.syspath_prepend(os.path.join(os.path.dirname(__file__), "test_apps"))
|
monkeypatch_.syspath_prepend(os.path.join(os.path.dirname(__file__), "test_apps"))
|
||||||
original_modules = set(sys.modules.keys())
|
original_modules = set(sys.modules.keys())
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
@ -97,7 +97,7 @@ def leak_detector():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=(True, False))
|
@pytest.fixture(params=(True, False))
|
||||||
def limit_loader(request, monkeypatch):
|
def limit_loader(request, monkeypatch_):
|
||||||
"""Patch pkgutil.get_loader to give loader without get_filename or archive.
|
"""Patch pkgutil.get_loader to give loader without get_filename or archive.
|
||||||
|
|
||||||
This provides for tests where a system has custom loaders, e.g. Google App
|
This provides for tests where a system has custom loaders, e.g. Google App
|
||||||
|
|
@ -124,31 +124,31 @@ def limit_loader(request, monkeypatch):
|
||||||
def get_loader(*args, **kwargs):
|
def get_loader(*args, **kwargs):
|
||||||
return LimitedLoader(old_get_loader(*args, **kwargs))
|
return LimitedLoader(old_get_loader(*args, **kwargs))
|
||||||
|
|
||||||
monkeypatch.setattr(pkgutil, "get_loader", get_loader)
|
monkeypatch_.setattr(pkgutil, "get_loader", get_loader)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def modules_tmp_path(tmp_path, monkeypatch):
|
def modules_tmp_path(tmp_path, monkeypatch_):
|
||||||
"""A temporary directory added to sys.path."""
|
"""A temporary directory added to sys.path."""
|
||||||
rv = tmp_path / "modules_tmp"
|
rv = tmp_path / "modules_tmp"
|
||||||
rv.mkdir()
|
rv.mkdir()
|
||||||
monkeypatch.syspath_prepend(os.fspath(rv))
|
monkeypatch_.syspath_prepend(os.fspath(rv))
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def modules_tmp_path_prefix(modules_tmp_path, monkeypatch):
|
def modules_tmp_path_prefix(modules_tmp_path_arg, monkeypatch_):
|
||||||
monkeypatch.setattr(sys, "prefix", os.fspath(modules_tmp_path))
|
monkeypatch_.setattr(sys, "prefix", os.fspath(modules_tmp_path_arg))
|
||||||
return modules_tmp_path
|
return modules_tmp_path_arg
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def site_packages(modules_tmp_path, monkeypatch):
|
def site_packages(modules_tmp_path_local, monkeypatch_arg):
|
||||||
"""Create a fake site-packages."""
|
"""Create a fake site-packages."""
|
||||||
py_dir = f"python{sys.version_info.major}.{sys.version_info.minor}"
|
py_dir = f"python{sys.version_info.major}.{sys.version_info.minor}"
|
||||||
rv = modules_tmp_path / "lib" / py_dir / "site-packages"
|
rv = modules_tmp_path_local / "lib" / py_dir / "site-packages"
|
||||||
rv.mkdir(parents=True)
|
rv.mkdir(parents=True)
|
||||||
monkeypatch.syspath_prepend(os.fspath(rv))
|
monkeypatch_arg.syspath_prepend(os.fspath(rv))
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ def test_app_tearing_down_with_unhandled_exception(app, client):
|
||||||
assert str(cleanup_stuff[0]) == "dummy"
|
assert str(cleanup_stuff[0]) == "dummy"
|
||||||
|
|
||||||
|
|
||||||
def test_app_ctx_globals_methods(app, app_ctx):
|
def test_app_ctx_globals_methods(app, app_ctx_local):
|
||||||
# get
|
# get
|
||||||
assert flask.g.get("foo") is None
|
assert flask.g.get("foo") is None
|
||||||
assert flask.g.get("foo", "bar") == "bar"
|
assert flask.g.get("foo", "bar") == "bar"
|
||||||
|
|
|
||||||
|
|
@ -294,9 +294,9 @@ def test_app_cli_has_app_context(app, runner):
|
||||||
@app.cli.command()
|
@app.cli.command()
|
||||||
@click.argument("value", callback=_param_cb)
|
@click.argument("value", callback=_param_cb)
|
||||||
def check(value):
|
def check(value):
|
||||||
app = click.get_current_context().obj.load_app()
|
app_obj = click.get_current_context().obj.load_app()
|
||||||
# the loaded app should be the same as current_app
|
# the loaded app should be the same as current_app
|
||||||
same_app = current_app._get_current_object() is app
|
same_app = current_app._get_current_object() is app_obj
|
||||||
return same_app, value
|
return same_app, value
|
||||||
|
|
||||||
cli = FlaskGroup(create_app=lambda: app)
|
cli = FlaskGroup(create_app=lambda: app)
|
||||||
|
|
@ -304,7 +304,7 @@ def test_app_cli_has_app_context(app, runner):
|
||||||
assert result.return_value == (True, True)
|
assert result.return_value == (True, True)
|
||||||
|
|
||||||
|
|
||||||
def test_with_appcontext(runner):
|
def test_with_appcontext(runner_):
|
||||||
@click.command()
|
@click.command()
|
||||||
@with_appcontext
|
@with_appcontext
|
||||||
def testcmd():
|
def testcmd():
|
||||||
|
|
@ -312,12 +312,12 @@ def test_with_appcontext(runner):
|
||||||
|
|
||||||
obj = ScriptInfo(create_app=lambda: Flask("testapp"))
|
obj = ScriptInfo(create_app=lambda: Flask("testapp"))
|
||||||
|
|
||||||
result = runner.invoke(testcmd, obj=obj)
|
result = runner_.invoke(testcmd, obj=obj)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert result.output == "testapp\n"
|
assert result.output == "testapp\n"
|
||||||
|
|
||||||
|
|
||||||
def test_appgroup_app_context(runner):
|
def test_appgroup_app_context(cli_runner):
|
||||||
@click.group(cls=AppGroup)
|
@click.group(cls=AppGroup)
|
||||||
def cli():
|
def cli():
|
||||||
pass
|
pass
|
||||||
|
|
@ -336,16 +336,16 @@ def test_appgroup_app_context(runner):
|
||||||
|
|
||||||
obj = ScriptInfo(create_app=lambda: Flask("testappgroup"))
|
obj = ScriptInfo(create_app=lambda: Flask("testappgroup"))
|
||||||
|
|
||||||
result = runner.invoke(cli, ["test"], obj=obj)
|
result = cli_runner.invoke(cli, ["test"], obj=obj)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert result.output == "testappgroup\n"
|
assert result.output == "testappgroup\n"
|
||||||
|
|
||||||
result = runner.invoke(cli, ["subgroup", "test2"], obj=obj)
|
result = cli_runner.invoke(cli, ["subgroup", "test2"], obj=obj)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert result.output == "testappgroup\n"
|
assert result.output == "testappgroup\n"
|
||||||
|
|
||||||
|
|
||||||
def test_flaskgroup_app_context(runner):
|
def test_flaskgroup_app_context(runner_):
|
||||||
def create_app():
|
def create_app():
|
||||||
return Flask("flaskgroup")
|
return Flask("flaskgroup")
|
||||||
|
|
||||||
|
|
@ -357,7 +357,7 @@ def test_flaskgroup_app_context(runner):
|
||||||
def test():
|
def test():
|
||||||
click.echo(current_app.name)
|
click.echo(current_app.name)
|
||||||
|
|
||||||
result = runner.invoke(cli, ["test"])
|
result = runner_.invoke(cli, ["test"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert result.output == "flaskgroup\n"
|
assert result.output == "flaskgroup\n"
|
||||||
|
|
||||||
|
|
@ -370,14 +370,14 @@ def test_flaskgroup_debug(runner, set_debug_flag):
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)
|
@click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)
|
||||||
def cli(**params):
|
def cli_command(**params):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@cli.command()
|
@cli_command.command()
|
||||||
def test():
|
def test():
|
||||||
click.echo(str(current_app.debug))
|
click.echo(str(current_app.debug))
|
||||||
|
|
||||||
result = runner.invoke(cli, ["test"])
|
result = runner.invoke(cli_command, ["test"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert result.output == f"{not set_debug_flag}\n"
|
assert result.output == f"{not set_debug_flag}\n"
|
||||||
|
|
||||||
|
|
@ -388,18 +388,18 @@ def test_flaskgroup_nested(app, runner):
|
||||||
cli.add_command(flask_group)
|
cli.add_command(flask_group)
|
||||||
|
|
||||||
@flask_group.command()
|
@flask_group.command()
|
||||||
def show():
|
def show_command():
|
||||||
click.echo(current_app.name)
|
click.echo(current_app.name)
|
||||||
|
|
||||||
result = runner.invoke(cli, ["flask", "show"])
|
result = runner.invoke(cli, ["flask", "show_command"])
|
||||||
assert result.output == "flask_test\n"
|
assert result.output == "flask_test\n"
|
||||||
|
|
||||||
|
|
||||||
def test_no_command_echo_loading_error():
|
def test_no_command_echo_loading_error():
|
||||||
from flask.cli import cli
|
from flask.cli import cli
|
||||||
|
|
||||||
runner = CliRunner(mix_stderr=False)
|
cli_runner = CliRunner(mix_stderr=False)
|
||||||
result = runner.invoke(cli, ["missing"])
|
result = cli_runner.invoke(cli, ["missing"])
|
||||||
assert result.exit_code == 2
|
assert result.exit_code == 2
|
||||||
assert "FLASK_APP" in result.stderr
|
assert "FLASK_APP" in result.stderr
|
||||||
assert "Usage:" in result.stderr
|
assert "Usage:" in result.stderr
|
||||||
|
|
@ -408,8 +408,8 @@ def test_no_command_echo_loading_error():
|
||||||
def test_help_echo_loading_error():
|
def test_help_echo_loading_error():
|
||||||
from flask.cli import cli
|
from flask.cli import cli
|
||||||
|
|
||||||
runner = CliRunner(mix_stderr=False)
|
cli_runner = CliRunner(mix_stderr=False)
|
||||||
result = runner.invoke(cli, ["--help"])
|
result = cli_runner.invoke(cli, ["--help"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert "FLASK_APP" in result.stderr
|
assert "FLASK_APP" in result.stderr
|
||||||
assert "Usage:" in result.stdout
|
assert "Usage:" in result.stdout
|
||||||
|
|
@ -420,8 +420,8 @@ def test_help_echo_exception():
|
||||||
raise Exception("oh no")
|
raise Exception("oh no")
|
||||||
|
|
||||||
cli = FlaskGroup(create_app=create_app)
|
cli = FlaskGroup(create_app=create_app)
|
||||||
runner = CliRunner(mix_stderr=False)
|
runner_obj = CliRunner(mix_stderr=False)
|
||||||
result = runner.invoke(cli, ["--help"])
|
result = runner_obj.invoke(cli, ["--help"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert "Exception: oh no" in result.stderr
|
assert "Exception: oh no" in result.stderr
|
||||||
assert "Usage:" in result.stdout
|
assert "Usage:" in result.stdout
|
||||||
|
|
@ -476,28 +476,28 @@ class TestRoutes:
|
||||||
output = invoke(["routes", "--all-methods"]).output
|
output = invoke(["routes", "--all-methods"]).output
|
||||||
assert "GET, HEAD, OPTIONS, POST" in output
|
assert "GET, HEAD, OPTIONS, POST" in output
|
||||||
|
|
||||||
def test_no_routes(self, runner):
|
def test_no_routes(self, runner_):
|
||||||
app = Flask(__name__, static_folder=None)
|
app = Flask(__name__, static_folder=None)
|
||||||
cli = FlaskGroup(create_app=lambda: app)
|
cli = FlaskGroup(create_app=lambda: app)
|
||||||
result = runner.invoke(cli, ["routes"])
|
result = runner_.invoke(cli, ["routes"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert "No routes were registered." in result.output
|
assert "No routes were registered." in result.output
|
||||||
|
|
||||||
def test_subdomain(self, runner):
|
def test_subdomain(self, runner_):
|
||||||
app = Flask(__name__, static_folder=None)
|
app = Flask(__name__, static_folder=None)
|
||||||
app.add_url_rule("/a", subdomain="a", endpoint="a")
|
app.add_url_rule("/a", subdomain="a", endpoint="a")
|
||||||
app.add_url_rule("/b", subdomain="b", endpoint="b")
|
app.add_url_rule("/b", subdomain="b", endpoint="b")
|
||||||
cli = FlaskGroup(create_app=lambda: app)
|
cli = FlaskGroup(create_app=lambda: app)
|
||||||
result = runner.invoke(cli, ["routes"])
|
result = runner_.invoke(cli, ["routes"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert "Subdomain" in result.output
|
assert "Subdomain" in result.output
|
||||||
|
|
||||||
def test_host(self, runner):
|
def test_host(self, runner_):
|
||||||
app = Flask(__name__, static_folder=None, host_matching=True)
|
app = Flask(__name__, static_folder=None, host_matching=True)
|
||||||
app.add_url_rule("/a", host="a", endpoint="a")
|
app.add_url_rule("/a", host="a", endpoint="a")
|
||||||
app.add_url_rule("/b", host="b", endpoint="b")
|
app.add_url_rule("/b", host="b", endpoint="b")
|
||||||
cli = FlaskGroup(create_app=lambda: app)
|
cli = FlaskGroup(create_app=lambda: app)
|
||||||
result = runner.invoke(cli, ["routes"])
|
result = runner_.invoke(cli, ["routes"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert "Host" in result.output
|
assert "Host" in result.output
|
||||||
|
|
||||||
|
|
@ -558,10 +558,10 @@ def test_dotenv_optional(monkeypatch):
|
||||||
|
|
||||||
|
|
||||||
@need_dotenv
|
@need_dotenv
|
||||||
def test_disable_dotenv_from_env(monkeypatch, runner):
|
def test_disable_dotenv_from_env(monkeypatch, runner_):
|
||||||
monkeypatch.chdir(test_path)
|
monkeypatch.chdir(test_path)
|
||||||
monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")
|
monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")
|
||||||
runner.invoke(FlaskGroup())
|
runner_.invoke(FlaskGroup())
|
||||||
assert "FOO" not in os.environ
|
assert "FOO" not in os.environ
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -196,8 +196,8 @@ def test_json_decimal():
|
||||||
def test_json_attr(app, client):
|
def test_json_attr(app, client):
|
||||||
@app.route("/add", methods=["POST"])
|
@app.route("/add", methods=["POST"])
|
||||||
def add():
|
def add():
|
||||||
json = flask.request.get_json()
|
data = flask.request.get_json()
|
||||||
return str(json["a"] + json["b"])
|
return str(data["a"] + data["b"])
|
||||||
|
|
||||||
rv = client.post(
|
rv = client.post(
|
||||||
"/add",
|
"/add",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue