Skip to content
Myr

test_cli.py

This file

Path

tests/test_cli.py

608 lines · 16.8 KiB · Python

Last changed by

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

History of this file

Take it

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

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 1–5why, one step back
1# -*- coding: utf-8 -*-
2"""3 tests.test_cli4 ~~~~~~~~~~~~~~5

Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c

line 6why, one step back
6 :copyright: © 2010 by the Pallets team.

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 7–8why, one step back
7 :license: BSD, see LICENSE for more details.
8"""

Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c

lines 9–12why, one step back
9
10# This file was part of Flask-CLI and was modified under the terms of11# its Revised BSD License. Copyright © 2015 CERN.12

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

lines 13–14why, one step back
13from __future__ import absolute_import
14

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 15why, one step back
15import os

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

line 16why, one step back
16import ssl

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 17why, one step back
17import sys

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

line 18why, one step back
18import types

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 19–22why, one step back
19from functools import partial
2021import click22import pytest

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

line 23why, one step back
23from _pytest.monkeypatch import notset

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 24why, one step back
24from click.testing import CliRunner

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

line 25why, one step back
25

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 26why, one step back
26from flask import Flask, current_app

Merge pull request #2592 from pallets/tests-envDavid Lordbefore adoption2949306

line 27why, one step back
27from flask.cli import (

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 28–39why, one step back
28 AppGroup,
29 FlaskGroup,30 NoAppException,31 ScriptInfo,32 dotenv,33 find_best_app,34 get_version,35 load_dotenv,36 locate_app,37 prepare_import,38 run_command,39 with_appcontext,

Merge pull request #2592 from pallets/tests-envDavid Lordbefore adoption2949306

line 40why, one step back
40)

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 41why, one step back
41

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

line 42why, one step back
42cwd = os.getcwd()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 43why, one step back
43test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps"))

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

lines 44–45why, one step back
44
45

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 46–53why, one step back
46@pytest.fixture
47def runner():48 return CliRunner()495051def test_cli_name(test_apps):52 """Make sure the CLI object's name is the app's name and not the app itself"""53 from cliapp.app import testapp

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 54why, one step back
54

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 55–62why, one step back
55 assert testapp.cli.name == testapp.name
565758def test_find_best_app(test_apps):59 """Test if `find_best_app` behaves as expected with different combinations of input."""60 script_info = ScriptInfo()6162 class Module:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 63why, one step back
63 app = Flask("appname")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 64–67why, one step back
64
65 assert find_best_app(script_info, Module) == Module.app6667 class Module:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 68why, one step back
68 application = Flask("appname")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 69–72why, one step back
69
70 assert find_best_app(script_info, Module) == Module.application7172 class Module:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 73why, one step back
73 myapp = Flask("appname")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 74–79why, one step back
74
75 assert find_best_app(script_info, Module) == Module.myapp7677 class Module:78 @staticmethod79 def create_app():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 80why, one step back
80 return Flask("appname")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 81–82why, one step back
81
82 assert isinstance(find_best_app(script_info, Module), Flask)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 83why, one step back
83 assert find_best_app(script_info, Module).name == "appname"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 84–87why, one step back
84
85 class Module:86 @staticmethod87 def create_app(foo):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 88why, one step back
88 return Flask("appname")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 89–90why, one step back
89
90 assert isinstance(find_best_app(script_info, Module), Flask)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 91why, one step back
91 assert find_best_app(script_info, Module).name == "appname"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 92–95why, one step back
92
93 class Module:94 @staticmethod95 def create_app(foo=None, script_info=None):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 96why, one step back
96 return Flask("appname")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 97–98why, one step back
97
98 assert isinstance(find_best_app(script_info, Module), Flask)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 99why, one step back
99 assert find_best_app(script_info, Module).name == "appname"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 100–103why, one step back
100
101 class Module:102 @staticmethod103 def make_app():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 104why, one step back
104 return Flask("appname")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 105–106why, one step back
105
106 assert isinstance(find_best_app(script_info, Module), Flask)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 107why, one step back
107 assert find_best_app(script_info, Module).name == "appname"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

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

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 110why, one step back
110 myapp = Flask("appname1")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 111–113why, one step back
111
112 @staticmethod113 def create_app():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 114why, one step back
114 return Flask("appname2")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 115–118why, one step back
115
116 assert find_best_app(script_info, Module) == Module.myapp117118 class Module:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 119why, one step back
119 myapp = Flask("appname1")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 120–122why, one step back
120
121 @staticmethod122 def create_app():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 123why, one step back
123 return Flask("appname2")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 124–132why, one step back
124
125 assert find_best_app(script_info, Module) == Module.myapp126127 class Module:128 pass129130 pytest.raises(NoAppException, find_best_app, script_info, Module)131132 class Module:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 133–134why, one step back
133 myapp1 = Flask("appname1")
134 myapp2 = Flask("appname2")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 135–140why, one step back
135
136 pytest.raises(NoAppException, find_best_app, script_info, Module)137138 class Module:139 @staticmethod140 def create_app(foo, bar):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 141why, one step back
141 return Flask("appname2")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 142–144why, one step back
142
143 pytest.raises(NoAppException, find_best_app, script_info, Module)144

