Skip to content
Myr

test_cli.py

This file

Path

tests/test_cli.py

667 lines · 18.8 KiB · Python

Last changed by

Merge branch '1.0.x'David Lordbefore adoption1351d0a

History of this file

Take it

The walk stopped after 200 commits: lines older than 3a0ea72 point at it.

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

Merge branch '1.0.x'David Lordbefore adoption1351d0a

lines 6–7why, one step back
6 :copyright: 2010 Pallets
7 :license: BSD-3-Clause

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 8–23why, one step back
8"""
9# This file was part of Flask-CLI and was modified under the terms of10# its Revised BSD License. Copyright © 2015 CERN.11from __future__ import absolute_import1213import os14import ssl15import sys16import types17from functools import partial1819import click20import pytest21from _pytest.monkeypatch import notset22from click.testing import CliRunner23

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

lines 24–38why, one step back
24from flask import Blueprint
25from flask import current_app26from flask import Flask27from flask.cli import AppGroup28from flask.cli import dotenv29from flask.cli import find_best_app30from flask.cli import FlaskGroup31from flask.cli import get_version32from flask.cli import load_dotenv33from flask.cli import locate_app34from flask.cli import NoAppException35from flask.cli import prepare_import36from flask.cli import run_command37from flask.cli import ScriptInfo38from flask.cli import with_appcontext

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 39–40why, one step back
39
40cwd = os.getcwd()

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 42–51why, one step back
42
4344@pytest.fixture45def runner():46 return CliRunner()474849def test_cli_name(test_apps):50 """Make sure the CLI object's name is the app's name and not the app itself"""51 from cliapp.app import testapp

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

line 52why, one step back
52

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 53–56why, one step back
53 assert testapp.cli.name == testapp.name
545556def test_find_best_app(test_apps):

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 58–60why, one step back
58 script_info = ScriptInfo()
5960 class Module:

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 62–65why, one step back
62
63 assert find_best_app(script_info, Module) == Module.app6465 class Module:

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 67–70why, one step back
67
68 assert find_best_app(script_info, Module) == Module.application6970 class Module:

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 72–77why, one step back
72
73 assert find_best_app(script_info, Module) == Module.myapp7475 class Module:76 @staticmethod77 def create_app():

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 79–80why, one step back
79
80 assert isinstance(find_best_app(script_info, Module), Flask)

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 82–85why, one step back
82
83 class Module:84 @staticmethod85 def create_app(foo):

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 87–88why, one step back
87
88 assert isinstance(find_best_app(script_info, Module), Flask)

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 90–93why, one step back
90
91 class Module:92 @staticmethod93 def create_app(foo=None, script_info=None):

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 95–96why, one step back
95
96 assert isinstance(find_best_app(script_info, Module), Flask)

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 98–101why, one step back
98
99 class Module:100 @staticmethod101 def make_app():

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 103–104why, one step back
103
104 assert isinstance(find_best_app(script_info, Module), Flask)

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 106–107why, one step back
106
107 class Module:

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 109–111why, one step back
109
110 @staticmethod111 def create_app():

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 113–116why, one step back
113
114 assert find_best_app(script_info, Module) == Module.myapp115116 class Module:

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 118–120why, one step back
118
119 @staticmethod120 def create_app():

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 122–130why, one step back
122
123 assert find_best_app(script_info, Module) == Module.myapp124125 class Module:126 pass127128 pytest.raises(NoAppException, find_best_app, script_info, Module)129130 class Module:

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 133–138why, one step back
133
134 pytest.raises(NoAppException, find_best_app, script_info, Module)135136 class Module:137 @staticmethod138 def create_app(foo, bar):

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 140–145why, one step back
140
141 pytest.raises(NoAppException, find_best_app, script_info, Module)142143 class Module:144 @staticmethod145 def create_app():

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 147–150why, one step back
147
148 pytest.raises(TypeError, find_best_app, script_info, Module)149150

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

line 153why, one step back
153 (

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

lines 154–178why, one step back
154 ("test", cwd, "test"),
155 ("test.py", cwd, "test"),156 ("a/test", os.path.join(cwd, "a"), "test"),157 ("test/__init__.py", cwd, "test"),158 ("test/__init__", cwd, "test"),159 # nested package160 (161 os.path.join(test_path, "cliapp", "inner1", "__init__"),162 test_path,163 "cliapp.inner1",164 ),165 (166 os.path.join(test_path, "cliapp", "inner1", "inner2"),167 test_path,168 "cliapp.inner1.inner2",169 ),170 # dotted name171 ("test.a.b", cwd, "test.a.b"),172 (os.path.join(test_path, "cliapp.app"), test_path, "cliapp.app"),173 # not a Python file, will be caught during import174 (175 os.path.join(test_path, "cliapp", "message.txt"),176 test_path,177 "cliapp.message.txt",178 ),

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

line 179why, one step back
179 ),

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

line 180why, one step back
180)

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 181–199why, one step back
181def test_prepare_import(request, value, path, result):
182 """Expect the correct path to be set and the correct import and app names183 to be returned.184185 :func:`prepare_exec_for_file` has a side effect where the parent directory186 of the given import is added to :data:`sys.path`. This is reset after the187 test runs.188 """189 original_path = sys.path[:]190191 def reset_path():192 sys.path[:] = original_path193194 request.addfinalizer(reset_path)195196 assert prepare_import(value) == result197 assert sys.path[0] == path198199

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

lines 200–217why, one step back
200@pytest.mark.parametrize(
201 "iname,aname,result",202 (203 ("cliapp.app", None, "testapp"),204 ("cliapp.app", "testapp", "testapp"),205 ("cliapp.factory", None, "app"),206 ("cliapp.factory", "create_app", "app"),207 ("cliapp.factory", "create_app()", "app"),208 # no script_info209 ("cliapp.factory", 'create_app2("foo", "bar")', "app2_foo_bar"),210 # trailing comma space211 ("cliapp.factory", 'create_app2("foo", "bar", )', "app2_foo_bar"),212 # takes script_info213 ("cliapp.factory", 'create_app3("foo")', "app3_foo_spam"),214 # strip whitespace215 ("cliapp.factory", " create_app () ", "app"),216 ),217)

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 221–223why, one step back
221 assert locate_app(info, iname, aname).name == result
222223

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

lines 224–241why, one step back
224@pytest.mark.parametrize(
225 "iname,aname",226 (227 ("notanapp.py", None),228 ("cliapp/app", None),229 ("cliapp.app", "notanapp"),230 # not enough arguments231 ("cliapp.factory", 'create_app2("foo")'),232 # invalid identifier233 ("cliapp.factory", "create_app("),234 # no app returned235 ("cliapp.factory", "no_app"),236 # nested import error237 ("cliapp.importerrorapp", None),238 # not a Python file239 ("cliapp.message.txt", None),240 ),241)

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 242–250why, one step back
242def test_locate_app_raises(test_apps, iname, aname):
243 info = ScriptInfo()244245 with pytest.raises(NoAppException):246 locate_app(info, iname, aname)247248249def test_locate_app_suppress_raise():250 info = ScriptInfo()

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 252–255why, one step back
252 assert app is None
253254 # only direct import error is suppressed255 with pytest.raises(NoAppException):

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 257–259why, one step back
257
258259def test_get_version(test_apps, capsys):

Merge branch '1.0-maintenance'David Lordbefore adoption4f3dbb3

lines 260–262why, one step back
260 from flask import __version__ as flask_version
261 from werkzeug import __version__ as werkzeug_version262 from platform import python_version

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 263–267why, one step back
263
264 class MockCtx(object):265 resilient_parsing = False266 color = None267

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

lines 268–269why, one step back
268 def exit(self):
269 return

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

Merge branch '1.0-maintenance'David Lordbefore adoption4f3dbb3

lines 274–276why, one step back
274 assert "Python " + python_version() in out
275 assert "Flask " + flask_version in out276 assert "Werkzeug " + werkzeug_version in out

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 277–281why, one step back
277
278279def test_scriptinfo(test_apps, monkeypatch):280 """Test of ScriptInfo."""281 obj = ScriptInfo(app_import_path="cliapp.app:testapp")

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

line 285why, one step back
285

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

lines 297–298why, one step back
297 assert obj.load_app() is app
298

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 299–304why, one step back
299 def create_app(info):
300 return Flask("createapp")301302 obj = ScriptInfo(create_app=create_app)303 app = obj.load_app()304 assert app.name == "createapp"

Merge branch '1.0-maintenance'David Lordbefore adoptionf7d50d4

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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 == "hello"

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 324–325why, one step back
324 obj = ScriptInfo()
325 app = obj.load_app()

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 327–340why, one step back
327
328329def test_with_appcontext(runner):330 """Test of with_appcontext."""331332 @click.command()333 @with_appcontext334 def testcmd():335 click.echo(current_app.name)336337 obj = ScriptInfo(create_app=lambda info: Flask("testapp"))338339 result = runner.invoke(testcmd, obj=obj)340 assert result.exit_code == 0

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 342–364why, one step back
342
343344def test_appgroup(runner):345 """Test of with_appcontext."""346347 @click.group(cls=AppGroup)348 def cli():349 pass350351 @cli.command(with_appcontext=True)352 def test():353 click.echo(current_app.name)354355 @cli.group()356 def subgroup():357 pass358359 @subgroup.command(with_appcontext=True)360 def test2():361 click.echo(current_app.name)362363 obj = ScriptInfo(create_app=lambda info: Flask("testappgroup"))364

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

line 368why, one step back
368

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 372–387why, one step back
372
373374def test_flaskgroup(runner):375 """Test FlaskGroup."""376377 def create_app(info):378 return Flask("flaskgroup")379380 @click.group(cls=FlaskGroup, create_app=create_app)381 def cli(**params):382 pass383384 @cli.command()385 def test():386 click.echo(current_app.name)387

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 391–392why, one step back
391
392

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

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

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

lines 394–409why, one step back
394def test_flaskgroup_debug(runner, set_debug_flag):
395 """Test FlaskGroup debug flag behavior."""396397 def create_app(info):398 app = Flask("flaskgroup")399 app.debug = True400 return app401402 @click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)403 def cli(**params):404 pass405406 @cli.command()407 def test():408 click.echo(str(current_app.debug))409

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

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

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

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

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

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

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

lines 413–414why, one step back
413
414

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 415–425why, one step back
415def test_print_exceptions(runner):
416 """Print the stacktrace if the CLI."""417418 def create_app(info):419 raise Exception("oh no")420 return Flask("flaskgroup")421422 @click.group(cls=FlaskGroup, create_app=create_app)423 def cli(**params):424 pass425

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 430–438why, one step back
430
431432class TestRoutes:433 @pytest.fixture434 def invoke(self, runner):435 def create_app(info):436 app = Flask(__name__)437 app.testing = True438

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 444–451why, one step back
444 def aaa_post():
445 pass446447 return app448449 cli = FlaskGroup(create_app=create_app)450 return partial(runner.invoke, cli)451

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

lines 452–462why, one step back
452 @pytest.fixture
453 def invoke_no_routes(self, runner):454 def create_app(info):455 app = Flask(__name__, static_folder=None)456 app.testing = True457458 return app459460 cli = FlaskGroup(create_app=create_app)461 return partial(runner.invoke, cli)462

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 489–491why, one step back
489 )
490491 def test_all_methods(self, invoke):

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

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

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

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

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

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

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

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 501–502why, one step back
501
502

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 504–508why, one step back
504
505506@need_dotenv507def test_load_dotenv(monkeypatch):508 # can't use monkeypatch.delitem since the keys don't exist yet

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

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

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 527–530why, one step back
527
528529@need_dotenv530def test_dotenv_path(monkeypatch):

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 532–534why, one step back
532 monkeypatch._setitem.append((os.environ, item, notset))
533534 cwd = os.getcwd()

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 538–540why, one step back
538
539540def test_dotenv_optional(monkeypatch):

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 545–546why, one step back
545
546

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

lines 553–554why, one step back
553
554

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

line 563why, one step back
563

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 566–568why, one step back
566
567568def test_run_cert_adhoc(monkeypatch):

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

lines 583–585why, one step back
583
584585def test_run_cert_import(monkeypatch):

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

move coveragerc to setup.cfgDavid Lordbefore adoption3a0ea72

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

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

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

Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606

lines 610–611why, one step back
610
611

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

lines 612–617why, one step back
612def test_run_cert_no_ssl(monkeypatch):
613 monkeypatch.setattr("flask.cli.ssl", None)614 with pytest.raises(click.BadParameter):615 run_command.make_context("run", ["--cert", "not_here"])616617

Merge pull request #2784 from doobeh/masterDavid Lordbefore adoptionb837606

lines 618–658why, one step back
618def test_cli_blueprints(app):
619 """Test blueprint commands register correctly to the application"""620 custom = Blueprint("custom", __name__, cli_group="customized")621 nested = Blueprint("nested", __name__)622 merged = Blueprint("merged", __name__, cli_group=None)623 late = Blueprint("late", __name__)624625 @custom.cli.command("custom")626 def custom_command():627 click.echo("custom_result")628629 @nested.cli.command("nested")630 def nested_command():631 click.echo("nested_result")632633 @merged.cli.command("merged")634 def merged_command():635 click.echo("merged_result")636637 @late.cli.command("late")638 def late_command():639 click.echo("late_result")640641 app.register_blueprint(custom)642 app.register_blueprint(nested)643 app.register_blueprint(merged)644 app.register_blueprint(late, cli_group="late_registration")645646 app_runner = app.test_cli_runner()647648 result = app_runner.invoke(args=["customized", "custom"])649 assert "custom_result" in result.output650651 result = app_runner.invoke(args=["nested", "nested"])652 assert "nested_result" in result.output653654 result = app_runner.invoke(args=["merged"])655 assert "merged_result" in result.output656657 result = app_runner.invoke(args=["late_registration", "late"])658 assert "late_result" in result.output

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

lines 659–667why, one step back
659
660661def test_cli_empty(app):662 """If a Blueprint's CLI group is empty, do not register it."""663 bp = Blueprint("blue", __name__, cli_group="blue")664 app.register_blueprint(bp)665666 result = app.test_cli_runner().invoke(args=["blue", "--help"])667 assert result.exit_code == 2, "Unexpected success:\n\n" + result.output