test_cli.py
This file
Path
tests/test_cli.py
652 lines · 18.5 KiB · Python
Last changed by
remove unused module docstringsDavid Lordbefore adoptionf2f027d
History of this fileTake it
The walk stopped after 200 commits: lines older than 5fba092 point at it.
Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 69–70why, one step back6970 assert isinstance(find_best_app(script_info, Module), Flask)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 71why, one step back71 assert find_best_app(script_info, Module).name == "appname"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 72–75why, one step back7273 class Module:74 @staticmethod75 def create_app(foo):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 76why, one step back76 return Flask("appname")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 77–78why, one step back7778 assert isinstance(find_best_app(script_info, Module), Flask)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 79why, one step back79 assert find_best_app(script_info, Module).name == "appname"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 80–83why, one step back8081 class Module:82 @staticmethod83 def create_app(foo=None, script_info=None):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 84why, one step back84 return Flask("appname")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 85–86why, one step back8586 assert isinstance(find_best_app(script_info, Module), Flask)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 87why, one step back87 assert find_best_app(script_info, Module).name == "appname"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 88–91why, one step back8889 class Module:90 @staticmethod91 def make_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 92why, one step back92 return Flask("appname")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 93–94why, one step back9394 assert isinstance(find_best_app(script_info, Module), Flask)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 95why, one step back95 assert find_best_app(script_info, Module).name == "appname"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 96–97why, one step back9697 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 98why, one step back98 myapp = Flask("appname1")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 99–101why, one step back99100 @staticmethod101 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 102why, one step back102 return Flask("appname2")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 103–106why, one step back103104 assert find_best_app(script_info, Module) == Module.myapp105106 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 107why, one step back107 myapp = Flask("appname1")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 108–110why, one step back108109 @staticmethod110 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 111why, one step back111 return Flask("appname2")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 112–120why, one step back112113 assert find_best_app(script_info, Module) == Module.myapp114115 class Module:116 pass117118 pytest.raises(NoAppException, find_best_app, script_info, Module)119120 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 121–122why, one step back121 myapp1 = Flask("appname1")122 myapp2 = Flask("appname2")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 123–128why, one step back123124 pytest.raises(NoAppException, find_best_app, script_info, Module)125126 class Module:127 @staticmethod128 def create_app(foo, bar):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 129why, one step back129 return Flask("appname2")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 130–135why, one step back130131 pytest.raises(NoAppException, find_best_app, script_info, Module)132133 class Module:134 @staticmethod135 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 136why, one step back136 raise TypeError("bad bad factory!")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 137–140why, one step back137138 pytest.raises(TypeError, find_best_app, script_info, Module)139140Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 141–142why, one step back141@pytest.mark.parametrize(142 "value,path,result",Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 143why, one step back143 (Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 144–168why, one step back144 ("test", cwd, "test"),145 ("test.py", cwd, "test"),146 ("a/test", os.path.join(cwd, "a"), "test"),147 ("test/__init__.py", cwd, "test"),148 ("test/__init__", cwd, "test"),149 # nested package150 (151 os.path.join(test_path, "cliapp", "inner1", "__init__"),152 test_path,153 "cliapp.inner1",154 ),155 (156 os.path.join(test_path, "cliapp", "inner1", "inner2"),157 test_path,158 "cliapp.inner1.inner2",159 ),160 # dotted name161 ("test.a.b", cwd, "test.a.b"),162 (os.path.join(test_path, "cliapp.app"), test_path, "cliapp.app"),163 # not a Python file, will be caught during import164 (165 os.path.join(test_path, "cliapp", "message.txt"),166 test_path,167 "cliapp.message.txt",168 ),Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 169why, one step back169 ),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 170why, one step back170)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 171–189why, one step back171def test_prepare_import(request, value, path, result):172 """Expect the correct path to be set and the correct import and app names173 to be returned.174175 :func:`prepare_exec_for_file` has a side effect where the parent directory176 of the given import is added to :data:`sys.path`. This is reset after the177 test runs.178 """179 original_path = sys.path[:]180181 def reset_path():182 sys.path[:] = original_path183184 request.addfinalizer(reset_path)185186 assert prepare_import(value) == result187 assert sys.path[0] == path188189Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 190–207why, one step back190@pytest.mark.parametrize(191 "iname,aname,result",192 (193 ("cliapp.app", None, "testapp"),194 ("cliapp.app", "testapp", "testapp"),195 ("cliapp.factory", None, "app"),196 ("cliapp.factory", "create_app", "app"),197 ("cliapp.factory", "create_app()", "app"),198 # no script_info199 ("cliapp.factory", 'create_app2("foo", "bar")', "app2_foo_bar"),200 # trailing comma space201 ("cliapp.factory", 'create_app2("foo", "bar", )', "app2_foo_bar"),202 # takes script_info203 ("cliapp.factory", 'create_app3("foo")', "app3_foo_spam"),204 # strip whitespace205 ("cliapp.factory", " create_app () ", "app"),206 ),207)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 208–209why, one step back208def test_locate_app(test_apps, iname, aname, result):209 info = ScriptInfo()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 210why, one step back210 info.data["test"] = "spam"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 211–213why, one step back211 assert locate_app(info, iname, aname).name == result212213Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 214–231why, one step back214@pytest.mark.parametrize(215 "iname,aname",216 (217 ("notanapp.py", None),218 ("cliapp/app", None),219 ("cliapp.app", "notanapp"),220 # not enough arguments221 ("cliapp.factory", 'create_app2("foo")'),222 # invalid identifier223 ("cliapp.factory", "create_app("),224 # no app returned225 ("cliapp.factory", "no_app"),226 # nested import error227 ("cliapp.importerrorapp", None),228 # not a Python file229 ("cliapp.message.txt", None),230 ),231)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 232–240why, one step back232def test_locate_app_raises(test_apps, iname, aname):233 info = ScriptInfo()234235 with pytest.raises(NoAppException):236 locate_app(info, iname, aname)237238239def test_locate_app_suppress_raise():240 info = ScriptInfo()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 241why, one step back241 app = locate_app(info, "notanapp.py", None, raise_if_not_found=False)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 242–245why, one step back242 assert app is None243244 # only direct import error is suppressed245 with pytest.raises(NoAppException):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 246why, one step back246 locate_app(info, "cliapp.importerrorapp", None, raise_if_not_found=False)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 247–249why, one step back247248249def test_get_version(test_apps, capsys):Merge branch '1.0-maintenance'David Lordbefore adoption4f3dbb3
lines 250–252why, one step back250 from flask import __version__ as flask_version251 from werkzeug import __version__ as werkzeug_version252 from platform import python_versionMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 253why, one step back253Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 254why, one step back254 class MockCtx:Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 255–257why, one step back255 resilient_parsing = False256 color = None257Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 258–259why, one step back258 def exit(self):259 returnMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 260–263why, one step back260261 ctx = MockCtx()262 get_version(ctx, None, "test")263 out, err = capsys.readouterr()Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 264–266why, one step back264 assert f"Python {python_version()}" in out265 assert f"Flask {flask_version}" in out266 assert f"Werkzeug {werkzeug_version}" in outMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 267–271why, one step back267268269def test_scriptinfo(test_apps, monkeypatch):270 """Test of ScriptInfo."""271 obj = ScriptInfo(app_import_path="cliapp.app:testapp")Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
lines 272–274why, one step back272 app = obj.load_app()273 assert app.name == "testapp"274 assert obj.load_app() is appMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 275why, one step back275Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 276why, one step back276 # import app with module's absolute pathMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 277–279why, one step back277 cli_app_path = os.path.abspath(278 os.path.join(os.path.dirname(__file__), "test_apps", "cliapp", "app.py")279 )Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
lines 280–281why, one step back280 obj = ScriptInfo(app_import_path=cli_app_path)281 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 282why, one step back282 assert app.name == "testapp"Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 283why, one step back283 assert obj.load_app() is appMerge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 284why, one step back284 obj = ScriptInfo(app_import_path=f"{cli_app_path}:testapp")Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 285why, one step back285 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
lines 287–288why, one step back287 assert obj.load_app() is app288Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 289–294why, one step back289 def create_app(info):290 return Flask("createapp")291292 obj = ScriptInfo(create_app=create_app)293 app = obj.load_app()294 assert app.name == "createapp"Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 295why, one step back295 assert obj.load_app() is appMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 296–300why, one step back296297 obj = ScriptInfo()298 pytest.raises(NoAppException, obj.load_app)299300 # import app from wsgi.py in current directoryMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 301–305why, one step back301 monkeypatch.chdir(302 os.path.abspath(303 os.path.join(os.path.dirname(__file__), "test_apps", "helloworld")304 )305 )Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 306–307why, one step back306 obj = ScriptInfo()307 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 308why, one step back308 assert app.name == "hello"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 309–310why, one step back309310 # import app from app.py in current directoryMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 311–313why, one step back311 monkeypatch.chdir(312 os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps", "cliapp"))313 )Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 314–315why, one step back314 obj = ScriptInfo()315 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 316why, one step back316 assert app.name == "testapp"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 317–330why, one step back317318319def test_with_appcontext(runner):320 """Test of with_appcontext."""321322 @click.command()323 @with_appcontext324 def testcmd():325 click.echo(current_app.name)326327 obj = ScriptInfo(create_app=lambda info: Flask("testapp"))328329 result = runner.invoke(testcmd, obj=obj)330 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 331why, one step back331 assert result.output == "testapp\n"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 332–354why, one step back332333334def test_appgroup(runner):335 """Test of with_appcontext."""336337 @click.group(cls=AppGroup)338 def cli():339 pass340341 @cli.command(with_appcontext=True)342 def test():343 click.echo(current_app.name)344345 @cli.group()346 def subgroup():347 pass348349 @subgroup.command(with_appcontext=True)350 def test2():351 click.echo(current_app.name)352353 obj = ScriptInfo(create_app=lambda info: Flask("testappgroup"))354Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 355why, one step back355 result = runner.invoke(cli, ["test"], obj=obj)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 356why, one step back356 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 357why, one step back357 assert result.output == "testappgroup\n"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 358why, one step back358Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 359why, one step back359 result = runner.invoke(cli, ["subgroup", "test2"], obj=obj)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 362–377why, one step back362363364def test_flaskgroup(runner):365 """Test FlaskGroup."""366367 def create_app(info):368 return Flask("flaskgroup")369370 @click.group(cls=FlaskGroup, create_app=create_app)371 def cli(**params):372 pass373374 @cli.command()375 def test():376 click.echo(current_app.name)377Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 378why, one step back378 result = runner.invoke(cli, ["test"])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 379why, one step back379 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 380why, one step back380 assert result.output == "flaskgroup\n"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 381–382why, one step back381382Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 383why, one step back383@pytest.mark.parametrize("set_debug_flag", (True, False))Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
lines 384–399why, one step back384def test_flaskgroup_debug(runner, set_debug_flag):385 """Test FlaskGroup debug flag behavior."""386387 def create_app(info):388 app = Flask("flaskgroup")389 app.debug = True390 return app391392 @click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)393 def cli(**params):394 pass395396 @cli.command()397 def test():398 click.echo(str(current_app.debug))399Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 400why, one step back400 result = runner.invoke(cli, ["test"])Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
line 401why, one step back401 assert result.exit_code == 0Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 402why, one step back402 assert result.output == f"{not set_debug_flag}\n"Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
lines 403–404why, one step back403404Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 405–415why, one step back405def test_print_exceptions(runner):406 """Print the stacktrace if the CLI."""407408 def create_app(info):409 raise Exception("oh no")410 return Flask("flaskgroup")411412 @click.group(cls=FlaskGroup, create_app=create_app)413 def cli(**params):414 pass415Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 416why, one step back416 result = runner.invoke(cli, ["--help"])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 417why, one step back417 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 418–419why, one step back418 assert "Exception: oh no" in result.output419 assert "Traceback" in result.outputMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 420–428why, one step back420421422class TestRoutes:423 @pytest.fixture424 def invoke(self, runner):425 def create_app(info):426 app = Flask(__name__)427 app.testing = True428Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 429why, one step back429 @app.route("/get_post/<int:x>/<int:y>", methods=["GET", "POST"])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 430–432why, one step back430 def yyy_get_post(x, y):431 pass432Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 433why, one step back433 @app.route("/zzz_post", methods=["POST"])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 434–441why, one step back434 def aaa_post():435 pass436437 return app438439 cli = FlaskGroup(create_app=create_app)440 return partial(runner.invoke, cli)441Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
lines 442–452why, one step back442 @pytest.fixture443 def invoke_no_routes(self, runner):444 def create_app(info):445 app = Flask(__name__, static_folder=None)446 app.testing = True447448 return app449450 cli = FlaskGroup(create_app=create_app)451 return partial(runner.invoke, cli)452Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 453–456why, one step back453 def expect_order(self, order, output):454 # skip the header and match the start of each row455 for expect, line in zip(order, output.splitlines()[2:]):456 # do this instead of startswith for nicer pytest outputMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 457why, one step back457 assert line[: len(expect)] == expectMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 458–459why, one step back458459 def test_simple(self, invoke):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 460why, one step back460 result = invoke(["routes"])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 461why, one step back461 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 462why, one step back462 self.expect_order(["aaa_post", "static", "yyy_get_post"], result.output)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 463–464why, one step back463464 def test_sort(self, invoke):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 465–466why, one step back465 default_output = invoke(["routes"]).output466 endpoint_output = invoke(["routes", "-s", "endpoint"]).outputMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 467–468why, one step back467 assert default_output == endpoint_output468 self.expect_order(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 469–470why, one step back469 ["static", "yyy_get_post", "aaa_post"],470 invoke(["routes", "-s", "methods"]).output,Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 471–472why, one step back471 )472 self.expect_order(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 473–474why, one step back473 ["yyy_get_post", "static", "aaa_post"],474 invoke(["routes", "-s", "rule"]).output,Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
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 ["aaa_post", "yyy_get_post", "static"],478 invoke(["routes", "-s", "match"]).output,Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 479–481why, one step back479 )480481 def test_all_methods(self, invoke):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 482–485why, one step back482 output = invoke(["routes"]).output483 assert "GET, HEAD, OPTIONS, POST" not in output484 output = invoke(["routes", "--all-methods"]).output485 assert "GET, HEAD, OPTIONS, POST" in outputMerge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
lines 486–487why, one step back486487 def test_no_routes(self, invoke_no_routes):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 488why, one step back488 result = invoke_no_routes(["routes"])Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
line 489why, one step back489 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 490why, one step back490 assert "No routes were registered." in result.outputMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 491–492why, one step back491492Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 493why, one step back493need_dotenv = pytest.mark.skipif(dotenv is None, reason="dotenv is not installed")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 494–498why, one step back494495496@need_dotenv497def test_load_dotenv(monkeypatch):498 # can't use monkeypatch.delitem since the keys don't exist yetMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 499why, one step back499 for item in ("FOO", "BAR", "SPAM"):Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 500–501why, one step back500 monkeypatch._setitem.append((os.environ, item, notset))501Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 502–503why, one step back502 monkeypatch.setenv("EGGS", "3")503 monkeypatch.chdir(os.path.join(test_path, "cliapp", "inner1"))Merge pull request #2939 from sharmaadarsh563/2937-correct-load_dotenv-return-valueDavid Lordbefore adoptiond3e1fed
line 504why, one step back504 assert load_dotenv()Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 505–506why, one step back505 assert os.getcwd() == test_path506 # .flaskenv doesn't overwrite .envMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 507why, one step back507 assert os.environ["FOO"] == "env"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 508why, one step back508 # set only in .flaskenvMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 509why, one step back509 assert os.environ["BAR"] == "bar"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 510why, one step back510 # set only in .envMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 511why, one step back511 assert os.environ["SPAM"] == "1"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 512why, one step back512 # set manually, files don't overwriteMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 513why, one step back513 assert os.environ["EGGS"] == "3"Merge pull request #2939 from sharmaadarsh563/2937-correct-load_dotenv-return-valueDavid Lordbefore adoptiond3e1fed
lines 514–515why, one step back514515 # Non existent file should not loadMerge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 516why, one step back516 assert not load_dotenv("non-existent-file")Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 517–520why, one step back517518519@need_dotenv520def test_dotenv_path(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 521why, one step back521 for item in ("FOO", "BAR", "EGGS"):Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 522–524why, one step back522 monkeypatch._setitem.append((os.environ, item, notset))523524 cwd = os.getcwd()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 525why, one step back525 load_dotenv(os.path.join(test_path, ".flaskenv"))Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 526why, one step back526 assert os.getcwd() == cwdMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 527why, one step back527 assert "FOO" in os.environMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 528–530why, one step back528529530def test_dotenv_optional(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 531why, one step back531 monkeypatch.setattr("flask.cli.dotenv", None)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 532–533why, one step back532 monkeypatch.chdir(test_path)533 load_dotenv()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 534why, one step back534 assert "FOO" not in os.environMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 535–536why, one step back535536Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
lines 537–539why, one step back537@need_dotenv538def test_disable_dotenv_from_env(monkeypatch, runner):539 monkeypatch.chdir(test_path)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 540why, one step back540 monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
line 541why, one step back541 runner.invoke(FlaskGroup())Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 542why, one step back542 assert "FOO" not in os.environMerge branch '1.0-maintenance'David Lordbefore adoption1fa9185
lines 543–544why, one step back543544Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 545–547why, one step back545def test_run_cert_path():546 # no key547 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 548why, one step back548 run_command.make_context("run", ["--cert", __file__])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 549–551why, one step back549550 # no cert551 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", ["--key", __file__])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 553why, one step back553Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 554–555why, one step back554 ctx = run_command.make_context("run", ["--cert", __file__, "--key", __file__])555 assert ctx.params["cert"] == (__file__, __file__)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 556–558why, one step back556557558def test_run_cert_adhoc(monkeypatch):Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e
line 559why, one step back559 monkeypatch.setitem(sys.modules, "cryptography", None)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 560why, one step back560Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e
line 561why, one step back561 # cryptography not installedMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 562why, one step back562 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 563why, one step back563 run_command.make_context("run", ["--cert", "adhoc"])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 564why, one step back564Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e
lines 565–566why, one step back565 # cryptography installed566 monkeypatch.setitem(sys.modules, "cryptography", types.ModuleType("cryptography"))Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 567–568why, one step back567 ctx = run_command.make_context("run", ["--cert", "adhoc"])568 assert ctx.params["cert"] == "adhoc"Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 569–571why, one step back569570 # no key with adhoc571 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 572why, one step back572 run_command.make_context("run", ["--cert", "adhoc", "--key", __file__])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 573–575why, one step back573574575def test_run_cert_import(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 576why, one step back576 monkeypatch.setitem(sys.modules, "not_here", None)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 577–579why, one step back577578 # ImportError579 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 580why, one step back580 run_command.make_context("run", ["--cert", "not_here"])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 581why, one step back581Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 582–583why, one step back582 with pytest.raises(click.BadParameter):583 run_command.make_context("run", ["--cert", "flask"])Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 584–585why, one step back584585 # SSLContextMerge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 586why, one step back586 ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
line 587why, one step back587Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 588–590why, one step back588 monkeypatch.setitem(sys.modules, "ssl_context", ssl_context)589 ctx = run_command.make_context("run", ["--cert", "ssl_context"])590 assert ctx.params["cert"] is ssl_contextMerge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092
lines 591–593why, one step back591592 # no --key with SSLContext593 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 594why, one step back594 run_command.make_context("run", ["--cert", "ssl_context", "--key", __file__])Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606
lines 595–596why, one step back595596Merge pull request #3242 from cslecrone/3211-ssl-importDavid Lordbefore adoption13b689b
lines 597–602why, one step back597def test_run_cert_no_ssl(monkeypatch):598 monkeypatch.setattr("flask.cli.ssl", None)599 with pytest.raises(click.BadParameter):600 run_command.make_context("run", ["--cert", "not_here"])601602Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606
lines 603–643why, one step back603def test_cli_blueprints(app):604 """Test blueprint commands register correctly to the application"""605 custom = Blueprint("custom", __name__, cli_group="customized")606 nested = Blueprint("nested", __name__)607 merged = Blueprint("merged", __name__, cli_group=None)608 late = Blueprint("late", __name__)609610 @custom.cli.command("custom")611 def custom_command():612 click.echo("custom_result")613614 @nested.cli.command("nested")615 def nested_command():616 click.echo("nested_result")617618 @merged.cli.command("merged")619 def merged_command():620 click.echo("merged_result")621622 @late.cli.command("late")623 def late_command():624 click.echo("late_result")625626 app.register_blueprint(custom)627 app.register_blueprint(nested)628 app.register_blueprint(merged)629 app.register_blueprint(late, cli_group="late_registration")630631 app_runner = app.test_cli_runner()632633 result = app_runner.invoke(args=["customized", "custom"])634 assert "custom_result" in result.output635636 result = app_runner.invoke(args=["nested", "nested"])637 assert "nested_result" in result.output638639 result = app_runner.invoke(args=["merged"])640 assert "merged_result" in result.output641642 result = app_runner.invoke(args=["late_registration", "late"])643 assert "late_result" in result.outputMerge pull request #3236 from lordmauve/no-cligroup-emptyDavid Lordbefore adoption91e53da
lines 644–651why, one step back644645646def test_cli_empty(app):647 """If a Blueprint's CLI group is empty, do not register it."""648 bp = Blueprint("blue", __name__, cli_group="blue")649 app.register_blueprint(bp)650651 result = app.test_cli_runner().invoke(args=["blue", "--help"])Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 652why, one step back652 assert result.exit_code == 2, f"Unexpected success:\n\n{result.output}"