fixed unmatched elif
Also update relevant test
This commit is contained in:
parent
f91aea2aa0
commit
41e08f4ccd
2 changed files with 11 additions and 4 deletions
|
|
@ -55,10 +55,10 @@ def prepare_exec_for_file(filename):
|
||||||
module = []
|
module = []
|
||||||
|
|
||||||
# Chop off file extensions or package markers
|
# Chop off file extensions or package markers
|
||||||
if filename.endswith('.py'):
|
if os.path.split(filename)[1] == '__init__.py':
|
||||||
filename = filename[:-3]
|
|
||||||
elif os.path.split(filename)[1] == '__init__.py':
|
|
||||||
filename = os.path.dirname(filename)
|
filename = os.path.dirname(filename)
|
||||||
|
elif filename.endswith('.py'):
|
||||||
|
filename = filename[:-3]
|
||||||
else:
|
else:
|
||||||
raise NoAppException('The file provided (%s) does exist but is not a '
|
raise NoAppException('The file provided (%s) does exist but is not a '
|
||||||
'valid Python file. This means that it cannot '
|
'valid Python file. This means that it cannot '
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ from click.testing import CliRunner
|
||||||
from flask import Flask, current_app
|
from flask import Flask, current_app
|
||||||
|
|
||||||
from flask.cli import AppGroup, FlaskGroup, NoAppException, ScriptInfo, \
|
from flask.cli import AppGroup, FlaskGroup, NoAppException, ScriptInfo, \
|
||||||
find_best_app, locate_app, with_appcontext
|
find_best_app, locate_app, with_appcontext, prepare_exec_for_file
|
||||||
|
|
||||||
|
|
||||||
def test_cli_name(test_apps):
|
def test_cli_name(test_apps):
|
||||||
|
|
@ -49,6 +49,13 @@ def test_find_best_app(test_apps):
|
||||||
pytest.raises(NoAppException, find_best_app, mod)
|
pytest.raises(NoAppException, find_best_app, mod)
|
||||||
|
|
||||||
|
|
||||||
|
def test_prepare_exec_for_file(test_apps):
|
||||||
|
assert prepare_exec_for_file('test.py') == 'test'
|
||||||
|
assert prepare_exec_for_file('/usr/share/__init__.py') == 'share'
|
||||||
|
with pytest.raises(NoAppException):
|
||||||
|
prepare_exec_for_file('test.txt')
|
||||||
|
|
||||||
|
|
||||||
def test_locate_app(test_apps):
|
def test_locate_app(test_apps):
|
||||||
"""Test of locate_app."""
|
"""Test of locate_app."""
|
||||||
assert locate_app("cliapp.app").name == "testapp"
|
assert locate_app("cliapp.app").name == "testapp"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue