test_cli.py
This file
Path
tests/test_cli.py
667 lines · 18.8 KiB · Python
Last changed by
Merge branch '1.0.x'David Lordbefore adoption1351d0a
History of this fileTake it
The walk stopped after 200 commits: lines older than 0a10908 point at it.
Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 1–5why, one step back1# -*- coding: utf-8 -*-2"""3 tests.test_cli4 ~~~~~~~~~~~~~~5Merge branch '1.0.x'David Lordbefore adoption1351d0a
lines 6–7why, one step back6 :copyright: 2010 Pallets7 :license: BSD-3-ClauseAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 8why, one step back8"""Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c
lines 9–10why, one step back9# This file was part of Flask-CLI and was modified under the terms of10# its Revised BSD License. Copyright © 2015 CERN.Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 11–13why, one step back11from __future__ import absolute_import1213import osMerge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
line 14why, one step back14import sslAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 15why, one step back15import sysMerge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
line 16why, one step back16import typesAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 17–23why, one step back17from functools import partial1819import click20import pytest21from _pytest.monkeypatch import notset22from click.testing import CliRunner23Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
lines 24–38why, one step back24from flask import Blueprint25from flask import current_app26from flask import Flask27from flask.cli import AppGroup28from flask.cli import dotenv29from flask.cli import find_best_app30from flask.cli import FlaskGroup31from flask.cli import get_version32from flask.cli import load_dotenv33from flask.cli import locate_app34from flask.cli import NoAppException35from flask.cli import prepare_import36from flask.cli import run_command37from flask.cli import ScriptInfo38from flask.cli import with_appcontextAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 39–40why, one step back3940cwd = os.getcwd()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 41why, one step back41test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps"))Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 42–51why, one step back424344@pytest.fixture45def runner():46 return CliRunner()474849def test_cli_name(test_apps):50 """Make sure the CLI object's name is the app's name and not the app itself"""51 from cliapp.app import testappMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 52why, one step back52Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 53–56why, one step back53 assert testapp.cli.name == testapp.name545556def test_find_best_app(test_apps):Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 57why, one step back57 """Test if `find_best_app` behaves as expected with different combinations of input.""" # noqa: B950Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 58–60why, one step back58 script_info = ScriptInfo()5960 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 61why, one step back61 app = Flask("appname")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 62–65why, one step back6263 assert find_best_app(script_info, Module) == Module.app6465 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 66why, one step back66 application = Flask("appname")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 67–70why, one step back6768 assert find_best_app(script_info, Module) == Module.application6970 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 71why, one step back71 myapp = Flask("appname")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 72–77why, one step back7273 assert find_best_app(script_info, Module) == Module.myapp7475 class Module:76 @staticmethod77 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 78why, one step back78 return Flask("appname")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 79–80why, one step back7980 assert isinstance(find_best_app(script_info, Module), Flask)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 81why, one step back81 assert find_best_app(script_info, Module).name == "appname"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 82–85why, one step back8283 class Module:84 @staticmethod85 def create_app(foo):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 86why, one step back86 return Flask("appname")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 87–88why, one step back8788 assert isinstance(find_best_app(script_info, Module), Flask)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 89why, one step back89 assert find_best_app(script_info, Module).name == "appname"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 90–93why, one step back9091 class Module:92 @staticmethod93 def create_app(foo=None, script_info=None):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 94why, one step back94 return Flask("appname")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 95–96why, one step back9596 assert isinstance(find_best_app(script_info, Module), Flask)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 97why, one step back97 assert find_best_app(script_info, Module).name == "appname"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 98–101why, one step back9899 class Module:100 @staticmethod101 def make_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 102why, one step back102 return Flask("appname")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 103–104why, one step back103104 assert isinstance(find_best_app(script_info, Module), Flask)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 105why, one step back105 assert find_best_app(script_info, Module).name == "appname"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 106–107why, one step back106107 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 108why, one step back108 myapp = Flask("appname1")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 109–111why, one step back109110 @staticmethod111 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 112why, one step back112 return Flask("appname2")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 113–116why, one step back113114 assert find_best_app(script_info, Module) == Module.myapp115116 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 117why, one step back117 myapp = Flask("appname1")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 118–120why, one step back118119 @staticmethod120 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 121why, one step back121 return Flask("appname2")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 122–130why, one step back122123 assert find_best_app(script_info, Module) == Module.myapp124125 class Module:126 pass127128 pytest.raises(NoAppException, find_best_app, script_info, Module)129130 class Module:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 131–132why, one step back131 myapp1 = Flask("appname1")132 myapp2 = Flask("appname2")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 133–138why, one step back133134 pytest.raises(NoAppException, find_best_app, script_info, Module)135136 class Module:137 @staticmethod138 def create_app(foo, bar):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 139why, one step back139 return Flask("appname2")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 140–142why, one step back140141 pytest.raises(NoAppException, find_best_app, script_info, Module)142Merge pull request #2530 from pallets/feature/factory-detectionDavid Lordbefore adoption03a2996
lines 143–145why, one step back143 class Module:144 @staticmethod145 def create_app():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 146why, one step back146 raise TypeError("bad bad factory!")Merge pull request #2530 from pallets/feature/factory-detectionDavid Lordbefore adoption03a2996
lines 147–149why, one step back147148 pytest.raises(TypeError, find_best_app, script_info, Module)149Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 150why, one step back150Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 151–152why, one step back151@pytest.mark.parametrize(152 "value,path,result",Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 153why, one step back153 (Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 154–178why, one step back154 ("test", cwd, "test"),155 ("test.py", cwd, "test"),156 ("a/test", os.path.join(cwd, "a"), "test"),157 ("test/__init__.py", cwd, "test"),158 ("test/__init__", cwd, "test"),159 # nested package160 (161 os.path.join(test_path, "cliapp", "inner1", "__init__"),162 test_path,163 "cliapp.inner1",164 ),165 (166 os.path.join(test_path, "cliapp", "inner1", "inner2"),167 test_path,168 "cliapp.inner1.inner2",169 ),170 # dotted name171 ("test.a.b", cwd, "test.a.b"),172 (os.path.join(test_path, "cliapp.app"), test_path, "cliapp.app"),173 # not a Python file, will be caught during import174 (175 os.path.join(test_path, "cliapp", "message.txt"),176 test_path,177 "cliapp.message.txt",178 ),Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 179why, one step back179 ),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 180why, one step back180)Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 181–199why, one step back181def test_prepare_import(request, value, path, result):182 """Expect the correct path to be set and the correct import and app names183 to be returned.184185 :func:`prepare_exec_for_file` has a side effect where the parent directory186 of the given import is added to :data:`sys.path`. This is reset after the187 test runs.188 """189 original_path = sys.path[:]190191 def reset_path():192 sys.path[:] = original_path193194 request.addfinalizer(reset_path)195196 assert prepare_import(value) == result197 assert sys.path[0] == path198199Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 200–217why, one step back200@pytest.mark.parametrize(201 "iname,aname,result",202 (203 ("cliapp.app", None, "testapp"),204 ("cliapp.app", "testapp", "testapp"),205 ("cliapp.factory", None, "app"),206 ("cliapp.factory", "create_app", "app"),207 ("cliapp.factory", "create_app()", "app"),208 # no script_info209 ("cliapp.factory", 'create_app2("foo", "bar")', "app2_foo_bar"),210 # trailing comma space211 ("cliapp.factory", 'create_app2("foo", "bar", )', "app2_foo_bar"),212 # takes script_info213 ("cliapp.factory", 'create_app3("foo")', "app3_foo_spam"),214 # strip whitespace215 ("cliapp.factory", " create_app () ", "app"),216 ),217)Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 218–219why, one step back218def test_locate_app(test_apps, iname, aname, result):219 info = ScriptInfo()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 220why, one step back220 info.data["test"] = "spam"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 221–223why, one step back221 assert locate_app(info, iname, aname).name == result222223Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 224–241why, one step back224@pytest.mark.parametrize(225 "iname,aname",226 (227 ("notanapp.py", None),228 ("cliapp/app", None),229 ("cliapp.app", "notanapp"),230 # not enough arguments231 ("cliapp.factory", 'create_app2("foo")'),232 # invalid identifier233 ("cliapp.factory", "create_app("),234 # no app returned235 ("cliapp.factory", "no_app"),236 # nested import error237 ("cliapp.importerrorapp", None),238 # not a Python file239 ("cliapp.message.txt", None),240 ),241)Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 242–250why, one step back242def test_locate_app_raises(test_apps, iname, aname):243 info = ScriptInfo()244245 with pytest.raises(NoAppException):246 locate_app(info, iname, aname)247248249def test_locate_app_suppress_raise():250 info = ScriptInfo()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 251why, one step back251 app = locate_app(info, "notanapp.py", None, raise_if_not_found=False)Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 252–255why, one step back252 assert app is None253254 # only direct import error is suppressed255 with pytest.raises(NoAppException):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 256why, one step back256 locate_app(info, "cliapp.importerrorapp", None, raise_if_not_found=False)Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 257–259why, one step back257258259def test_get_version(test_apps, capsys):Merge branch '1.0-maintenance'David Lordbefore adoption4f3dbb3
lines 260–262why, one step back260 from flask import __version__ as flask_version261 from werkzeug import __version__ as werkzeug_version262 from platform import python_versionAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 263–267why, one step back263264 class MockCtx(object):265 resilient_parsing = False266 color = None267Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 268–269why, one step back268 def exit(self):269 returnAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 270–273why, one step back270271 ctx = MockCtx()272 get_version(ctx, None, "test")273 out, err = capsys.readouterr()Merge branch '1.0-maintenance'David Lordbefore adoption4f3dbb3
lines 274–276why, one step back274 assert "Python " + python_version() in out275 assert "Flask " + flask_version in out276 assert "Werkzeug " + werkzeug_version in outAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 277–281why, one step back277278279def test_scriptinfo(test_apps, monkeypatch):280 """Test of ScriptInfo."""281 obj = ScriptInfo(app_import_path="cliapp.app:testapp")Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
lines 282–284why, one step back282 app = obj.load_app()283 assert app.name == "testapp"284 assert obj.load_app() is appAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 285why, one step back285Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 286why, one step back286 # import app with module's absolute pathMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 287–289why, one step back287 cli_app_path = os.path.abspath(288 os.path.join(os.path.dirname(__file__), "test_apps", "cliapp", "app.py")289 )Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
lines 290–291why, one step back290 obj = ScriptInfo(app_import_path=cli_app_path)291 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 292why, one step back292 assert app.name == "testapp"Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 293why, one step back293 assert obj.load_app() is appMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 294why, one step back294 obj = ScriptInfo(app_import_path=cli_app_path + ":testapp")Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 295why, one step back295 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 296why, one step back296 assert app.name == "testapp"Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
lines 297–298why, one step back297 assert obj.load_app() is app298Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 299–304why, one step back299 def create_app(info):300 return Flask("createapp")301302 obj = ScriptInfo(create_app=create_app)303 app = obj.load_app()304 assert app.name == "createapp"Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4
line 305why, one step back305 assert obj.load_app() is appAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 306–310why, one step back306307 obj = ScriptInfo()308 pytest.raises(NoAppException, obj.load_app)309310 # import app from wsgi.py in current directoryMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 311–315why, one step back311 monkeypatch.chdir(312 os.path.abspath(313 os.path.join(os.path.dirname(__file__), "test_apps", "helloworld")314 )315 )Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 316–317why, one step back316 obj = ScriptInfo()317 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 318why, one step back318 assert app.name == "hello"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 319–320why, one step back319320 # import app from app.py in current directoryMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 321–323why, one step back321 monkeypatch.chdir(322 os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps", "cliapp"))323 )Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 324–325why, one step back324 obj = ScriptInfo()325 app = obj.load_app()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 326why, one step back326 assert app.name == "testapp"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 327–340why, one step back327328329def test_with_appcontext(runner):330 """Test of with_appcontext."""331332 @click.command()333 @with_appcontext334 def testcmd():335 click.echo(current_app.name)336337 obj = ScriptInfo(create_app=lambda info: Flask("testapp"))338339 result = runner.invoke(testcmd, obj=obj)340 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 341why, one step back341 assert result.output == "testapp\n"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 342–364why, one step back342343344def test_appgroup(runner):345 """Test of with_appcontext."""346347 @click.group(cls=AppGroup)348 def cli():349 pass350351 @cli.command(with_appcontext=True)352 def test():353 click.echo(current_app.name)354355 @cli.group()356 def subgroup():357 pass358359 @subgroup.command(with_appcontext=True)360 def test2():361 click.echo(current_app.name)362363 obj = ScriptInfo(create_app=lambda info: Flask("testappgroup"))364Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 365why, one step back365 result = runner.invoke(cli, ["test"], obj=obj)Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 366why, one step back366 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 367why, one step back367 assert result.output == "testappgroup\n"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 368why, one step back368Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 369why, one step back369 result = runner.invoke(cli, ["subgroup", "test2"], obj=obj)Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 370why, one step back370 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 371why, one step back371 assert result.output == "testappgroup\n"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 372–387why, one step back372373374def test_flaskgroup(runner):375 """Test FlaskGroup."""376377 def create_app(info):378 return Flask("flaskgroup")379380 @click.group(cls=FlaskGroup, create_app=create_app)381 def cli(**params):382 pass383384 @cli.command()385 def test():386 click.echo(current_app.name)387Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 388why, one step back388 result = runner.invoke(cli, ["test"])Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 389why, one step back389 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 390why, one step back390 assert result.output == "flaskgroup\n"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 391–392why, one step back391392Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 393why, one step back393@pytest.mark.parametrize("set_debug_flag", (True, False))Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
lines 394–409why, one step back394def test_flaskgroup_debug(runner, set_debug_flag):395 """Test FlaskGroup debug flag behavior."""396397 def create_app(info):398 app = Flask("flaskgroup")399 app.debug = True400 return app401402 @click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)403 def cli(**params):404 pass405406 @cli.command()407 def test():408 click.echo(str(current_app.debug))409Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 410why, one step back410 result = runner.invoke(cli, ["test"])Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
line 411why, one step back411 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 412why, one step back412 assert result.output == "%s\n" % str(not set_debug_flag)Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
lines 413–414why, one step back413414Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 415–425why, one step back415def test_print_exceptions(runner):416 """Print the stacktrace if the CLI."""417418 def create_app(info):419 raise Exception("oh no")420 return Flask("flaskgroup")421422 @click.group(cls=FlaskGroup, create_app=create_app)423 def cli(**params):424 pass425Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 426why, one step back426 result = runner.invoke(cli, ["--help"])Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 427why, one step back427 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 428–429why, one step back428 assert "Exception: oh no" in result.output429 assert "Traceback" in result.outputAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 430–438why, one step back430431432class TestRoutes:433 @pytest.fixture434 def invoke(self, runner):435 def create_app(info):436 app = Flask(__name__)437 app.testing = True438Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 439why, one step back439 @app.route("/get_post/<int:x>/<int:y>", methods=["GET", "POST"])Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 440–442why, one step back440 def yyy_get_post(x, y):441 pass442Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 443why, one step back443 @app.route("/zzz_post", methods=["POST"])Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 444–451why, one step back444 def aaa_post():445 pass446447 return app448449 cli = FlaskGroup(create_app=create_app)450 return partial(runner.invoke, cli)451Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
lines 452–462why, one step back452 @pytest.fixture453 def invoke_no_routes(self, runner):454 def create_app(info):455 app = Flask(__name__, static_folder=None)456 app.testing = True457458 return app459460 cli = FlaskGroup(create_app=create_app)461 return partial(runner.invoke, cli)462Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 463–466why, one step back463 def expect_order(self, order, output):464 # skip the header and match the start of each row465 for expect, line in zip(order, output.splitlines()[2:]):466 # do this instead of startswith for nicer pytest outputMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 467why, one step back467 assert line[: len(expect)] == expectAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 468–469why, one step back468469 def test_simple(self, invoke):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 470why, one step back470 result = invoke(["routes"])Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 471why, one step back471 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 472why, one step back472 self.expect_order(["aaa_post", "static", "yyy_get_post"], result.output)Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 473–474why, one step back473474 def test_sort(self, invoke):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 475–476why, one step back475 default_output = invoke(["routes"]).output476 endpoint_output = invoke(["routes", "-s", "endpoint"]).outputAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 477–478why, one step back477 assert default_output == endpoint_output478 self.expect_order(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 479–480why, one step back479 ["static", "yyy_get_post", "aaa_post"],480 invoke(["routes", "-s", "methods"]).output,Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 481–482why, one step back481 )482 self.expect_order(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 483–484why, one step back483 ["yyy_get_post", "static", "aaa_post"],484 invoke(["routes", "-s", "rule"]).output,Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 485–486why, one step back485 )486 self.expect_order(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 487–488why, one step back487 ["aaa_post", "yyy_get_post", "static"],488 invoke(["routes", "-s", "match"]).output,Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 489–491why, one step back489 )490491 def test_all_methods(self, invoke):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 492–495why, one step back492 output = invoke(["routes"]).output493 assert "GET, HEAD, OPTIONS, POST" not in output494 output = invoke(["routes", "--all-methods"]).output495 assert "GET, HEAD, OPTIONS, POST" in outputMerge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
lines 496–497why, one step back496497 def test_no_routes(self, invoke_no_routes):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 498why, one step back498 result = invoke_no_routes(["routes"])Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75
line 499why, one step back499 assert result.exit_code == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 500why, one step back500 assert "No routes were registered." in result.outputAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 501–502why, one step back501502Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 503why, one step back503need_dotenv = pytest.mark.skipif(dotenv is None, reason="dotenv is not installed")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 504–508why, one step back504505506@need_dotenv507def test_load_dotenv(monkeypatch):508 # can't use monkeypatch.delitem since the keys don't exist yetMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 509why, one step back509 for item in ("FOO", "BAR", "SPAM"):Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 510–511why, one step back510 monkeypatch._setitem.append((os.environ, item, notset))511Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 512–513why, one step back512 monkeypatch.setenv("EGGS", "3")513 monkeypatch.chdir(os.path.join(test_path, "cliapp", "inner1"))Merge pull request #2939 from sharmaadarsh563/2937-correct-load_dotenv-return-valueDavid Lordbefore adoptiond3e1fed
line 514why, one step back514 assert load_dotenv()Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 515–516why, one step back515 assert os.getcwd() == test_path516 # .flaskenv doesn't overwrite .envMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 517why, one step back517 assert os.environ["FOO"] == "env"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 518why, one step back518 # set only in .flaskenvMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 519why, one step back519 assert os.environ["BAR"] == "bar"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 520why, one step back520 # set only in .envMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 521why, one step back521 assert os.environ["SPAM"] == "1"Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 522why, one step back522 # set manually, files don't overwriteMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 523why, one step back523 assert os.environ["EGGS"] == "3"Merge pull request #2939 from sharmaadarsh563/2937-correct-load_dotenv-return-valueDavid Lordbefore adoptiond3e1fed
lines 524–525why, one step back524525 # Non existent file should not loadMerge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 526why, one step back526 assert not load_dotenv("non-existent-file")Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 527–530why, one step back527528529@need_dotenv530def test_dotenv_path(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 531why, one step back531 for item in ("FOO", "BAR", "EGGS"):Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 532–534why, one step back532 monkeypatch._setitem.append((os.environ, item, notset))533534 cwd = os.getcwd()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 535why, one step back535 load_dotenv(os.path.join(test_path, ".flaskenv"))Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
line 536why, one step back536 assert os.getcwd() == cwdMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 537why, one step back537 assert "FOO" in os.environAdd additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 538–540why, one step back538539540def test_dotenv_optional(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 541why, one step back541 monkeypatch.setattr("flask.cli.dotenv", None)Add additional information in the url_rule docs (#2467)Henry Chladilbefore adoption0a10908
lines 542–543why, one step back542 monkeypatch.chdir(test_path)543 load_dotenv()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 544why, one step back544 assert "FOO" not in os.environMerge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 545–546why, one step back545546Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
lines 547–549why, one step back547@need_dotenv548def test_disable_dotenv_from_env(monkeypatch, runner):549 monkeypatch.chdir(test_path)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 550why, one step back550 monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
line 551why, one step back551 runner.invoke(FlaskGroup())Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 552why, one step back552 assert "FOO" not in os.environMerge branch '1.0-maintenance'David Lordbefore adoption1fa9185
lines 553–554why, one step back553554Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 555–557why, one step back555def test_run_cert_path():556 # no key557 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 558why, one step back558 run_command.make_context("run", ["--cert", __file__])Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 559–561why, one step back559560 # no cert561 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 562why, one step back562 run_command.make_context("run", ["--key", __file__])Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
line 563why, one step back563Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 564–565why, one step back564 ctx = run_command.make_context("run", ["--cert", __file__, "--key", __file__])565 assert ctx.params["cert"] == (__file__, __file__)Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 566–568why, one step back566567568def test_run_cert_adhoc(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 569why, one step back569 monkeypatch.setitem(sys.modules, "OpenSSL", None)Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 570–572why, one step back570571 # pyOpenSSL not installed572 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 573why, one step back573 run_command.make_context("run", ["--cert", "adhoc"])Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 574–575why, one step back574575 # pyOpenSSL installedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 576–578why, one step back576 monkeypatch.setitem(sys.modules, "OpenSSL", types.ModuleType("OpenSSL"))577 ctx = run_command.make_context("run", ["--cert", "adhoc"])578 assert ctx.params["cert"] == "adhoc"Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 579–581why, one step back579580 # no key with adhoc581 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 582why, one step back582 run_command.make_context("run", ["--cert", "adhoc", "--key", __file__])Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 583–585why, one step back583584585def test_run_cert_import(monkeypatch):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 586why, one step back586 monkeypatch.setitem(sys.modules, "not_here", None)Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 587–589why, one step back587588 # ImportError589 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 590why, one step back590 run_command.make_context("run", ["--cert", "not_here"])Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 591–592why, one step back591592 # not an SSLContextMerge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
line 593why, one step back593 if sys.version_info >= (2, 7, 9):Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
line 594why, one step back594 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 595why, one step back595 run_command.make_context("run", ["--cert", "flask"])Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 596–597why, one step back596597 # SSLContextMerge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
line 598why, one step back598 if sys.version_info < (2, 7, 9):Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 599–602why, one step back599 ssl_context = object()600 else:601 ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)602Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 603–605why, one step back603 monkeypatch.setitem(sys.modules, "ssl_context", ssl_context)604 ctx = run_command.make_context("run", ["--cert", "ssl_context"])605 assert ctx.params["cert"] is ssl_contextMerge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef
lines 606–608why, one step back606607 # no --key with SSLContext608 with pytest.raises(click.BadParameter):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 609why, one step back609 run_command.make_context("run", ["--cert", "ssl_context", "--key", __file__])Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606
lines 610–611why, one step back610611Merge pull request #3242 from cslecrone/3211-ssl-importDavid Lordbefore adoption13b689b
lines 612–617why, one step back612def test_run_cert_no_ssl(monkeypatch):613 monkeypatch.setattr("flask.cli.ssl", None)614 with pytest.raises(click.BadParameter):615 run_command.make_context("run", ["--cert", "not_here"])616617Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606
lines 618–658why, one step back618def test_cli_blueprints(app):619 """Test blueprint commands register correctly to the application"""620 custom = Blueprint("custom", __name__, cli_group="customized")621 nested = Blueprint("nested", __name__)622 merged = Blueprint("merged", __name__, cli_group=None)623 late = Blueprint("late", __name__)624625 @custom.cli.command("custom")626 def custom_command():627 click.echo("custom_result")628629 @nested.cli.command("nested")630 def nested_command():631 click.echo("nested_result")632633 @merged.cli.command("merged")634 def merged_command():635 click.echo("merged_result")636637 @late.cli.command("late")638 def late_command():639 click.echo("late_result")640641 app.register_blueprint(custom)642 app.register_blueprint(nested)643 app.register_blueprint(merged)644 app.register_blueprint(late, cli_group="late_registration")645646 app_runner = app.test_cli_runner()647648 result = app_runner.invoke(args=["customized", "custom"])649 assert "custom_result" in result.output650651 result = app_runner.invoke(args=["nested", "nested"])652 assert "nested_result" in result.output653654 result = app_runner.invoke(args=["merged"])655 assert "merged_result" in result.output656657 result = app_runner.invoke(args=["late_registration", "late"])658 assert "late_result" in result.outputMerge pull request #3236 from lordmauve/no-cligroup-emptyDavid Lordbefore adoption91e53da
lines 659–667why, one step back659660661def test_cli_empty(app):662 """If a Blueprint's CLI group is empty, do not register it."""663 bp = Blueprint("blue", __name__, cli_group="blue")664 app.register_blueprint(bp)665666 result = app.test_cli_runner().invoke(args=["blue", "--help"])667 assert result.exit_code == 2, "Unexpected success:\n\n" + result.output