Skip to content

Commit 41e08f4

Browse files
jphilipsen05untitaker
authored andcommitted
fixed unmatched elif
Also update relevant test
1 parent f91aea2 commit 41e08f4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

flask/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def prepare_exec_for_file(filename):
5555
module = []
5656

5757
# Chop off file extensions or package markers
58-
if filename.endswith('.py'):
59-
filename = filename[:-3]
60-
elif os.path.split(filename)[1] == '__init__.py':
58+
if os.path.split(filename)[1] == '__init__.py':
6159
filename = os.path.dirname(filename)
60+
elif filename.endswith('.py'):
61+
filename = filename[:-3]
6262
else:
6363
raise NoAppException('The file provided (%s) does exist but is not a '
6464
'valid Python file. This means that it cannot '

tests/test_cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from flask import Flask, current_app
2020

2121
from flask.cli import AppGroup, FlaskGroup, NoAppException, ScriptInfo, \
22-
find_best_app, locate_app, with_appcontext
22+
find_best_app, locate_app, with_appcontext, prepare_exec_for_file
2323

2424

2525
def test_cli_name(test_apps):
@@ -49,6 +49,13 @@ class mod:
4949
pytest.raises(NoAppException, find_best_app, mod)
5050

5151

52+
def test_prepare_exec_for_file(test_apps):
53+
assert prepare_exec_for_file('test.py') == 'test'
54+
assert prepare_exec_for_file('/usr/share/__init__.py') == 'share'
55+
with pytest.raises(NoAppException):
56+
prepare_exec_for_file('test.txt')
57+
58+
5259
def test_locate_app(test_apps):
5360
"""Test of locate_app."""
5461
assert locate_app("cliapp.app").name == "testapp"

0 commit comments

Comments
 (0)