Skip to content

Commit

Permalink
Testing __main__
Browse files Browse the repository at this point in the history
  • Loading branch information
Suszyński Krzysztof committed Jun 6, 2018
1 parent 380cdc4 commit e37e382
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
5 changes: 0 additions & 5 deletions puppeter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ def get_logger(cls):

def __fullname(cls):
return cls.__module__ + "." + cls.__name__


if __name__ == '__main__':
from puppeter.main import main
main()
4 changes: 3 additions & 1 deletion puppeter/__main__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from puppeter.main import main
main()

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def find_version(*file_paths):
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version=find_version('puppeter', '__init__.py'),
version=find_version('puppeter', '__main__.py'),

description='Puppeter - an automatic puppet installer',
# Get the long description from the README file
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# the inclusion of the tests module is not meant to offer best practices for
# testing in general, but rather to support the `find_packages` example in
# setup.py that excludes installing the "tests" package

21 changes: 21 additions & 0 deletions tests/test__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import re

import pytest

from tests.helpers.commandline import captured_output


def test_usage_printout():
from puppeter import __main__

with pytest.raises(SystemExit) as sysexit:
with captured_output() as (out, err):
__main__.main(['puppeter', '--help'])

stdout = out.getvalue().strip()
stderr = err.getvalue().strip()
assert sysexit.value.code == 0
assert stdout == ''
assert re.compile('Puppeter', re.MULTILINE).search(stderr)
assert re.compile('--answers FILE, -a FILE', re.MULTILINE).search(stderr)
assert re.compile('--execute, -e', re.MULTILINE).search(stderr)

0 comments on commit e37e382

Please sign in to comment.