Skip to content

Commit beaf598

Browse files
add tests
1 parent 92b6c95 commit beaf598

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

index_generator/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from jinja2.exceptions import TemplateNotFound
1010
from index_generator.models.entries import Entry
11-
from index_generator.models.exceptions import IndexGeneratorTemplateNotFound
11+
from index_generator.models.exceptions import IndexGeneratorTemplateNotFound, IndexGeneratorPathNotExists
1212
from . import APP_NAME, APP_URL, APP_VERSION
1313

1414
indexIgnore = ('index.html', 'images', 'favicon.ico')
@@ -51,6 +51,8 @@ def app(args):
5151
print('Usage: index-generator [OPTIONS] PATH.')
5252
print('See: index-generator --help')
5353
sys.exit(0)
54+
if not os.path.exists(args.path):
55+
raise IndexGeneratorPathNotExists('Path does not exists')
5456
if args.no_recursive:
5557
os.chdir(args.path)
5658
generate_once(args.theme, '.', os.listdir('.'), args.name, args.print, base=args.root, human=args.human,

index_generator/models/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ def __init__(self, message, hint='Something went wrong.'):
77
class IndexGeneratorTemplateNotFound(IndexGeneratorBaseException):
88
def __init__(self, message):
99
super().__init__(message, hint='Template folder does not exists or template file is not found.')
10+
11+
12+
class IndexGeneratorPathNotExists(IndexGeneratorBaseException):
13+
def __init__(self, message):
14+
super().__init__(message, hint='Target path does not exists.')

tests/test_main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,21 @@ def test_app_missing_argument(capfd):
1919
main()
2020
out, _ = capfd.readouterr()
2121
assert out == APP_NAME + ' ' + APP_VERSION + ' ' + APP_URL + "\nUsage: index-generator [OPTIONS] PATH.\nSee: index-generator --help\n"
22+
23+
24+
def test_app_template_not_found(capfd):
25+
sys.argv = ['index_generator', '--template', '/tmp/not_existed', '/tmp']
26+
main()
27+
out, _ = capfd.readouterr()
28+
assert 'IndexGeneratorTemplateNotFound' in out
29+
sys.argv = ['index_generator', '-T', '/tmp/not_existed', '/tmp']
30+
main()
31+
out, _ = capfd.readouterr()
32+
assert 'IndexGeneratorTemplateNotFound' in out
33+
34+
35+
def test_app_path_not_exists(capfd):
36+
sys.argv = ['index_generator', '/tmp/not_existed']
37+
main()
38+
out, _ = capfd.readouterr()
39+
assert 'IndexGeneratorPathNotExists' in out

0 commit comments

Comments
 (0)