Skip to content
Myr

test_cli.py

This file

Path

tests/test_cli.py

661 lines · 18.5 KiB · Python

Last changed by

Merge pull request #3711 from pallets/cli-loading-errorDavid Lordbefore adoption6638432

History of this file

Take it

The walk stopped after 200 commits: lines older than 86bf9dc point at it.

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 43–49why, one step back
43 assert testapp.cli.name == testapp.name
444546def test_find_best_app(test_apps):47 script_info = ScriptInfo()4849 class Module:

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 51–54why, one step back
51
52 assert find_best_app(script_info, Module) == Module.app5354 class Module:

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 56–59why, one step back
56
57 assert find_best_app(script_info, Module) == Module.application5859 class Module:

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 61–66why, one step back
61
62 assert find_best_app(script_info, Module) == Module.myapp6364 class Module:65 @staticmethod66 def create_app():

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 68why, one step back
68

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

lines 69–71why, one step back
69 app = find_best_app(script_info, Module)
70 assert isinstance(app, Flask)71 assert app.name == "appname"

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 77why, one step back
77

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

lines 78–79why, one step back
78 with pytest.deprecated_call(match="Script info"):
79 app = find_best_app(script_info, Module)

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 80why, one step back
80

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

lines 81–83why, one step back
81 assert isinstance(app, Flask)
82 assert app.name == "appname"83

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 84–86why, one step back
84 class Module:
85 @staticmethod86 def create_app(foo=None, script_info=None):

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 88why, one step back
88

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

lines 89–90why, one step back
89 with pytest.deprecated_call(match="script_info"):
90 app = find_best_app(script_info, Module)

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 91why, one step back
91

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

lines 92–94why, one step back
92 assert isinstance(app, Flask)
93 assert app.name == "appname"94

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 95–97why, one step back
95 class Module:
96 @staticmethod97 def make_app():

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 99why, one step back
99

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

lines 100–102why, one step back
100 app = find_best_app(script_info, Module)
101 assert isinstance(app, Flask)102 assert app.name == "appname"

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 103–104why, one step back
103
104 class Module:

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 106–108why, one step back
106
107 @staticmethod108 def create_app():

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 110–113why, one step back
110
111 assert find_best_app(script_info, Module) == Module.myapp112113 class Module:

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 115–117why, one step back
115
116 @staticmethod117 def create_app():

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 119–127why, one step back
119
120 assert find_best_app(script_info, Module) == Module.myapp121122 class Module:123 pass124125 pytest.raises(NoAppException, find_best_app, script_info, Module)126127 class Module:

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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(foo, bar):

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 137–142why, one step back
137
138 pytest.raises(NoAppException, find_best_app, script_info, Module)139140 class Module:141 @staticmethod142 def create_app():

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 144–147why, one step back
144
145 pytest.raises(TypeError, find_best_app, script_info, Module)146147

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 150why, one step back
150 (

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

lines 151–175why, one step back
151 ("test", cwd, "test"),
152 ("test.py", cwd, "test"),153 ("a/test", os.path.join(cwd, "a"), "test"),154 ("test/__init__.py", cwd, "test"),155 ("test/__init__", cwd, "test"),156 # nested package157 (158 os.path.join(test_path, "cliapp", "inner1", "__init__"),159 test_path,160 "cliapp.inner1",161 ),162 (163 os.path.join(test_path, "cliapp", "inner1", "inner2"),164 test_path,165 "cliapp.inner1.inner2",166 ),167 # dotted name168 ("test.a.b", cwd, "test.a.b"),169 (os.path.join(test_path, "cliapp.app"), test_path, "cliapp.app"),170 # not a Python file, will be caught during import171 (172 os.path.join(test_path, "cliapp", "message.txt"),173 test_path,174 "cliapp.message.txt",175 ),

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 176why, one step back
176 ),

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

line 177why, one step back
177)

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 178–196why, one step back
178def test_prepare_import(request, value, path, result):
179 """Expect the correct path to be set and the correct import and app names180 to be returned.181182 :func:`prepare_exec_for_file` has a side effect where the parent directory183 of the given import is added to :data:`sys.path`. This is reset after the184 test runs.185 """186 original_path = sys.path[:]187188 def reset_path():189 sys.path[:] = original_path190191 request.addfinalizer(reset_path)192193 assert prepare_import(value) == result194 assert sys.path[0] == path195196

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