Merge pull request #2530 from pallets/feature/factory-detectionDavid Lordbefore adoption03a2996

lines 145–147why, one step back
145 class Module:
146 @staticmethod147 def create_app():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 148why, one step back
148 raise TypeError("bad bad factory!")

Merge pull request #2530 from pallets/feature/factory-detectionDavid Lordbefore adoption03a2996

lines 149–151why, one step back
149
150 pytest.raises(TypeError, find_best_app, script_info, Module)151

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 152why, one step back
152

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 153–154why, one step back
153@pytest.mark.parametrize(
154 "value,path,result",

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

line 155why, one step back
155 (

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 156–180why, one step back
156 ("test", cwd, "test"),
157 ("test.py", cwd, "test"),158 ("a/test", os.path.join(cwd, "a"), "test"),159 ("test/__init__.py", cwd, "test"),160 ("test/__init__", cwd, "test"),161 # nested package162 (163 os.path.join(test_path, "cliapp", "inner1", "__init__"),164 test_path,165 "cliapp.inner1",166 ),167 (168 os.path.join(test_path, "cliapp", "inner1", "inner2"),169 test_path,170 "cliapp.inner1.inner2",171 ),172 # dotted name173 ("test.a.b", cwd, "test.a.b"),174 (os.path.join(test_path, "cliapp.app"), test_path, "cliapp.app"),175 # not a Python file, will be caught during import176 (177 os.path.join(test_path, "cliapp", "message.txt"),178 test_path,179 "cliapp.message.txt",180 ),

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

line 181why, one step back
181 ),

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 182why, one step back
182)

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

lines 183–189why, one step back
183def test_prepare_import(request, value, path, result):
184 """Expect the correct path to be set and the correct import and app names185 to be returned.186187 :func:`prepare_exec_for_file` has a side effect where the parent directory188 of the given import is added to :data:`sys.path`. This is reset after the189 test runs.

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 190why, one step back
190 """

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

line 191why, one step back
191 original_path = sys.path[:]

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 192why, one step back
192

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

lines 193–194why, one step back
193 def reset_path():
194 sys.path[:] = original_path

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 195why, one step back
195

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

line 196why, one step back
196 request.addfinalizer(reset_path)

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 197why, one step back
197

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

