Skip to content
Myr

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 file

Take 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 back
1# This file was part of Flask-CLI and was modified under the terms of
2# its Revised BSD License. Copyright © 2015 CERN.3import os4import ssl5import sys6import types7from functools import partial89import click10import pytest11from _pytest.monkeypatch import notset12from click.testing import CliRunner13

Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697

lines 14–28why, one step back
14from flask import Blueprint
15from 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_appcontext

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 29–30why, one step back
29
30cwd = os.getcwd()

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

line 31why, one step back
31test_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 back
32
3334@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 testapp

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

line 42why, one step back
42

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 43–46why, one step back
43 assert testapp.cli.name == testapp.name
444546def test_find_best_app(test_apps):

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 47why, one step back
47 """Test if `find_best_app` behaves as expected with different combinations of input.""" # noqa: B950

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 48–50why, one step back
48 script_info = ScriptInfo()
4950 class Module:

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 52–55why, one step back
52
53 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 back
56 application = Flask("appname")

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 57–60why, one step back
57
58 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 back
61 myapp = Flask("appname")

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 62–67why, one step back
62
63 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 back
68 return Flask("appname")

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 69–70why, one step back
69
70 assert isinstance(find_best_app(script_info, Module), Flask)

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 72–75why, one step back
72
73 class Module:74 @staticmethod75 def create_app(foo):

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 77–78why, one step back
77
78 assert isinstance(find_best_app(script_info, Module), Flask)

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 80–83why, one step back
80
81 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 back
84 return Flask("appname")

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 85–86why, one step back
85
86 assert isinstance(find_best_app(script_info, Module), Flask)

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 88–91why, one step back
88
89 class Module:90 @staticmethod91 def make_app():

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 93–94why, one step back
93
94 assert isinstance(find_best_app(script_info, Module), Flask)

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 96–97why, one step back
96
97 class Module:

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 99–101why, one step back
99
100 @staticmethod101 def create_app():

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 103–106why, one step back
103
104 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 back
107 myapp = Flask("appname1")

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 108–110why, one step back
108
109 @staticmethod110 def create_app():

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 112–120why, one step back
112
113 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 back
121 myapp1 = Flask("appname1")
122 myapp2 = Flask("appname2")

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 123–128why, one step back
123
124 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 back
129 return Flask("appname2")

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 130–135why, one step back
130
131 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 back
136 raise TypeError("bad bad factory!")

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 137–140why, one step back
137
138 pytest.raises(TypeError, find_best_app, script_info, Module)139140

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

line 143why, one step back
143 (

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

lines 144–168why, one step back
144 ("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 back
169 ),

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

line 170why, one step back
170)

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 171–189why, one step back
171def 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] == path188189

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

lines 190–207why, one step back
190@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 back
208def 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 back
210 info.data["test"] = "spam"

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 211–213why, one step back
211 assert locate_app(info, iname, aname).name == result
212213

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

lines 214–231why, one step back
214@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 back
232def 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 back
241 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 back
242 assert app is None
243244 # only direct import error is suppressed245 with pytest.raises(NoAppException):

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

line 246why, one step back
246 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 back
247
248249def test_get_version(test_apps, capsys):

Merge branch '1.0-maintenance'David Lordbefore adoption4f3dbb3

lines 250–252why, one step back
250 from flask import __version__ as flask_version
251 from werkzeug import __version__ as werkzeug_version252 from platform import python_version

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

line 253why, one step back
253

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 254why, one step back
254 class MockCtx:

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 255–257why, one step back
255 resilient_parsing = False
256 color = None257

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

lines 258–259why, one step back
258 def exit(self):
259 return

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 260–263why, one step back
260
261 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 back
264 assert f"Python {python_version()}" in out
265 assert f"Flask {flask_version}" in out266 assert f"Werkzeug {werkzeug_version}" in out

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 267–271why, one step back
267
268269def 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 back
272 app = obj.load_app()
273 assert app.name == "testapp"274 assert obj.load_app() is app

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

line 275why, one step back
275

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

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

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

lines 277–279why, one step back
277 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 back
280 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 back
282 assert app.name == "testapp"

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 284why, one step back
284 obj = ScriptInfo(app_import_path=f"{cli_app_path}:testapp")

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

lines 287–288why, one step back
287 assert obj.load_app() is app
288

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 289–294why, one step back
289 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 back
295 assert obj.load_app() is app

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 296–300why, one step back
296
297 obj = ScriptInfo()298 pytest.raises(NoAppException, obj.load_app)299300 # import app from wsgi.py in current directory

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

lines 301–305why, one step back
301 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 back
306 obj = ScriptInfo()
307 app = obj.load_app()

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

lines 311–313why, one step back
311 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 back
314 obj = ScriptInfo()
315 app = obj.load_app()

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 317–330why, one step back
317
318319def 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 == 0

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 332–354why, one step back
332
333334def 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"))354

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

line 358why, one step back
358

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 362–377why, one step back
362
363364def 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)377

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 381–382why, one step back
381
382

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

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

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

lines 384–399why, one step back
384def 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))399

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

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

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 402why, one step back
402 assert result.output == f"{not set_debug_flag}\n"

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

lines 403–404why, one step back
403
404

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 405–415why, one step back
405def 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 pass415

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 420–428why, one step back
420
421422class TestRoutes:423 @pytest.fixture424 def invoke(self, runner):425 def create_app(info):426 app = Flask(__name__)427 app.testing = True428

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

line 429why, one step back
429 @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 back
430 def yyy_get_post(x, y):
431 pass432

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 434–441why, one step back
434 def aaa_post():
435 pass436437 return app438439 cli = FlaskGroup(create_app=create_app)440 return partial(runner.invoke, cli)441

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

lines 442–452why, one step back
442 @pytest.fixture
443 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)452

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 453–456why, one step back
453 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 output

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 458–459why, one step back
458
459 def test_simple(self, invoke):

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

line 462why, one step back
462 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 back
463
464 def test_sort(self, invoke):

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 467–468why, one step back
467 assert default_output == endpoint_output
468 self.expect_order(

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

lines 469–470why, one step back
469 ["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 back
471 )
472 self.expect_order(

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

lines 473–474why, one step back
473 ["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 back
475 )
476 self.expect_order(

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

lines 477–478why, one step back
477 ["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 back
479 )
480481 def test_all_methods(self, invoke):

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

lines 482–485why, one step back
482 output = invoke(["routes"]).output
483 assert "GET, HEAD, OPTIONS, POST" not in output484 output = invoke(["routes", "--all-methods"]).output485 assert "GET, HEAD, OPTIONS, POST" in output

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

lines 486–487why, one step back
486
487 def test_no_routes(self, invoke_no_routes):

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

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

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

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

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 491–492why, one step back
491
492

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

line 493why, one step back
493need_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 back
494
495496@need_dotenv497def test_load_dotenv(monkeypatch):498 # can't use monkeypatch.delitem since the keys don't exist yet

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

lines 502–503why, one step back
502 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 back
504 assert load_dotenv()

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 505–506why, one step back
505 assert os.getcwd() == test_path
506 # .flaskenv doesn't overwrite .env

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

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

Merge pull request #2939 from sharmaadarsh563/2937-correct-load_dotenv-return-valueDavid Lordbefore adoptiond3e1fed

lines 514–515why, one step back
514
515 # Non existent file should not load

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

line 516why, one step back
516 assert not load_dotenv("non-existent-file")

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 517–520why, one step back
517
518519@need_dotenv520def test_dotenv_path(monkeypatch):

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 522–524why, one step back
522 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 back
525 load_dotenv(os.path.join(test_path, ".flaskenv"))

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 528–530why, one step back
528
529530def test_dotenv_optional(monkeypatch):

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 532–533why, one step back
532 monkeypatch.chdir(test_path)
533 load_dotenv()

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 535–536why, one step back
535
536

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

lines 537–539why, one step back
537@need_dotenv
538def 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 back
540 monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

lines 543–544why, one step back
543
544

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 545–547why, one step back
545def 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 back
548 run_command.make_context("run", ["--cert", __file__])

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 549–551why, one step back
549
550 # no cert551 with pytest.raises(click.BadParameter):

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

line 553why, one step back
553

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

lines 554–555why, one step back
554 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 back
556
557558def test_run_cert_adhoc(monkeypatch):

Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e

line 559why, one step back
559 monkeypatch.setitem(sys.modules, "cryptography", None)

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

line 560why, one step back
560

Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e

line 561why, one step back
561 # cryptography not installed

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

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

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

line 564why, one step back
564

Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e

lines 565–566why, one step back
565 # cryptography installed
566 monkeypatch.setitem(sys.modules, "cryptography", types.ModuleType("cryptography"))

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

lines 567–568why, one step back
567 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 back
569
570 # no key with adhoc571 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", "--key", __file__])

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 573–575why, one step back
573
574575def test_run_cert_import(monkeypatch):

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 577–579why, one step back
577
578 # ImportError579 with pytest.raises(click.BadParameter):

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

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

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

line 581why, one step back
581

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

lines 582–583why, one step back
582 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 back
584
585 # SSLContext

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 586why, one step back
586 ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

line 587why, one step back
587

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

lines 588–590why, one step back
588 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_context

Merge pull request #2709 from davidism/docs-themeDavid Lordbefore adoption5fba092

lines 591–593why, one step back
591
592 # no --key with SSLContext593 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", "ssl_context", "--key", __file__])

Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606

lines 595–596why, one step back
595
596

Merge pull request #3242 from cslecrone/3211-ssl-importDavid Lordbefore adoption13b689b

lines 597–602why, one step back
597def 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"])601602

Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606

lines 603–643why, one step back
603def 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.output

Merge pull request #3236 from lordmauve/no-cligroup-emptyDavid Lordbefore adoption91e53da

lines 644–651why, one step back
644
645646def 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 back
652 assert result.exit_code == 2, f"Unexpected success:\n\n{result.output}"