lines 197–211why, one step back
197@pytest.mark.parametrize(
198 "iname,aname,result",199 (200 ("cliapp.app", None, "testapp"),201 ("cliapp.app", "testapp", "testapp"),202 ("cliapp.factory", None, "app"),203 ("cliapp.factory", "create_app", "app"),204 ("cliapp.factory", "create_app()", "app"),205 ("cliapp.factory", 'create_app2("foo", "bar")', "app2_foo_bar"),206 # trailing comma space207 ("cliapp.factory", 'create_app2("foo", "bar", )', "app2_foo_bar"),208 # strip whitespace209 ("cliapp.factory", " create_app () ", "app"),210 ),211)

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 212–216why, one step back
212def test_locate_app(test_apps, iname, aname, result):
213 info = ScriptInfo()214 assert locate_app(info, iname, aname).name == result215216

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

lines 217–234why, one step back
217@pytest.mark.parametrize(
218 "iname,aname",219 (220 ("notanapp.py", None),221 ("cliapp/app", None),222 ("cliapp.app", "notanapp"),223 # not enough arguments224 ("cliapp.factory", 'create_app2("foo")'),225 # invalid identifier226 ("cliapp.factory", "create_app("),227 # no app returned228 ("cliapp.factory", "no_app"),229 # nested import error230 ("cliapp.importerrorapp", None),231 # not a Python file232 ("cliapp.message.txt", None),233 ),234)

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 235–241why, one step back
235def test_locate_app_raises(test_apps, iname, aname):
236 info = ScriptInfo()237238 with pytest.raises(NoAppException):239 locate_app(info, iname, aname)240241

Merge pull request #3711 from pallets/cli-loading-errorDavid Lordbefore adoption6638432

line 242why, one step back
242def test_locate_app_suppress_raise(test_apps):

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 243why, one step back
243 info = ScriptInfo()

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 245–248why, one step back
245 assert app is None
246247 # only direct import error is suppressed248 with pytest.raises(NoAppException):

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 250–256why, one step back
250
251252def test_get_version(test_apps, capsys):253 from flask import __version__ as flask_version254 from werkzeug import __version__ as werkzeug_version255 from platform import python_version256

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

line 257why, one step back
257 class MockCtx:

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 258–260why, one step back
258 resilient_parsing = False
259 color = None260

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

lines 261–262why, one step back
261 def exit(self):
262 return

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 263–266why, one step back
263
264 ctx = MockCtx()265 get_version(ctx, None, "test")266 out, err = capsys.readouterr()

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

lines 267–269why, one step back
267 assert f"Python {python_version()}" in out
268 assert f"Flask {flask_version}" in out269 assert f"Werkzeug {werkzeug_version}" in out

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 270–278why, one step back
270
271272def test_scriptinfo(test_apps, monkeypatch):273 obj = ScriptInfo(app_import_path="cliapp.app:testapp")274 app = obj.load_app()275 assert app.name == "testapp"276 assert obj.load_app() is app277278 # import app with module's absolute path

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

lines 279–281why, one step back
279 cli_app_path = os.path.abspath(
280 os.path.join(os.path.dirname(__file__), "test_apps", "cliapp", "app.py")281 )

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 289–290why, one step back
289 assert obj.load_app() is app
290

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

line 291why, one step back
291 def create_app():

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 292–302why, one step back
292 return Flask("createapp")
293294 obj = ScriptInfo(create_app=create_app)295 app = obj.load_app()296 assert app.name == "createapp"297 assert obj.load_app() is app298299 obj = ScriptInfo()300 pytest.raises(NoAppException, obj.load_app)301302 # import app from wsgi.py in current directory

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

lines 303–307why, one step back
303 monkeypatch.chdir(
304 os.path.abspath(305 os.path.join(os.path.dirname(__file__), "test_apps", "helloworld")306 )307 )

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 308–309why, one step back
308 obj = ScriptInfo()
309 app = obj.load_app()

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 316–317why, one step back
316 obj = ScriptInfo()
317 app = obj.load_app()

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 319–326why, one step back
319
320321def test_with_appcontext(runner):322 @click.command()323 @with_appcontext324 def testcmd():325 click.echo(current_app.name)326

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

line 327why, one step back
327 obj = ScriptInfo(create_app=lambda: Flask("testapp"))

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 328–330why, one step back
328
329 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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 332–350why, one step back
332
333334def test_appgroup(runner):335 @click.group(cls=AppGroup)336 def cli():337 pass338339 @cli.command(with_appcontext=True)340 def test():341 click.echo(current_app.name)342343 @cli.group()344 def subgroup():345 pass346347 @subgroup.command(with_appcontext=True)348 def test2():349 click.echo(current_app.name)350

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

line 351why, one step back
351 obj = ScriptInfo(create_app=lambda: Flask("testappgroup"))

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 352why, one step back
352

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 356why, one step back
356

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 360–362why, one step back
360
361362def test_flaskgroup(runner):

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

line 363why, one step back
363 def create_app():

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 364–373why, one step back
364 return Flask("flaskgroup")
365366 @click.group(cls=FlaskGroup, create_app=create_app)367 def cli(**params):368 pass369370 @cli.command()371 def test():372 click.echo(current_app.name)373

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 377–378why, one step back
377
378

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 380why, one step back
380def test_flaskgroup_debug(runner, set_debug_flag):

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

line 381why, one step back
381 def create_app():

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 382–393why, one step back
382 app = Flask("flaskgroup")
383 app.debug = True384 return app385386 @click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)387 def cli(**params):388 pass389390 @cli.command()391 def test():392 click.echo(str(current_app.debug))393

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 397–398why, one step back
397
398

Merge pull request #3711 from pallets/cli-loading-errorDavid Lordbefore adoption6638432

lines 399–400why, one step back
399def test_no_command_echo_loading_error():
400 from flask.cli import cli

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 401why, one step back
401

Merge pull request #3711 from pallets/cli-loading-errorDavid Lordbefore adoption6638432

lines 402–419why, one step back
402 runner = CliRunner(mix_stderr=False)
403 result = runner.invoke(cli, ["missing"])404 assert result.exit_code == 2405 assert "FLASK_APP" in result.stderr406 assert "Usage:" in result.stderr407408409def test_help_echo_loading_error():410 from flask.cli import cli411412 runner = CliRunner(mix_stderr=False)413 result = runner.invoke(cli, ["--help"])414 assert result.exit_code == 0415 assert "FLASK_APP" in result.stderr416 assert "Usage:" in result.stdout417418419def test_help_echo_exception():

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

line 420why, one step back
420 def create_app():

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 421–422why, one step back
421 raise Exception("oh no")
422

Merge pull request #3711 from pallets/cli-loading-errorDavid Lordbefore adoption6638432

lines 423–424why, one step back
423 cli = FlaskGroup(create_app=create_app)
424 runner = CliRunner(mix_stderr=False)

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

Merge pull request #3711 from pallets/cli-loading-errorDavid Lordbefore adoption6638432

lines 427–428why, one step back
427 assert "Exception: oh no" in result.stderr
428 assert "Usage:" in result.stdout

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 429–433why, one step back
429
430431class TestRoutes:432 @pytest.fixture433 def invoke(self, runner):

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

line 434why, one step back
434 def create_app():

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 435–437why, one step back
435 app = Flask(__name__)
436 app.testing = True437

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 439–441why, one step back
439 def yyy_get_post(x, y):
440 pass441

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 443–452why, one step back
443 def aaa_post():
444 pass445446 return app447448 cli = FlaskGroup(create_app=create_app)449 return partial(runner.invoke, cli)450451 @pytest.fixture452 def invoke_no_routes(self, runner):

Merge pull request #3563 from pallets/deprecate-script-info-argDavid Lordbefore adoption0d04b40

line 453why, one step back
453 def create_app():

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 454–465why, one step back
454 app = Flask(__name__, static_folder=None)
455 app.testing = True456457 return app458459 cli = FlaskGroup(create_app=create_app)460 return partial(runner.invoke, cli)461462 def expect_order(self, order, output):463 # skip the header and match the start of each row464 for expect, line in zip(order, output.splitlines()[2:]):465 # do this instead of startswith for nicer pytest output

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 467–468why, one step back
467
468 def test_simple(self, invoke):

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 472–473why, one step back
472
473 def test_sort(self, invoke):

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 476–477why, one step back
476 assert default_output == endpoint_output
477 self.expect_order(

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 480–481why, one step back
480 )
481 self.expect_order(

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 488–490why, one step back
488 )
489490 def test_all_methods(self, invoke):

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

lines 491–494why, one step back
491 output = invoke(["routes"]).output
492 assert "GET, HEAD, OPTIONS, POST" not in output493 output = invoke(["routes", "--all-methods"]).output494 assert "GET, HEAD, OPTIONS, POST" in output

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 495–496why, one step back
495
496 def test_no_routes(self, invoke_no_routes):

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 500–501why, one step back
500
501

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 503–507why, one step back
503
504505@need_dotenv506def test_load_dotenv(monkeypatch):507 # can't use monkeypatch.delitem since the keys don't exist yet

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

line 511why, one step back
511 monkeypatch.setenv("EGGS", "3")

Merge pull request #3560 from greyli/fix-env-chdirJoshua Bronsonbefore adoptiona40c381

line 512why, one step back
512 monkeypatch.chdir(test_path)

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

line 513why, one step back
513 assert load_dotenv()

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

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

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

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

lines 523–524why, one step back
523
524 # Non existent file should not load

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 544–548why, one step back
544
545546@need_dotenv547def 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 pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 552–556why, one step back
552
553554def 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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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

Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 569why, one step back
569

Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 571why, one step back
571 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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 573why, one step back
573

Merge pull request #3492 from pallets/cryptographyDavid Lordbefore adoptionb074a2e

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

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

lines 576–577why, one step back
576 ctx = run_command.make_context("run", ["--cert", "adhoc"])
577 assert ctx.params["cert"] == "adhoc"

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

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 #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 590why, one step back
590

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

lines 591–592why, one step back
591 with pytest.raises(click.BadParameter):
592 run_command.make_context("run", ["--cert", "flask"])

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 593–594why, one step back
593
594 # SSLContext

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

line 596why, one step back
596

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

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

Merge pull request #3103 from tbm/typosDavid Lordbefore adoption86bf9dc

lines 600–602why, one step back
600
601 # no --key with SSLContext602 with pytest.raises(click.BadParameter):

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

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

Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606

lines 604–605why, one step back
604
605

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

lines 606–611why, one step back
606def test_run_cert_no_ssl(monkeypatch):
607 monkeypatch.setattr("flask.cli.ssl", None)608 with pytest.raises(click.BadParameter):609 run_command.make_context("run", ["--cert", "not_here"])610611

Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606

lines 612–652why, one step back
612def test_cli_blueprints(app):
613 """Test blueprint commands register correctly to the application"""614 custom = Blueprint("custom", __name__, cli_group="customized")615 nested = Blueprint("nested", __name__)616 merged = Blueprint("merged", __name__, cli_group=None)617 late = Blueprint("late", __name__)618619 @custom.cli.command("custom")620 def custom_command():621 click.echo("custom_result")622623 @nested.cli.command("nested")624 def nested_command():625 click.echo("nested_result")626627 @merged.cli.command("merged")628 def merged_command():629 click.echo("merged_result")630631 @late.cli.command("late")632 def late_command():633 click.echo("late_result")634635 app.register_blueprint(custom)636 app.register_blueprint(nested)637 app.register_blueprint(merged)638 app.register_blueprint(late, cli_group="late_registration")639640 app_runner = app.test_cli_runner()641642 result = app_runner.invoke(args=["customized", "custom"])643 assert "custom_result" in result.output644645 result = app_runner.invoke(args=["nested", "nested"])646 assert "nested_result" in result.output647648 result = app_runner.invoke(args=["merged"])649 assert "merged_result" in result.output650651 result = app_runner.invoke(args=["late_registration", "late"])652 assert "late_result" in result.output

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

lines 653–660why, one step back
653
654655def test_cli_empty(app):656 """If a Blueprint's CLI group is empty, do not register it."""657 bp = Blueprint("blue", __name__, cli_group="blue")658 app.register_blueprint(bp)659660 result = app.test_cli_runner().invoke(args=["blue", "--help"])

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

line 661why, one step back
661 assert result.exit_code == 2, f"Unexpected success:\n\n{result.output}"