Browse Source

Merge pull request #2963 from garenchan/bugfix-#2961

Fix #2961:ignore colon followed by slash when split app_import_path
pull/2966/head
David Lord 6 years ago committed by GitHub
parent
commit
0038a6796f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      flask/cli.py
  2. 19
      tests/test_cli.py

2
flask/cli.py

@ -369,7 +369,7 @@ class ScriptInfo(object):
app = call_factory(self, self.create_app) app = call_factory(self, self.create_app)
else: else:
if self.app_import_path: if self.app_import_path:
path, name = (self.app_import_path.split(':', 1) + [None])[:2] path, name = (re.split(r':(?![\\/])', self.app_import_path, 1) + [None])[:2]
import_name = prepare_import(path) import_name = prepare_import(path)
app = locate_app(self, import_name, name) app = locate_app(self, import_name, name)
else: else:

19
tests/test_cli.py

@ -261,8 +261,21 @@ def test_get_version(test_apps, capsys):
def test_scriptinfo(test_apps, monkeypatch): def test_scriptinfo(test_apps, monkeypatch):
"""Test of ScriptInfo.""" """Test of ScriptInfo."""
obj = ScriptInfo(app_import_path="cliapp.app:testapp") obj = ScriptInfo(app_import_path="cliapp.app:testapp")
assert obj.load_app().name == "testapp" app = obj.load_app()
assert obj.load_app().name == "testapp" assert app.name == "testapp"
assert obj.load_app() is app
# import app with module's absolute path
cli_app_path = os.path.abspath(os.path.join(
os.path.dirname(__file__), 'test_apps', 'cliapp', 'app.py'))
obj = ScriptInfo(app_import_path=cli_app_path)
app = obj.load_app()
assert app.name == 'testapp'
assert obj.load_app() is app
obj = ScriptInfo(app_import_path=cli_app_path + ':testapp')
app = obj.load_app()
assert app.name == 'testapp'
assert obj.load_app() is app
def create_app(info): def create_app(info):
return Flask("createapp") return Flask("createapp")
@ -270,7 +283,7 @@ def test_scriptinfo(test_apps, monkeypatch):
obj = ScriptInfo(create_app=create_app) obj = ScriptInfo(create_app=create_app)
app = obj.load_app() app = obj.load_app()
assert app.name == "createapp" assert app.name == "createapp"
assert obj.load_app() == app assert obj.load_app() is app
obj = ScriptInfo() obj = ScriptInfo()
pytest.raises(NoAppException, obj.load_app) pytest.raises(NoAppException, obj.load_app)

Loading…
Cancel
Save