test_cli.py
This file
Path
tests/test_cli.py
656 lines · 18.4 KiB · Python
Last changed by
Merge pull request #3564 from pallets/cli-ast-parseDavid Lordbefore adoption2062d98
History of this fileTake it
The walk stopped after 200 commits: lines older than 0123e65 point at it.
Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 1–13why, one step back1# This file was part of Flask-CLI and was modified under the terms of2# its Revised BSD License. Copyright © 2015 CERN.3import os4import ssl5import sys6import types7from functools import partial89import click10import pytest11from _pytest.monkeypatch import notset12from click.testing import CliRunner13Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
lines 14–28why, one step back14from flask import Blueprint15from flask import current_app16from flask import Flask17from flask.cli import AppGroup18from flask.cli import dotenv19from flask.cli import find_best_app20from flask.cli import FlaskGroup21from flask.cli import get_version22from flask.cli import load_dotenv23from flask.cli import locate_app24from flask.cli import NoAppException25from flask.cli import prepare_import26from flask.cli import run_command27from flask.cli import ScriptInfo28from flask.cli import with_appcontextMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 29–30why, one step back2930cwd = os.getcwd()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 31why, one step back31test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps"))Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 32–41why, one step back323334@pytest.fixture35def runner():36 return CliRunner()373839def test_cli_name(test_apps):40 """Make sure the CLI object's name is the app's name and not the app itself"""41 from cliapp.app import testappMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 42why, one step back42Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 43–46why, one step back43 assert testapp.cli.name == testapp.name444546def test_find_best_app(test_apps):Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 47why, one step back47 """Test if `find_best_app` behaves as expected with different combinations of input.""" # noqa: B950Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 48–50why, one step back48 script_info = ScriptInfo()4950 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 51why, one step back51 app = Flask("appname")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 52–55why, one step back5253 assert find_best_app(script_info, Module) == Module.app5455 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 56why, one step back56 application = Flask("appname")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 57–60why, one step back5758 assert find_best_app(script_info, Module) == Module.application5960 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 61why, one step back61 myapp = Flask("appname")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 62–67why, one step back6263 assert find_best_app(script_info, Module) == Module.myapp6465 class Module:66 @staticmethod67 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 68why, one step back68 return Flask("appname")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 69why, one step back69Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
lines 70–72why, one step back70 app = find_best_app(script_info, Module)71 assert isinstance(app, Flask)72 assert app.name == "appname"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 73–76why, one step back7374 class Module:75 @staticmethod76 def create_app(foo):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 77why, one step back77 return Flask("appname")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 78why, one step back78Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
lines 79–80why, one step back79 with pytest.deprecated_call(match="Script info"):80 app = find_best_app(script_info, Module)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 81why, one step back81Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
lines 82–84why, one step back82 assert isinstance(app, Flask)83 assert app.name == "appname"84Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 85–87why, one step back85 class Module:86 @staticmethod87 def create_app(foo=None, script_info=None):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 88why, one step back88 return Flask("appname")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 89why, one step back89Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
lines 90–91why, one step back90 with pytest.deprecated_call(match="script_info"):91 app = find_best_app(script_info, Module)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 92why, one step back92Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
lines 93–95why, one step back93 assert isinstance(app, Flask)94 assert app.name == "appname"95Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 96–98why, one step back96 class Module:97 @staticmethod98 def make_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 99why, one step back99 return Flask("appname")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 100why, one step back100Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
lines 101–103why, one step back101 app = find_best_app(script_info, Module)102 assert isinstance(app, Flask)103 assert app.name == "appname"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 104–105why, one step back104105 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 106why, one step back106 myapp = Flask("appname1")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 107–109why, one step back107108 @staticmethod109 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 110why, one step back110 return Flask("appname2")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 111–114why, one step back111112 assert find_best_app(script_info, Module) == Module.myapp113114 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 115why, one step back115 myapp = Flask("appname1")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 116–118why, one step back116117 @staticmethod118 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 119why, one step back119 return Flask("appname2")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 120–128why, one step back120121 assert find_best_app(script_info, Module) == Module.myapp122123 class Module:124 pass125126 pytest.raises(NoAppException, find_best_app, script_info, Module)127128 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 129–130why, one step back129 myapp1 = Flask("appname1")130 myapp2 = Flask("appname2")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 131–136why, one step back131132 pytest.raises(NoAppException, find_best_app, script_info, Module)133134 class Module:135 @staticmethod136 def create_app(foo, bar):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 137why, one step back137 return Flask("appname2")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 138–143why, one step back138139 pytest.raises(NoAppException, find_best_app, script_info, Module)140141 class Module:142 @staticmethod143 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 144why, one step back144 raise TypeError("bad bad factory!")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 145–148why, one step back145146 pytest.raises(TypeError, find_best_app, script_info, Module)147148Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 149–150why, one step back149@pytest.mark.parametrize(150 "value,path,result",Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 151why, one step back151 (Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 152–176why, one step back152 ("test", cwd, "test"),153 ("test.py", cwd, "test"),154 ("a/test", os.path.join(cwd, "a"), "test"),155 ("test/__init__.py", cwd, "test"),156 ("test/__init__", cwd, "test"),157 # nested package158 (159 os.path.join(test_path, "cliapp", "inner1", "__init__"),160 test_path,161 "cliapp.inner1",162 ),163 (164 os.path.join(test_path, "cliapp", "inner1", "inner2"),165 test_path,166 "cliapp.inner1.inner2",167 ),168 # dotted name169 ("test.a.b", cwd, "test.a.b"),170 (os.path.join(test_path, "cliapp.app"), test_path, "cliapp.app"),171 # not a Python file, will be caught during import172 (173 os.path.join(test_path, "cliapp", "message.txt"),174 test_path,175 "cliapp.message.txt",176 ),Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 177why, one step back177 ),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 178why, one step back178)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 179–197why, one step back179def test_prepare_import(request, value, path, result):180 """Expect the correct path to be set and the correct import and app names181 to be returned.182183 :func:`prepare_exec_for_file` has a side effect where the parent directory184 of the given import is added to :data:`sys.path`. This is reset after the185 test runs.186 """187 original_path = sys.path[:]188189 def reset_path():190 sys.path[:] = original_path191192 request.addfinalizer(reset_path)193194 assert prepare_import(value) == result195 assert sys.path[0] == path196197Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 198–212why, one step back198@pytest.mark.parametrize(199 "iname,aname,result",200 (201 ("cliapp.app", None, "testapp"),202 ("cliapp.app", "testapp", "testapp"),203 ("cliapp.factory", None, "app"),204 ("cliapp.factory", "create_app", "app"),205 ("cliapp.factory", "create_app()", "app"),206 ("cliapp.factory", 'create_app2("foo", "bar")', "app2_foo_bar"),207 # trailing comma space208 ("cliapp.factory", 'create_app2("foo", "bar", )', "app2_foo_bar"),209 # strip whitespace210 ("cliapp.factory", " create_app () ", "app"),211 ),212)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 213–217why, one step back213def test_locate_app(test_apps, iname, aname, result):214 info = ScriptInfo()215 assert locate_app(info, iname, aname).name == result216217Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 218–235why, one step back218@pytest.mark.parametrize(219 "iname,aname",220 (221 ("notanapp.py", None),222 ("cliapp/app", None),223 ("cliapp.app", "notanapp"),224 # not enough arguments225 ("cliapp.factory", 'create_app2("foo")'),226 # invalid identifier227 ("cliapp.factory", "create_app("),228 # no app returned229 ("cliapp.factory", "no_app"),230 # nested import error231 ("cliapp.importerrorapp", None),232 # not a Python file233 ("cliapp.message.txt", None),234 ),235)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 236–244why, one step back236def test_locate_app_raises(test_apps, iname, aname):237 info = ScriptInfo()238239 with pytest.raises(NoAppException):240 locate_app(info, iname, aname)241242243def test_locate_app_suppress_raise():244 info = ScriptInfo()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 245why, one step back245 app = locate_app(info, "notanapp.py", None, raise_if_not_found=False)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 246–249why, one step back246 assert app is None247248 # only direct import error is suppressed249 with pytest.raises(NoAppException):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 250why, one step back250 locate_app(info, "cliapp.importerrorapp", None, raise_if_not_found=False)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 251–253why, one step back251252253def test_get_version(test_apps, capsys):Merge branch '1.0-maintenance'David Lordbefore adoption4f3dbb3
lines 254–256why, one step back254 from flask import __version__ as flask_version255 from werkzeug import __version__ as werkzeug_version256 from platform import python_versionMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 257why, one step back257Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 258why, one step back258 class MockCtx:Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 259–261why, one step back259 resilient_parsing = False260 color = None261Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 262–263why, one step back262 def exit(self):263 returnMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 264–267why, one step back264265 ctx = MockCtx()266 get_version(ctx, None, "test")267 out, err = capsys.readouterr()Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 268–270why, one step back268 assert f"Python {python_version()}" in out269 assert f"Flask {flask_version}" in out270 assert f"Werkzeug {werkzeug_version}" in outMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 271–275why, one step back271272273def test_scriptinfo(test_apps, monkeypatch):274 """Test of ScriptInfo."""275 obj = ScriptInfo(app_import_path="cliapp.app:testapp")Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
lines 276–278why, one step back276 app = obj.load_app()277 assert app.name == "testapp"278 assert obj.load_app() is appMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 279why, one step back279Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 280why, one step back280 # import app with module's absolute pathMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 281–283why, one step back281 cli_app_path = os.path.abspath(282 os.path.join(os.path.dirname(__file__), "test_apps", "cliapp", "app.py")283 )Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
lines 284–285why, one step back284 obj = ScriptInfo(app_import_path=cli_app_path)285 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 286why, one step back286 assert app.name == "testapp"Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 287why, one step back287 assert obj.load_app() is appMerge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 288why, one step back288 obj = ScriptInfo(app_import_path=f"{cli_app_path}:testapp")Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 289why, one step back289 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 290why, one step back290 assert app.name == "testapp"Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
lines 291–292why, one step back291 assert obj.load_app() is app292Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
line 293why, one step back293 def create_app():Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 294–298why, one step back294 return Flask("createapp")295296 obj = ScriptInfo(create_app=create_app)297 app = obj.load_app()298 assert app.name == "createapp"Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 299why, one step back299 assert obj.load_app() is appMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 300–304why, one step back300301 obj = ScriptInfo()302 pytest.raises(NoAppException, obj.load_app)303304 # import app from wsgi.py in current directoryMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 305–309why, one step back305 monkeypatch.chdir(306 os.path.abspath(307 os.path.join(os.path.dirname(__file__), "test_apps", "helloworld")308 )309 )Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 310–311why, one step back310 obj = ScriptInfo()311 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 312why, one step back312 assert app.name == "hello"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 313–314why, one step back313314 # import app from app.py in current directoryMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 315–317why, one step back315 monkeypatch.chdir(316 os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps", "cliapp"))317 )Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 318–319why, one step back318 obj = ScriptInfo()319 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 320why, one step back320 assert app.name == "testapp"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 321–330why, one step back321322323def test_with_appcontext(runner):324 """Test of with_appcontext."""325326 @click.command()327 @with_appcontext328 def testcmd():329 click.echo(current_app.name)330Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
line 331why, one step back331 obj = ScriptInfo(create_app=lambda: Flask("testapp"))Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 332–334why, one step back332333 result = runner.invoke(testcmd, obj=obj)334 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 335why, one step back335 assert result.output == "testapp\n"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 336–356why, one step back336337338def test_appgroup(runner):339 """Test of with_appcontext."""340341 @click.group(cls=AppGroup)342 def cli():343 pass344345 @cli.command(with_appcontext=True)346 def test():347 click.echo(current_app.name)348349 @cli.group()350 def subgroup():351 pass352353 @subgroup.command(with_appcontext=True)354 def test2():355 click.echo(current_app.name)356Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
line 357why, one step back357 obj = ScriptInfo(create_app=lambda: Flask("testappgroup"))Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 358why, one step back358Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 359why, one step back359 result = runner.invoke(cli, ["test"], obj=obj)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 360why, one step back360 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 361why, one step back361 assert result.output == "testappgroup\n"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 362why, one step back362Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 363why, one step back363 result = runner.invoke(cli, ["subgroup", "test2"], obj=obj)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 364why, one step back364 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 365why, one step back365 assert result.output == "testappgroup\n"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 366–370why, one step back366367368def test_flaskgroup(runner):369 """Test FlaskGroup."""370Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
line 371why, one step back371 def create_app():Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 372–381why, one step back372 return Flask("flaskgroup")373374 @click.group(cls=FlaskGroup, create_app=create_app)375 def cli(**params):376 pass377378 @cli.command()379 def test():380 click.echo(current_app.name)381Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 382why, one step back382 result = runner.invoke(cli, ["test"])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 383why, one step back383 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 384why, one step back384 assert result.output == "flaskgroup\n"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 385–386why, one step back385386Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 387why, one step back387@pytest.mark.parametrize("set_debug_flag", (True, False))Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
lines 388–390why, one step back388def test_flaskgroup_debug(runner, set_debug_flag):389 """Test FlaskGroup debug flag behavior."""390Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
line 391why, one step back391 def create_app():Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
lines 392–403why, one step back392 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))403Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 404why, one step back404 result = runner.invoke(cli, ["test"])Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
line 405why, one step back405 assert result.exit_code == 0Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 406why, one step back406 assert result.output == f"{not set_debug_flag}\n"Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
lines 407–408why, one step back407408Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 409–411why, one step back409def test_print_exceptions(runner):410 """Print the stacktrace if the CLI."""411Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
line 412why, one step back412 def create_app():Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 413–419why, one step back413 raise Exception("oh no")414 return Flask("flaskgroup")415416 @click.group(cls=FlaskGroup, create_app=create_app)417 def cli(**params):418 pass419Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 420why, one step back420 result = runner.invoke(cli, ["--help"])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 421why, one step back421 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 422–423why, one step back422 assert "Exception: oh no" in result.output423 assert "Traceback" in result.outputMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 424–428why, one step back424425426class TestRoutes:427 @pytest.fixture428 def invoke(self, runner):Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
line 429why, one step back429 def create_app():Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 430–432why, one step back430 app = Flask(__name__)431 app.testing = True432Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 433why, one step back433 @app.route("/get_post/<int:x>/<int:y>", methods=["GET", "POST"])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 434–436why, one step back434 def yyy_get_post(x, y):435 pass436Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 437why, one step back437 @app.route("/zzz_post", methods=["POST"])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 438–445why, one step back438 def aaa_post():439 pass440441 return app442443 cli = FlaskGroup(create_app=create_app)444 return partial(runner.invoke, cli)445Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
lines 446–447why, one step back446 @pytest.fixture447 def invoke_no_routes(self, runner):Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40
line 448why, one step back448 def create_app():Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
lines 449–456why, one step back449 app = Flask(__name__, static_folder=None)450 app.testing = True451452 return app453454 cli = FlaskGroup(create_app=create_app)455 return partial(runner.invoke, cli)456Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 457–460why, one step back457 def expect_order(self, order, output):458 # skip the header and match the start of each row459 for expect, line in zip(order, output.splitlines()[2:]):460 # do this instead of startswith for nicer pytest outputMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 461why, one step back461 assert line[: len(expect)] == expectMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 462–463why, one step back462463 def test_simple(self, invoke):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 464why, one step back464 result = invoke(["routes"])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 465why, one step back465 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 466why, one step back466 self.expect_order(["aaa_post", "static", "yyy_get_post"], result.output)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 467–468why, one step back467468 def test_sort(self, invoke):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 469–470why, one step back469 default_output = invoke(["routes"]).output470 endpoint_output = invoke(["routes", "-s", "endpoint"]).outputMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 471–472why, one step back471 assert default_output == endpoint_output472 self.expect_order(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 473–474why, one step back473 ["static", "yyy_get_post", "aaa_post"],474 invoke(["routes", "-s", "methods"]).output,Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 475–476why, one step back475 )476 self.expect_order(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 477–478why, one step back477 ["yyy_get_post", "static", "aaa_post"],478 invoke(["routes", "-s", "rule"]).output,Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 479–480why, one step back479 )480 self.expect_order(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 481–482why, one step back481 ["aaa_post", "yyy_get_post", "static"],482 invoke(["routes", "-s", "match"]).output,Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 483–485why, one step back483 )484485 def test_all_methods(self, invoke):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 486–489why, one step back486 output = invoke(["routes"]).output487 assert "GET, HEAD, OPTIONS, POST" not in output488 output = invoke(["routes", "--all-methods"]).output489 assert "GET, HEAD, OPTIONS, POST" in outputMerge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
lines 490–491why, one step back490491 def test_no_routes(self, invoke_no_routes):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 492why, one step back492 result = invoke_no_routes(["routes"])Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
line 493why, one step back493 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 494why, one step back494 assert "No routes were registered." in result.outputMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 495–496why, one step back495496Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 497why, one step back497need_dotenv = pytest.mark.skipif(dotenv is None, reason="dotenv is not installed")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 498–502why, one step back498499500@need_dotenv501def test_load_dotenv(monkeypatch):502 # can't use monkeypatch.delitem since the keys don't exist yetMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 503why, one step back503 for item in ("FOO", "BAR", "SPAM"):Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 504–505why, one step back504 monkeypatch._setitem.append((os.environ, item, notset))505Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 506–507why, one step back506 monkeypatch.setenv("EGGS", "3")507 monkeypatch.chdir(os.path.join(test_path, "cliapp", "inner1"))Merge pull request #2939 from sharmaadarsh563/2937-correct-load_dotenv-return-valueDavid Lordbefore adoptiond3e1fed
line 508why, one step back508 assert load_dotenv()Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 509–510why, one step back509 assert os.getcwd() == test_path510 # .flaskenv doesn't overwrite .envMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 511why, one step back511 assert os.environ["FOO"] == "env"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 512why, one step back512 # set only in .flaskenvMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 513why, one step back513 assert os.environ["BAR"] == "bar"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 514why, one step back514 # set only in .envMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 515why, one step back515 assert os.environ["SPAM"] == "1"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 516why, one step back516 # set manually, files don't overwriteMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 517why, one step back517 assert os.environ["EGGS"] == "3"Merge pull request #2939 from sharmaadarsh563/2937-correct-load_dotenv-return-valueDavid Lordbefore adoptiond3e1fed
lines 518–519why, one step back518519 # Non existent file should not loadMerge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 520why, one step back520 assert not load_dotenv("non-existent-file")Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 521–524why, one step back521522523@need_dotenv524def test_dotenv_path(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 525why, one step back525 for item in ("FOO", "BAR", "EGGS"):Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 526–528why, one step back526 monkeypatch._setitem.append((os.environ, item, notset))527528 cwd = os.getcwd()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 529why, one step back529 load_dotenv(os.path.join(test_path, ".flaskenv"))Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 530why, one step back530 assert os.getcwd() == cwdMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 531why, one step back531 assert "FOO" in os.environMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 532–534why, one step back532533534def test_dotenv_optional(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 535why, one step back535 monkeypatch.setattr("flask.cli.dotenv", None)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 536–537why, one step back536 monkeypatch.chdir(test_path)537 load_dotenv()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 538why, one step back538 assert "FOO" not in os.environMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 539–540why, one step back539540Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
lines 541–543why, one step back541@need_dotenv542def test_disable_dotenv_from_env(monkeypatch, runner):543 monkeypatch.chdir(test_path)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 544why, one step back544 monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
line 545why, one step back545 runner.invoke(FlaskGroup())Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 546why, one step back546 assert "FOO" not in os.environMerge branch '1.0-maintenance'David Lordbefore adoption1fa9185
lines 547–548why, one step back547548Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 549–551why, one step back549def test_run_cert_path():550 # no key551 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 552why, one step back552 run_command.make_context("run", ["--cert", __file__])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 553–555why, one step back553554 # no cert555 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 556why, one step back556 run_command.make_context("run", ["--key", __file__])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 557why, one step back557Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 558–559why, one step back558 ctx = run_command.make_context("run", ["--cert", __file__, "--key", __file__])559 assert ctx.params["cert"] == (__file__, __file__)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 560–562why, one step back560561562def test_run_cert_adhoc(monkeypatch):Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e
line 563why, one step back563 monkeypatch.setitem(sys.modules, "cryptography", None)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 564why, one step back564Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e
line 565why, one step back565 # cryptography not installedMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 566why, one step back566 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 567why, one step back567 run_command.make_context("run", ["--cert", "adhoc"])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 568why, one step back568Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e
lines 569–570why, one step back569 # cryptography installed570 monkeypatch.setitem(sys.modules, "cryptography", types.ModuleType("cryptography"))Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 571–572why, one step back571 ctx = run_command.make_context("run", ["--cert", "adhoc"])572 assert ctx.params["cert"] == "adhoc"Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 573–575why, one step back573574 # no key with adhoc575 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 576why, one step back576 run_command.make_context("run", ["--cert", "adhoc", "--key", __file__])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 577–579why, one step back577578579def test_run_cert_import(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 580why, one step back580 monkeypatch.setitem(sys.modules, "not_here", None)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 581–583why, one step back581582 # ImportError583 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 584why, one step back584 run_command.make_context("run", ["--cert", "not_here"])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 585why, one step back585Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 586–587why, one step back586 with pytest.raises(click.BadParameter):587 run_command.make_context("run", ["--cert", "flask"])Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 588–589why, one step back588589 # SSLContextMerge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 590why, one step back590 ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)Merge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
line 591why, one step back591Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 592–594why, one step back592 monkeypatch.setitem(sys.modules, "ssl_context", ssl_context)593 ctx = run_command.make_context("run", ["--cert", "ssl_context"])594 assert ctx.params["cert"] is ssl_contextMerge pull request #2717 from filipefilardi/masterDavid Lordbefore adoption0123e65
lines 595–597why, one step back595596 # no --key with SSLContext597 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 598why, one step back598 run_command.make_context("run", ["--cert", "ssl_context", "--key", __file__])Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606
lines 599–600why, one step back599600Merge pull request #3242 from cslecrone/3211-ssl-importDavid Lordbefore adoption13b689b
lines 601–606why, one step back601def test_run_cert_no_ssl(monkeypatch):602 monkeypatch.setattr("flask.cli.ssl", None)603 with pytest.raises(click.BadParameter):604 run_command.make_context("run", ["--cert", "not_here"])605606Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606
lines 607–647why, one step back607def test_cli_blueprints(app):608 """Test blueprint commands register correctly to the application"""609 custom = Blueprint("custom", __name__, cli_group="customized")610 nested = Blueprint("nested", __name__)611 merged = Blueprint("merged", __name__, cli_group=None)612 late = Blueprint("late", __name__)613614 @custom.cli.command("custom")615 def custom_command():616 click.echo("custom_result")617618 @nested.cli.command("nested")619 def nested_command():620 click.echo("nested_result")621622 @merged.cli.command("merged")623 def merged_command():624 click.echo("merged_result")625626 @late.cli.command("late")627 def late_command():628 click.echo("late_result")629630 app.register_blueprint(custom)631 app.register_blueprint(nested)632 app.register_blueprint(merged)633 app.register_blueprint(late, cli_group="late_registration")634635 app_runner = app.test_cli_runner()636637 result = app_runner.invoke(args=["customized", "custom"])638 assert "custom_result" in result.output639640 result = app_runner.invoke(args=["nested", "nested"])641 assert "nested_result" in result.output642643 result = app_runner.invoke(args=["merged"])644 assert "merged_result" in result.output645646 result = app_runner.invoke(args=["late_registration", "late"])647 assert "late_result" in result.outputMerge pull request #3236 from lordmauve/no-cligroup-emptyDavid Lordbefore adoption91e53da
lines 648–655why, one step back648649650def test_cli_empty(app):651 """If a Blueprint's CLI group is empty, do not register it."""652 bp = Blueprint("blue", __name__, cli_group="blue")653 app.register_blueprint(bp)654655 result = app.test_cli_runner().invoke(args=["blue", "--help"])Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 656why, one step back656 assert result.exit_code == 2, f"Unexpected success:\n\n{result.output}"