More DRYing up the test suite (#2325)
This commit is contained in:
parent
50c6df7098
commit
4ec1fbc9f5
10 changed files with 230 additions and 283 deletions
|
|
@ -40,22 +40,27 @@ def test_cli_name(test_apps):
|
|||
def test_find_best_app(test_apps):
|
||||
"""Test if `find_best_app` behaves as expected with different combinations of input."""
|
||||
script_info = ScriptInfo()
|
||||
|
||||
class Module:
|
||||
app = Flask('appname')
|
||||
|
||||
assert find_best_app(script_info, Module) == Module.app
|
||||
|
||||
class Module:
|
||||
application = Flask('appname')
|
||||
|
||||
assert find_best_app(script_info, Module) == Module.application
|
||||
|
||||
class Module:
|
||||
myapp = Flask('appname')
|
||||
|
||||
assert find_best_app(script_info, Module) == Module.myapp
|
||||
|
||||
class Module:
|
||||
@staticmethod
|
||||
def create_app():
|
||||
return Flask('appname')
|
||||
|
||||
assert isinstance(find_best_app(script_info, Module), Flask)
|
||||
assert find_best_app(script_info, Module).name == 'appname'
|
||||
|
||||
|
|
@ -63,6 +68,7 @@ def test_find_best_app(test_apps):
|
|||
@staticmethod
|
||||
def create_app(foo):
|
||||
return Flask('appname')
|
||||
|
||||
assert isinstance(find_best_app(script_info, Module), Flask)
|
||||
assert find_best_app(script_info, Module).name == 'appname'
|
||||
|
||||
|
|
@ -70,6 +76,7 @@ def test_find_best_app(test_apps):
|
|||
@staticmethod
|
||||
def create_app(foo=None, script_info=None):
|
||||
return Flask('appname')
|
||||
|
||||
assert isinstance(find_best_app(script_info, Module), Flask)
|
||||
assert find_best_app(script_info, Module).name == 'appname'
|
||||
|
||||
|
|
@ -77,36 +84,44 @@ def test_find_best_app(test_apps):
|
|||
@staticmethod
|
||||
def make_app():
|
||||
return Flask('appname')
|
||||
|
||||
assert isinstance(find_best_app(script_info, Module), Flask)
|
||||
assert find_best_app(script_info, Module).name == 'appname'
|
||||
|
||||
class Module:
|
||||
myapp = Flask('appname1')
|
||||
|
||||
@staticmethod
|
||||
def create_app():
|
||||
return Flask('appname2')
|
||||
|
||||
assert find_best_app(script_info, Module) == Module.myapp
|
||||
|
||||
class Module:
|
||||
myapp = Flask('appname1')
|
||||
|
||||
@staticmethod
|
||||
def create_app():
|
||||
return Flask('appname2')
|
||||
|
||||
assert find_best_app(script_info, Module) == Module.myapp
|
||||
|
||||
class Module:
|
||||
pass
|
||||
|
||||
pytest.raises(NoAppException, find_best_app, script_info, Module)
|
||||
|
||||
class Module:
|
||||
myapp1 = Flask('appname1')
|
||||
myapp2 = Flask('appname2')
|
||||
|
||||
pytest.raises(NoAppException, find_best_app, script_info, Module)
|
||||
|
||||
class Module:
|
||||
@staticmethod
|
||||
def create_app(foo, bar):
|
||||
return Flask('appname2')
|
||||
|
||||
pytest.raises(NoAppException, find_best_app, script_info, Module)
|
||||
|
||||
|
||||
|
|
@ -163,10 +178,13 @@ def test_get_version(test_apps, capsys):
|
|||
"""Test of get_version."""
|
||||
from flask import __version__ as flask_ver
|
||||
from sys import version as py_ver
|
||||
|
||||
class MockCtx(object):
|
||||
resilient_parsing = False
|
||||
color = None
|
||||
|
||||
def exit(self): return
|
||||
|
||||
ctx = MockCtx()
|
||||
get_version(ctx, None, "test")
|
||||
out, err = capsys.readouterr()
|
||||
|
|
@ -191,6 +209,7 @@ def test_scriptinfo(test_apps):
|
|||
|
||||
def test_with_appcontext(runner):
|
||||
"""Test of with_appcontext."""
|
||||
|
||||
@click.command()
|
||||
@with_appcontext
|
||||
def testcmd():
|
||||
|
|
@ -205,6 +224,7 @@ def test_with_appcontext(runner):
|
|||
|
||||
def test_appgroup(runner):
|
||||
"""Test of with_appcontext."""
|
||||
|
||||
@click.group(cls=AppGroup)
|
||||
def cli():
|
||||
pass
|
||||
|
|
@ -234,6 +254,7 @@ def test_appgroup(runner):
|
|||
|
||||
def test_flaskgroup(runner):
|
||||
"""Test FlaskGroup."""
|
||||
|
||||
def create_app(info):
|
||||
return Flask("flaskgroup")
|
||||
|
||||
|
|
@ -252,6 +273,7 @@ def test_flaskgroup(runner):
|
|||
|
||||
def test_print_exceptions(runner):
|
||||
"""Print the stacktrace if the CLI."""
|
||||
|
||||
def create_app(info):
|
||||
raise Exception("oh no")
|
||||
return Flask("flaskgroup")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue