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 8e039d4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 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()
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 8e039d4

Please sign in to comment.