lines 198–199why, one step back
198 assert prepare_import(value) == result
199 assert sys.path[0] == path

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 200–201why, one step back
200
201

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 202–219why, one step back
202@pytest.mark.parametrize(
203 "iname,aname,result",204 (205 ("cliapp.app", None, "testapp"),206 ("cliapp.app", "testapp", "testapp"),207 ("cliapp.factory", None, "app"),208 ("cliapp.factory", "create_app", "app"),209 ("cliapp.factory", "create_app()", "app"),210 # no script_info211 ("cliapp.factory", 'create_app2("foo", "bar")', "app2_foo_bar"),212 # trailing comma space213 ("cliapp.factory", 'create_app2("foo", "bar", )', "app2_foo_bar"),214 # takes script_info215 ("cliapp.factory", 'create_app3("foo")', "app3_foo_spam"),216 # strip whitespace217 ("cliapp.factory", " create_app () ", "app"),218 ),219)

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

lines 220–221why, one step back
220def test_locate_app(test_apps, iname, aname, result):
221 info = ScriptInfo()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 222why, one step back
222 info.data["test"] = "spam"

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

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

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 224why, one step back
224

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

line 225why, one step back
225

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 226–243why, one step back
226@pytest.mark.parametrize(
227 "iname,aname",228 (229 ("notanapp.py", None),230 ("cliapp/app", None),231 ("cliapp.app", "notanapp"),232 # not enough arguments233 ("cliapp.factory", 'create_app2("foo")'),234 # invalid identifier235 ("cliapp.factory", "create_app("),236 # no app returned237 ("cliapp.factory", "no_app"),238 # nested import error239 ("cliapp.importerrorapp", None),240 # not a Python file241 ("cliapp.message.txt", None),242 ),243)

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

lines 244–252why, one step back
244def test_locate_app_raises(test_apps, iname, aname):
245 info = ScriptInfo()246247 with pytest.raises(NoAppException):248 locate_app(info, iname, aname)249250251def test_locate_app_suppress_raise():252 info = ScriptInfo()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

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

Merge pull request #2414 from davidism/cli-load-local-packageDavid Lordbefore adoption77b98a2

lines 254–257why, one step back
254 assert app is None
255256 # only direct import error is suppressed257 with pytest.raises(NoAppException):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

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

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 259–261why, one step back
259
260261def test_get_version(test_apps, capsys):

Merge branch '1.0-maintenance'David Lordbefore adoption4f3dbb3

lines 262–264why, one step back
262 from flask import __version__ as flask_version
263 from werkzeug import __version__ as werkzeug_version264 from platform import python_version

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 265–269why, one step back
265
266 class MockCtx(object):267 resilient_parsing = False268 color = None269

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 270–271why, one step back
270 def exit(self):
271 return

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 272–275why, one step back
272
273 ctx = MockCtx()274 get_version(ctx, None, "test")275 out, err = capsys.readouterr()

Merge branch '1.0-maintenance'David Lordbefore adoption4f3dbb3

lines 276–278why, one step back
276 assert "Python " + python_version() in out
277 assert "Flask " + flask_version in out278 assert "Werkzeug " + werkzeug_version in out

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 279–280why, one step back
279
280

Merge pull request #2378 from miguelgrinberg/default-flask-appDavid Lordbefore adoption29c055a

line 281why, one step back
281def test_scriptinfo(test_apps, monkeypatch):

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 282–283why, one step back
282 """Test of ScriptInfo."""
283 obj = ScriptInfo(app_import_path="cliapp.app:testapp")

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

lines 284–286why, one step back
284 app = obj.load_app()
285 assert app.name == "testapp"286 assert obj.load_app() is app

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 287why, one step back
287

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

line 288why, one step back
288 # import app with module's absolute path

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 289–291why, one step back
289 cli_app_path = os.path.abspath(
290 os.path.join(os.path.dirname(__file__), "test_apps", "cliapp", "app.py")291 )

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

lines 292–293why, one step back
292 obj = ScriptInfo(app_import_path=cli_app_path)
293 app = obj.load_app()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 294why, one step back
294 assert app.name == "testapp"

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

line 295why, one step back
295 assert obj.load_app() is app

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 296why, one step back
296 obj = ScriptInfo(app_import_path=cli_app_path + ":testapp")

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

line 297why, one step back
297 app = obj.load_app()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 298why, one step back
298 assert app.name == "testapp"

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

lines 299–300why, one step back
299 assert obj.load_app() is app
300

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 301–306why, one step back
301 def create_app(info):
302 return Flask("createapp")303304 obj = ScriptInfo(create_app=create_app)305 app = obj.load_app()306 assert app.name == "createapp"

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

line 307why, one step back
307 assert obj.load_app() is app

Merge pull request #2378 from miguelgrinberg/default-flask-appDavid Lordbefore adoption29c055a

lines 308–312why, one step back
308
309 obj = ScriptInfo()310 pytest.raises(NoAppException, obj.load_app)311312 # import app from wsgi.py in current directory

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 313–317why, one step back
313 monkeypatch.chdir(
314 os.path.abspath(315 os.path.join(os.path.dirname(__file__), "test_apps", "helloworld")316 )317 )

Merge pull request #2378 from miguelgrinberg/default-flask-appDavid Lordbefore adoption29c055a

lines 318–319why, one step back
318 obj = ScriptInfo()
319 app = obj.load_app()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 320why, one step back
320 assert app.name == "hello"

Merge pull request #2378 from miguelgrinberg/default-flask-appDavid Lordbefore adoption29c055a

lines 321–322why, one step back
321
322 # import app from app.py in current directory

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 323–325why, one step back
323 monkeypatch.chdir(
324 os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps", "cliapp"))325 )

Merge pull request #2378 from miguelgrinberg/default-flask-appDavid Lordbefore adoption29c055a

lines 326–327why, one step back
326 obj = ScriptInfo()
327 app = obj.load_app()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 328why, one step back
328 assert app.name == "testapp"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 329–342why, one step back
329
330331def test_with_appcontext(runner):332 """Test of with_appcontext."""333334 @click.command()335 @with_appcontext336 def testcmd():337 click.echo(current_app.name)338339 obj = ScriptInfo(create_app=lambda info: Flask("testapp"))340341 result = runner.invoke(testcmd, obj=obj)342 assert result.exit_code == 0

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 343why, one step back
343 assert result.output == "testapp\n"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 344–366why, one step back
344
345346def test_appgroup(runner):347 """Test of with_appcontext."""348349 @click.group(cls=AppGroup)350 def cli():351 pass352353 @cli.command(with_appcontext=True)354 def test():355 click.echo(current_app.name)356357 @cli.group()358 def subgroup():359 pass360361 @subgroup.command(with_appcontext=True)362 def test2():363 click.echo(current_app.name)364365 obj = ScriptInfo(create_app=lambda info: Flask("testappgroup"))366

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 367why, one step back
367 result = runner.invoke(cli, ["test"], obj=obj)

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 368why, one step back
368 assert result.exit_code == 0

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 369why, one step back
369 assert result.output == "testappgroup\n"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 370why, one step back
370

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 371why, one step back
371 result = runner.invoke(cli, ["subgroup", "test2"], obj=obj)

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 372why, one step back
372 assert result.exit_code == 0

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 373why, one step back
373 assert result.output == "testappgroup\n"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 374–389why, one step back
374
375376def test_flaskgroup(runner):377 """Test FlaskGroup."""378379 def create_app(info):380 return Flask("flaskgroup")381382 @click.group(cls=FlaskGroup, create_app=create_app)383 def cli(**params):384 pass385386 @cli.command()387 def test():388 click.echo(current_app.name)389

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 390why, one step back
390 result = runner.invoke(cli, ["test"])

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 391why, one step back
391 assert result.exit_code == 0

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 392why, one step back
392 assert result.output == "flaskgroup\n"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 393–394why, one step back
393
394

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 395why, one step back
395@pytest.mark.parametrize("set_debug_flag", (True, False))

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

lines 396–411why, one step back
396def test_flaskgroup_debug(runner, set_debug_flag):
397 """Test FlaskGroup debug flag behavior."""398399 def create_app(info):400 app = Flask("flaskgroup")401 app.debug = True402 return app403404 @click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)405 def cli(**params):406 pass407408 @cli.command()409 def test():410 click.echo(str(current_app.debug))411

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 412why, one step back
412 result = runner.invoke(cli, ["test"])

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

line 413why, one step back
413 assert result.exit_code == 0

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 414why, one step back
414 assert result.output == "%s\n" % str(not set_debug_flag)

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

lines 415–416why, one step back
415
416

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 417–427why, one step back
417def test_print_exceptions(runner):
418 """Print the stacktrace if the CLI."""419420 def create_app(info):421 raise Exception("oh no")422 return Flask("flaskgroup")423424 @click.group(cls=FlaskGroup, create_app=create_app)425 def cli(**params):426 pass427

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 428why, one step back
428 result = runner.invoke(cli, ["--help"])

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 429why, one step back
429 assert result.exit_code == 0

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 430–431why, one step back
430 assert "Exception: oh no" in result.output
431 assert "Traceback" in result.output

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 432–440why, one step back
432
433434class TestRoutes:435 @pytest.fixture436 def invoke(self, runner):437 def create_app(info):438 app = Flask(__name__)439 app.testing = True440

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 441why, one step back
441 @app.route("/get_post/<int:x>/<int:y>", methods=["GET", "POST"])

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 442–444why, one step back
442 def yyy_get_post(x, y):
443 pass444

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 445why, one step back
445 @app.route("/zzz_post", methods=["POST"])

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 446–453why, one step back
446 def aaa_post():
447 pass448449 return app450451 cli = FlaskGroup(create_app=create_app)452 return partial(runner.invoke, cli)453

Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75

lines 454–464why, one step back
454 @pytest.fixture
455 def invoke_no_routes(self, runner):456 def create_app(info):457 app = Flask(__name__, static_folder=None)458 app.testing = True459460 return app461462 cli = FlaskGroup(create_app=create_app)463 return partial(runner.invoke, cli)464

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 465–468why, one step back
465 def expect_order(self, order, output):
466 # skip the header and match the start of each row467 for expect, line in zip(order, output.splitlines()[2:]):468 # do this instead of startswith for nicer pytest output

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 469why, one step back
469 assert line[: len(expect)] == expect

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 470–471why, one step back
470
471 def test_simple(self, invoke):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 472why, one step back
472 result = invoke(["routes"])

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 473why, one step back
473 assert result.exit_code == 0

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 474why, one step back
474 self.expect_order(["aaa_post", "static", "yyy_get_post"], result.output)

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 475–476why, one step back
475
476 def test_sort(self, invoke):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 477–478why, one step back
477 default_output = invoke(["routes"]).output
478 endpoint_output = invoke(["routes", "-s", "endpoint"]).output

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 479–480why, one step back
479 assert default_output == endpoint_output
480 self.expect_order(

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 481–482why, one step back
481 ["static", "yyy_get_post", "aaa_post"],
482 invoke(["routes", "-s", "methods"]).output,

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 483–484why, one step back
483 )
484 self.expect_order(

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 485–486why, one step back
485 ["yyy_get_post", "static", "aaa_post"],
486 invoke(["routes", "-s", "rule"]).output,

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 487–488why, one step back
487 )
488 self.expect_order(

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 489–490why, one step back
489 ["aaa_post", "yyy_get_post", "static"],
490 invoke(["routes", "-s", "match"]).output,

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 491–493why, one step back
491 )
492493 def test_all_methods(self, invoke):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 494–497why, one step back
494 output = invoke(["routes"]).output
495 assert "GET, HEAD, OPTIONS, POST" not in output496 output = invoke(["routes", "--all-methods"]).output497 assert "GET, HEAD, OPTIONS, POST" in output

Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75

lines 498–499why, one step back
498
499 def test_no_routes(self, invoke_no_routes):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 500why, one step back
500 result = invoke_no_routes(["routes"])

Merge pull request #2811 from greyli/test-routes-command-for-no-routesDavid Lordbefore adoptionb6a8f75

line 501why, one step back
501 assert result.exit_code == 0

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 502why, one step back
502 assert "No routes were registered." in result.output

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

lines 503–504why, one step back
503
504

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 505why, one step back
505need_dotenv = pytest.mark.skipif(dotenv is None, reason="dotenv is not installed")

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

lines 506–510why, one step back
506
507508@need_dotenv509def test_load_dotenv(monkeypatch):510 # can't use monkeypatch.delitem since the keys don't exist yet

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

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

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

lines 512–513why, one step back
512 monkeypatch._setitem.append((os.environ, item, notset))
513

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 514–515why, one step back
514 monkeypatch.setenv("EGGS", "3")
515 monkeypatch.chdir(os.path.join(test_path, "cliapp", "inner1"))

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

lines 516–518why, one step back
516 load_dotenv()
517 assert os.getcwd() == test_path518 # .flaskenv doesn't overwrite .env

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 519why, one step back
519 assert os.environ["FOO"] == "env"

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

line 520why, one step back
520 # set only in .flaskenv

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 521why, one step back
521 assert os.environ["BAR"] == "bar"

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

line 522why, one step back
522 # set only in .env

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 523why, one step back
523 assert os.environ["SPAM"] == "1"

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

line 524why, one step back
524 # set manually, files don't overwrite

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 525why, one step back
525 assert os.environ["EGGS"] == "3"

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

lines 526–529why, one step back
526
527528@need_dotenv529def test_dotenv_path(monkeypatch):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 530why, one step back
530 for item in ("FOO", "BAR", "EGGS"):

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

lines 531–533why, one step back
531 monkeypatch._setitem.append((os.environ, item, notset))
532533 cwd = os.getcwd()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 534why, one step back
534 load_dotenv(os.path.join(test_path, ".flaskenv"))

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

line 535why, one step back
535 assert os.getcwd() == cwd

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 536why, one step back
536 assert "FOO" in os.environ

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

lines 537–539why, one step back
537
538539def test_dotenv_optional(monkeypatch):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 540why, one step back
540 monkeypatch.setattr("flask.cli.dotenv", None)

Merge pull request #2416 from davidism/dotenvDavid Lordbefore adoption851eaa4

lines 541–542why, one step back
541 monkeypatch.chdir(test_path)
542 load_dotenv()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 543why, one step back
543 assert "FOO" not in os.environ

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 544–545why, one step back
544
545

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

lines 546–548why, one step back
546@need_dotenv
547def test_disable_dotenv_from_env(monkeypatch, runner):548 monkeypatch.chdir(test_path)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 549why, one step back
549 monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

line 550why, one step back
550 runner.invoke(FlaskGroup())

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 551why, one step back
551 assert "FOO" not in os.environ

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

lines 552–553why, one step back
552
553

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 554–556why, one step back
554def test_run_cert_path():
555 # no key556 with pytest.raises(click.BadParameter):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 557why, one step back
557 run_command.make_context("run", ["--cert", __file__])

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 558–560why, one step back
558
559 # no cert560 with pytest.raises(click.BadParameter):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 561why, one step back
561 run_command.make_context("run", ["--key", __file__])

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

line 562why, one step back
562

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

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

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 565–567why, one step back
565
566567def test_run_cert_adhoc(monkeypatch):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 568why, one step back
568 monkeypatch.setitem(sys.modules, "OpenSSL", None)

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 569–571why, one step back
569
570 # pyOpenSSL not installed571 with pytest.raises(click.BadParameter):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 572why, one step back
572 run_command.make_context("run", ["--cert", "adhoc"])

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 573–574why, one step back
573
574 # pyOpenSSL installed

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 575–577why, one step back
575 monkeypatch.setitem(sys.modules, "OpenSSL", types.ModuleType("OpenSSL"))
576 ctx = run_command.make_context("run", ["--cert", "adhoc"])577 assert ctx.params["cert"] == "adhoc"

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 578–580why, one step back
578
579 # no key with adhoc580 with pytest.raises(click.BadParameter):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 581why, one step back
581 run_command.make_context("run", ["--cert", "adhoc", "--key", __file__])

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 582–584why, one step back
582
583584def test_run_cert_import(monkeypatch):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 585why, one step back
585 monkeypatch.setitem(sys.modules, "not_here", None)

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 586–588why, one step back
586
587 # ImportError588 with pytest.raises(click.BadParameter):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 589why, one step back
589 run_command.make_context("run", ["--cert", "not_here"])

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 590–591why, one step back
590
591 # not an SSLContext

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

line 592why, one step back
592 if sys.version_info >= (2, 7, 9):

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

line 593why, one step back
593 with pytest.raises(click.BadParameter):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 594why, one step back
594 run_command.make_context("run", ["--cert", "flask"])

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 595–596why, one step back
595
596 # SSLContext

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

line 597why, one step back
597 if sys.version_info < (2, 7, 9):

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 598–601why, one step back
598 ssl_context = object()
599 else:600 ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)601

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 602–604why, one step back
602 monkeypatch.setitem(sys.modules, "ssl_context", ssl_context)
603 ctx = run_command.make_context("run", ["--cert", "ssl_context"])604 assert ctx.params["cert"] is ssl_context

Merge pull request #2606 from pallets/run-sslDavid Lordbefore adoption8ff0cef

lines 605–607why, one step back
605
606 # no --key with SSLContext607 with pytest.raises(click.BadParameter):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 608why, one step back
608 run_command.make_context("run", ["--cert", "ssl_context", "--key", __file__])