Skip to content
Myr

test_cli.py

This file

Path

tests/test_cli.py

700 lines · 19.5 KiB · Python

Last changed by

Merge branch '2.1.x'David Lordbefore adoption1626aff

History of this file

Take it

The walk stopped after 200 commits: lines older than f7e33f2 point at it.

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 1–3why, one step back
1# This file was part of Flask-CLI and was modified under the terms of
2# its Revised BSD License. Copyright © 2015 CERN.3import os

Merge branch '2.0.x'David Lordbefore adoption44bc286

line 4why, one step back
4import platform

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 5–8why, one step back
5import ssl
6import sys7import types8from functools import partial

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 9why, one step back
9from pathlib import Path

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 10–19why, one step back
10
11import click12import pytest13from _pytest.monkeypatch import notset14from click.testing import CliRunner1516from flask import Blueprint17from flask import current_app18from flask import Flask19from flask.cli import AppGroup

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoptionafc13b9

line 20why, one step back
20from flask.cli import DispatchingApp

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 21–31why, one step back
21from flask.cli import find_best_app
22from flask.cli import FlaskGroup23from flask.cli import get_version24from flask.cli import load_dotenv25from flask.cli import locate_app26from flask.cli import NoAppException27from flask.cli import prepare_import28from flask.cli import run_command29from flask.cli import ScriptInfo30from flask.cli import with_appcontext31

Merge branch '2.0.x'David Lordbefore adoption83f7efa

lines 32–33why, one step back
32cwd = Path.cwd()
33test_path = (Path(__file__) / ".." / "test_apps").resolve()

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 34–51why, one step back
34
3536@pytest.fixture37def runner():38 return CliRunner()394041def test_cli_name(test_apps):42 """Make sure the CLI object's name is the app's name and not the app itself"""43 from cliapp.app import testapp4445 assert testapp.cli.name == testapp.name464748def test_find_best_app(test_apps):49 class Module:50 app = Flask("appname")51

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 52why, one step back
52 assert find_best_app(Module) == Module.app

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 53–56why, one step back
53
54 class Module:55 application = Flask("appname")56

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 57why, one step back
57 assert find_best_app(Module) == Module.application

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 58–61why, one step back
58
59 class Module:60 myapp = Flask("appname")61

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 62why, one step back
62 assert find_best_app(Module) == Module.myapp

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 63–68why, one step back
63
64 class Module:65 @staticmethod66 def create_app():67 return Flask("appname")68

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 69why, one step back
69 app = find_best_app(Module)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 70–74why, one step back
70 assert isinstance(app, Flask)
71 assert app.name == "appname"7273 class Module:74 @staticmethod

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoptionafc13b9

lines 75–77why, one step back
75 def create_app(**kwargs):
76 return Flask("appname")77

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 78why, one step back
78 app = find_best_app(Module)

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoptionafc13b9

lines 79–83why, one step back
79 assert isinstance(app, Flask)
80 assert app.name == "appname"8182 class Module:83 @staticmethod

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 84–86why, one step back
84 def make_app():
85 return Flask("appname")86

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 87why, one step back
87 app = find_best_app(Module)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 88–97why, one step back
88 assert isinstance(app, Flask)
89 assert app.name == "appname"9091 class Module:92 myapp = Flask("appname1")9394 @staticmethod95 def create_app():96 return Flask("appname2")97

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 98why, one step back
98 assert find_best_app(Module) == Module.myapp

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 99–106why, one step back
99
100 class Module:101 myapp = Flask("appname1")102103 @staticmethod104 def create_app():105 return Flask("appname2")106

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 107why, one step back
107 assert find_best_app(Module) == Module.myapp

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 108–111why, one step back
108
109 class Module:110 pass111

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 112why, one step back
112 pytest.raises(NoAppException, find_best_app, Module)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 113–117why, one step back
113
114 class Module:115 myapp1 = Flask("appname1")116 myapp2 = Flask("appname2")117

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 118why, one step back
118 pytest.raises(NoAppException, find_best_app, Module)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 119–124why, one step back
119
120 class Module:121 @staticmethod122 def create_app(foo, bar):123 return Flask("appname2")124

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 125why, one step back
125 pytest.raises(NoAppException, find_best_app, Module)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 126–131why, one step back
126
127 class Module:128 @staticmethod129 def create_app():130 raise TypeError("bad bad factory!")131

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 132why, one step back
132 pytest.raises(TypeError, find_best_app, Module)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 133–139why, one step back
133
134135@pytest.mark.parametrize(136 "value,path,result",137 (138 ("test", cwd, "test"),139 ("test.py", cwd, "test"),

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 140why, one step back
140 ("a/test", cwd / "a", "test"),

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 141–144why, one step back
141 ("test/__init__.py", cwd, "test"),
142 ("test/__init__", cwd, "test"),143 # nested package144 (

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 145why, one step back
145 test_path / "cliapp" / "inner1" / "__init__",

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 146–149why, one step back
146 test_path,
147 "cliapp.inner1",148 ),149 (

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 150why, one step back
150 test_path / "cliapp" / "inner1" / "inner2",

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 151–155why, one step back
151 test_path,
152 "cliapp.inner1.inner2",153 ),154 # dotted name155 ("test.a.b", cwd, "test.a.b"),

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 156why, one step back
156 (test_path / "cliapp.app", test_path, "cliapp.app"),

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

line 157why, one step back
157 # not a Python file, will be caught during import

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 158why, one step back
158 (test_path / "cliapp" / "message.txt", test_path, "cliapp.message.txt"),

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 159–176why, one step back
159 ),
160)161def test_prepare_import(request, value, path, result):162 """Expect the correct path to be set and the correct import and app names163 to be returned.164165 :func:`prepare_exec_for_file` has a side effect where the parent directory166 of the given import is added to :data:`sys.path`. This is reset after the167 test runs.168 """169 original_path = sys.path[:]170171 def reset_path():172 sys.path[:] = original_path173174 request.addfinalizer(reset_path)175176 assert prepare_import(value) == result

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 177why, one step back
177 assert sys.path[0] == str(path)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 178–195why, one step back
178
179180@pytest.mark.parametrize(181 "iname,aname,result",182 (183 ("cliapp.app", None, "testapp"),184 ("cliapp.app", "testapp", "testapp"),185 ("cliapp.factory", None, "app"),186 ("cliapp.factory", "create_app", "app"),187 ("cliapp.factory", "create_app()", "app"),188 ("cliapp.factory", 'create_app2("foo", "bar")', "app2_foo_bar"),189 # trailing comma space190 ("cliapp.factory", 'create_app2("foo", "bar", )', "app2_foo_bar"),191 # strip whitespace192 ("cliapp.factory", " create_app () ", "app"),193 ),194)195def test_locate_app(test_apps, iname, aname, result):

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 196why, one step back
196 assert locate_app(iname, aname).name == result

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 197–218why, one step back
197
198199@pytest.mark.parametrize(200 "iname,aname",201 (202 ("notanapp.py", None),203 ("cliapp/app", None),204 ("cliapp.app", "notanapp"),205 # not enough arguments206 ("cliapp.factory", 'create_app2("foo")'),207 # invalid identifier208 ("cliapp.factory", "create_app("),209 # no app returned210 ("cliapp.factory", "no_app"),211 # nested import error212 ("cliapp.importerrorapp", None),213 # not a Python file214 ("cliapp.message.txt", None),215 ),216)217def test_locate_app_raises(test_apps, iname, aname):218 with pytest.raises(NoAppException):

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 219why, one step back
219 locate_app(iname, aname)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 220–222why, one step back
220
221222def test_locate_app_suppress_raise(test_apps):

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 223why, one step back
223 app = locate_app("notanapp.py", None, raise_if_not_found=False)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 224–227why, one step back
224 assert app is None
225226 # only direct import error is suppressed227 with pytest.raises(NoAppException):

Merge pull request #4337 from pallets/remove-deprecated-codeDavid Lordbefore adoption7620cb7

line 228why, one step back
228 locate_app("cliapp.importerrorapp", None, raise_if_not_found=False)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 229–257why, one step back
229
230231def test_get_version(test_apps, capsys):232 from flask import __version__ as flask_version233 from werkzeug import __version__ as werkzeug_version234 from platform import python_version235236 class MockCtx:237 resilient_parsing = False238 color = None239240 def exit(self):241 return242243 ctx = MockCtx()244 get_version(ctx, None, "test")245 out, err = capsys.readouterr()246 assert f"Python {python_version()}" in out247 assert f"Flask {flask_version}" in out248 assert f"Werkzeug {werkzeug_version}" in out249250251def test_scriptinfo(test_apps, monkeypatch):252 obj = ScriptInfo(app_import_path="cliapp.app:testapp")253 app = obj.load_app()254 assert app.name == "testapp"255 assert obj.load_app() is app256257 # import app with module's absolute path

Merge branch '2.0.x'David Lordbefore adoption83f7efa

lines 258–259why, one step back
258 cli_app_path = str(test_path / "cliapp" / "app.py")
259

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 260–280why, one step back
260 obj = ScriptInfo(app_import_path=cli_app_path)
261 app = obj.load_app()262 assert app.name == "testapp"263 assert obj.load_app() is app264 obj = ScriptInfo(app_import_path=f"{cli_app_path}:testapp")265 app = obj.load_app()266 assert app.name == "testapp"267 assert obj.load_app() is app268269 def create_app():270 return Flask("createapp")271272 obj = ScriptInfo(create_app=create_app)273 app = obj.load_app()274 assert app.name == "createapp"275 assert obj.load_app() is app276277 obj = ScriptInfo()278 pytest.raises(NoAppException, obj.load_app)279280 # import app from wsgi.py in current directory

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 281why, one step back
281 monkeypatch.chdir(test_path / "helloworld")

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 282–286why, one step back
282 obj = ScriptInfo()
283 app = obj.load_app()284 assert app.name == "hello"285286 # import app from app.py in current directory

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 287why, one step back
287 monkeypatch.chdir(test_path / "cliapp")

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 288–290why, one step back
288 obj = ScriptInfo()
289 app = obj.load_app()290 assert app.name == "testapp"

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoptionafc13b9

lines 291–292why, one step back
291
292

Merge branch '2.0.x'David Lordbefore adoption44bc286

line 293why, one step back
293@pytest.mark.xfail(platform.python_implementation() == "PyPy", reason="flaky on pypy")

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoptionafc13b9

lines 294–306why, one step back
294def test_lazy_load_error(monkeypatch):
295 """When using lazy loading, the correct exception should be296 re-raised.297 """298299 class BadExc(Exception):300 pass301302 def bad_load():303 raise BadExc304305 lazy = DispatchingApp(bad_load, use_eager_loading=False)306

Merge branch '2.1.x'David Lordbefore adoptionf976d5b

lines 307–309why, one step back
307 # reduce flakiness by waiting for the internal loading lock
308 with lazy._lock:309 with pytest.raises(BadExc):

Merge branch '2.0.x'David Lordbefore adoptionfb82e3c

line 310why, one step back
310 lazy._flush_bg_loading_exception()

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 311–312why, one step back
311
312

Merge pull request #4647 from pallets/cli-app_contextDavid Lordbefore adoptioncec5f74

lines 313–323why, one step back
313def test_app_cli_has_app_context(app, runner):
314 def _param_cb(ctx, param, value):315 # current_app should be available in parameter callbacks316 return bool(current_app)317318 @app.cli.command()319 @click.argument("value", callback=_param_cb)320 def check(value):321 app = click.get_current_context().obj.load_app()322 # the loaded app should be the same as current_app323 same_app = current_app._get_current_object() is app

Merge pull request #4662 from pallets/fix-run-skipDavid Lordbefore adoption3635583

line 324why, one step back
324 return same_app, value

Merge pull request #4647 from pallets/cli-app_contextDavid Lordbefore adoptioncec5f74

lines 325–327why, one step back
325
326 cli = FlaskGroup(create_app=lambda: app)327 result = runner.invoke(cli, ["check", "x"], standalone_mode=False)

Merge pull request #4662 from pallets/fix-run-skipDavid Lordbefore adoption3635583

line 328why, one step back
328 assert result.return_value == (True, True)

Merge pull request #4647 from pallets/cli-app_contextDavid Lordbefore adoptioncec5f74

lines 329–330why, one step back
329
330

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 331–343why, one step back
331def test_with_appcontext(runner):
332 @click.command()333 @with_appcontext334 def testcmd():335 click.echo(current_app.name)336337 obj = ScriptInfo(create_app=lambda: Flask("testapp"))338339 result = runner.invoke(testcmd, obj=obj)340 assert result.exit_code == 0341 assert result.output == "testapp\n"342343

Merge pull request #4647 from pallets/cli-app_contextDavid Lordbefore adoptioncec5f74

line 344why, one step back
344def test_appgroup_app_context(runner):

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 345–348why, one step back
345 @click.group(cls=AppGroup)
346 def cli():347 pass348

Merge pull request #4647 from pallets/cli-app_contextDavid Lordbefore adoptioncec5f74

line 349why, one step back
349 @cli.command()

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 350–356why, one step back
350 def test():
351 click.echo(current_app.name)352353 @cli.group()354 def subgroup():355 pass356

Merge pull request #4647 from pallets/cli-app_contextDavid Lordbefore adoptioncec5f74

line 357why, one step back
357 @subgroup.command()

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 358–371why, one step back
358 def test2():
359 click.echo(current_app.name)360361 obj = ScriptInfo(create_app=lambda: Flask("testappgroup"))362363 result = runner.invoke(cli, ["test"], obj=obj)364 assert result.exit_code == 0365 assert result.output == "testappgroup\n"366367 result = runner.invoke(cli, ["subgroup", "test2"], obj=obj)368 assert result.exit_code == 0369 assert result.output == "testappgroup\n"370371

Merge pull request #4647 from pallets/cli-app_contextDavid Lordbefore adoptioncec5f74

line 372why, one step back
372def test_flaskgroup_app_context(runner):

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 373–408why, one step back
373 def create_app():
374 return Flask("flaskgroup")375376 @click.group(cls=FlaskGroup, create_app=create_app)377 def cli(**params):378 pass379380 @cli.command()381 def test():382 click.echo(current_app.name)383384 result = runner.invoke(cli, ["test"])385 assert result.exit_code == 0386 assert result.output == "flaskgroup\n"387388389@pytest.mark.parametrize("set_debug_flag", (True, False))390def test_flaskgroup_debug(runner, set_debug_flag):391 def create_app():392 app = Flask("flaskgroup")393 app.debug = True394 return app395396 @click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)397 def cli(**params):398 pass399400 @cli.command()401 def test():402 click.echo(str(current_app.debug))403404 result = runner.invoke(cli, ["test"])405 assert result.exit_code == 0406 assert result.output == f"{not set_debug_flag}\n"407408

Merge pull request #4642 from pallets/cli-nestDavid Lordbefore adoptionfe4003b

lines 409–421why, one step back
409def test_flaskgroup_nested(app, runner):
410 cli = click.Group("cli")411 flask_group = FlaskGroup(name="flask", create_app=lambda: app)412 cli.add_command(flask_group)413414 @flask_group.command()415 def show():416 click.echo(current_app.name)417418 result = runner.invoke(cli, ["flask", "show"])419 assert result.output == "flask_test\n"420421

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 422–455why, one step back
422def test_no_command_echo_loading_error():
423 from flask.cli import cli424425 runner = CliRunner(mix_stderr=False)426 result = runner.invoke(cli, ["missing"])427 assert result.exit_code == 2428 assert "FLASK_APP" in result.stderr429 assert "Usage:" in result.stderr430431432def test_help_echo_loading_error():433 from flask.cli import cli434435 runner = CliRunner(mix_stderr=False)436 result = runner.invoke(cli, ["--help"])437 assert result.exit_code == 0438 assert "FLASK_APP" in result.stderr439 assert "Usage:" in result.stdout440441442def test_help_echo_exception():443 def create_app():444 raise Exception("oh no")445446 cli = FlaskGroup(create_app=create_app)447 runner = CliRunner(mix_stderr=False)448 result = runner.invoke(cli, ["--help"])449 assert result.exit_code == 0450 assert "Exception: oh no" in result.stderr451 assert "Usage:" in result.stdout452453454class TestRoutes:455 @pytest.fixture

Merge branch '2.1.x'David Lordbefore adoption1626aff

lines 456–458why, one step back
456 def app(self):
457 app = Flask(__name__)458 app.testing = True

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

line 459why, one step back
459

Merge branch '2.1.x'David Lordbefore adoption1626aff

lines 460–462why, one step back
460 @app.route("/get_post/<int:x>/<int:y>", methods=["GET", "POST"])
461 def yyy_get_post(x, y):462 pass

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

line 463why, one step back
463

Merge branch '2.1.x'David Lordbefore adoption1626aff

lines 464–466why, one step back
464 @app.route("/zzz_post", methods=["POST"])
465 def aaa_post():466 pass

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

line 467why, one step back
467

Merge branch '2.1.x'David Lordbefore adoption1626aff

line 468why, one step back
468 return app

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

line 469why, one step back
469

Merge branch '2.1.x'David Lordbefore adoption1626aff

lines 470–472why, one step back
470 @pytest.fixture
471 def invoke(self, app, runner):472 cli = FlaskGroup(create_app=lambda: app)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 473–496why, one step back
473 return partial(runner.invoke, cli)
474475 @pytest.fixture476 def invoke_no_routes(self, runner):477 def create_app():478 app = Flask(__name__, static_folder=None)479 app.testing = True480481 return app482483 cli = FlaskGroup(create_app=create_app)484 return partial(runner.invoke, cli)485486 def expect_order(self, order, output):487 # skip the header and match the start of each row488 for expect, line in zip(order, output.splitlines()[2:]):489 # do this instead of startswith for nicer pytest output490 assert line[: len(expect)] == expect491492 def test_simple(self, invoke):493 result = invoke(["routes"])494 assert result.exit_code == 0495 self.expect_order(["aaa_post", "static", "yyy_get_post"], result.output)496

Merge branch '2.1.x'David Lordbefore adoption1626aff

line 497why, one step back
497 def test_sort(self, app, invoke):

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 498–508why, one step back
498 default_output = invoke(["routes"]).output
499 endpoint_output = invoke(["routes", "-s", "endpoint"]).output500 assert default_output == endpoint_output501 self.expect_order(502 ["static", "yyy_get_post", "aaa_post"],503 invoke(["routes", "-s", "methods"]).output,504 )505 self.expect_order(506 ["yyy_get_post", "static", "aaa_post"],507 invoke(["routes", "-s", "rule"]).output,508 )

Merge branch '2.1.x'David Lordbefore adoption1626aff

lines 509–510why, one step back
509 match_order = [r.endpoint for r in app.url_map.iter_rules()]
510 self.expect_order(match_order, invoke(["routes", "-s", "match"]).output)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 511–523why, one step back
511
512 def test_all_methods(self, invoke):513 output = invoke(["routes"]).output514 assert "GET, HEAD, OPTIONS, POST" not in output515 output = invoke(["routes", "--all-methods"]).output516 assert "GET, HEAD, OPTIONS, POST" in output517518 def test_no_routes(self, invoke_no_routes):519 result = invoke_no_routes(["routes"])520 assert result.exit_code == 0521 assert "No routes were registered." in result.output522523

Merge remote-tracking branch 'origin/2.1.x'David Lordbefore adoption1888df3

lines 524–528why, one step back
524def dotenv_not_available():
525 try:526 import dotenv # noqa: F401527 except ImportError:528 return True

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

line 529why, one step back
529

Merge remote-tracking branch 'origin/2.1.x'David Lordbefore adoption1888df3

line 530why, one step back
530 return False

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

line 531why, one step back
531

Merge remote-tracking branch 'origin/2.1.x'David Lordbefore adoption1888df3

lines 532–537why, one step back
532
533need_dotenv = pytest.mark.skipif(534 dotenv_not_available(), reason="dotenv is not installed"535)536537

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 538–540why, one step back
538@need_dotenv
539def test_load_dotenv(monkeypatch):540 # can't use monkeypatch.delitem since the keys don't exist yet

Merge pull request #3932 from greyli/set-encodingDavid Lordbefore adoption3316604

line 541why, one step back
541 for item in ("FOO", "BAR", "SPAM", "HAM"):

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 542–546why, one step back
542 monkeypatch._setitem.append((os.environ, item, notset))
543544 monkeypatch.setenv("EGGS", "3")545 monkeypatch.chdir(test_path)546 assert load_dotenv()

Merge branch '2.0.x'David Lordbefore adoption83f7efa

line 547why, one step back
547 assert Path.cwd() == test_path

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 548–555why, one step back
548 # .flaskenv doesn't overwrite .env
549 assert os.environ["FOO"] == "env"550 # set only in .flaskenv551 assert os.environ["BAR"] == "bar"552 # set only in .env553 assert os.environ["SPAM"] == "1"554 # set manually, files don't overwrite555 assert os.environ["EGGS"] == "3"

Merge pull request #3932 from greyli/set-encodingDavid Lordbefore adoption3316604

lines 556–557why, one step back
556 # test env file encoding
557 assert os.environ["HAM"] == "火腿"

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 558–566why, one step back
558 # Non existent file should not load
559 assert not load_dotenv("non-existent-file")560561562@need_dotenv563def test_dotenv_path(monkeypatch):564 for item in ("FOO", "BAR", "EGGS"):565 monkeypatch._setitem.append((os.environ, item, notset))566

Merge branch '2.0.x'David Lordbefore adoption83f7efa

lines 567–568why, one step back
567 load_dotenv(test_path / ".flaskenv")
568 assert Path.cwd() == cwd

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 569–572why, one step back
569 assert "FOO" in os.environ
570571572def test_dotenv_optional(monkeypatch):

Merge remote-tracking branch 'origin/2.1.x'David Lordbefore adoption1888df3

line 573why, one step back
573 monkeypatch.setitem(sys.modules, "dotenv", None)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 574–595why, one step back
574 monkeypatch.chdir(test_path)
575 load_dotenv()576 assert "FOO" not in os.environ577578579@need_dotenv580def test_disable_dotenv_from_env(monkeypatch, runner):581 monkeypatch.chdir(test_path)582 monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")583 runner.invoke(FlaskGroup())584 assert "FOO" not in os.environ585586587def test_run_cert_path():588 # no key589 with pytest.raises(click.BadParameter):590 run_command.make_context("run", ["--cert", __file__])591592 # no cert593 with pytest.raises(click.BadParameter):594 run_command.make_context("run", ["--key", __file__])595

Merge branch '2.1.x'David Lordbefore adoptioncb4f742

line 596why, one step back
596 # cert specified first

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 597–599why, one step back
597 ctx = run_command.make_context("run", ["--cert", __file__, "--key", __file__])
598 assert ctx.params["cert"] == (__file__, __file__)599

Merge branch '2.1.x'David Lordbefore adoptioncb4f742

lines 600–602why, one step back
600 # key specified first
601 ctx = run_command.make_context("run", ["--key", __file__, "--cert", __file__])602 assert ctx.params["cert"] == (__file__, __file__)

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

line 603why, one step back
603

Merge branch '2.1.x'David Lordbefore adoptioncb4f742

line 604why, one step back
604

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 605–644why, one step back
605def test_run_cert_adhoc(monkeypatch):
606 monkeypatch.setitem(sys.modules, "cryptography", None)607608 # cryptography not installed609 with pytest.raises(click.BadParameter):610 run_command.make_context("run", ["--cert", "adhoc"])611612 # cryptography installed613 monkeypatch.setitem(sys.modules, "cryptography", types.ModuleType("cryptography"))614 ctx = run_command.make_context("run", ["--cert", "adhoc"])615 assert ctx.params["cert"] == "adhoc"616617 # no key with adhoc618 with pytest.raises(click.BadParameter):619 run_command.make_context("run", ["--cert", "adhoc", "--key", __file__])620621622def test_run_cert_import(monkeypatch):623 monkeypatch.setitem(sys.modules, "not_here", None)624625 # ImportError626 with pytest.raises(click.BadParameter):627 run_command.make_context("run", ["--cert", "not_here"])628629 with pytest.raises(click.BadParameter):630 run_command.make_context("run", ["--cert", "flask"])631632 # SSLContext633 ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)634635 monkeypatch.setitem(sys.modules, "ssl_context", ssl_context)636 ctx = run_command.make_context("run", ["--cert", "ssl_context"])637 assert ctx.params["cert"] is ssl_context638639 # no --key with SSLContext640 with pytest.raises(click.BadParameter):641 run_command.make_context("run", ["--cert", "ssl_context", "--key", __file__])642643644def test_run_cert_no_ssl(monkeypatch):

Merge remote-tracking branch 'origin/2.1.x'David Lordbefore adoption1888df3

lines 645–646why, one step back
645 monkeypatch.setitem(sys.modules, "ssl", None)
646

Bump sphinx-tabs from 1.1.13 to 1.3.0 (#3822)dependabot-preview[bot]before adoptionf7e33f2

lines 647–700why, one step back
647 with pytest.raises(click.BadParameter):
648 run_command.make_context("run", ["--cert", "not_here"])649650651def test_cli_blueprints(app):652 """Test blueprint commands register correctly to the application"""653 custom = Blueprint("custom", __name__, cli_group="customized")654 nested = Blueprint("nested", __name__)655 merged = Blueprint("merged", __name__, cli_group=None)656 late = Blueprint("late", __name__)657658 @custom.cli.command("custom")659 def custom_command():660 click.echo("custom_result")661662 @nested.cli.command("nested")663 def nested_command():664 click.echo("nested_result")665666 @merged.cli.command("merged")667 def merged_command():668 click.echo("merged_result")669670 @late.cli.command("late")671 def late_command():672 click.echo("late_result")673674 app.register_blueprint(custom)675 app.register_blueprint(nested)676 app.register_blueprint(merged)677 app.register_blueprint(late, cli_group="late_registration")678679 app_runner = app.test_cli_runner()680681 result = app_runner.invoke(args=["customized", "custom"])682 assert "custom_result" in result.output683684 result = app_runner.invoke(args=["nested", "nested"])685 assert "nested_result" in result.output686687 result = app_runner.invoke(args=["merged"])688 assert "merged_result" in result.output689690 result = app_runner.invoke(args=["late_registration", "late"])691 assert "late_result" in result.output692693694def test_cli_empty(app):695 """If a Blueprint's CLI group is empty, do not register it."""696 bp = Blueprint("blue", __name__, cli_group="blue")697 app.register_blueprint(bp)698699 result = app.test_cli_runner().invoke(args=["blue", "--help"])700 assert result.exit_code == 2, f"Unexpected success:\n\n{result.output}"