Skip to content

Commit

Permalink
Increase code coverage by testing CLI functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nottrobin committed Feb 9, 2017
1 parent bd5f84f commit 2ac15f0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bin/documentation-builder
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Core modules
import locale
import sys

# Local modules
from ubuntudesign.documentation_builder import cli
Expand All @@ -13,5 +14,5 @@ if 'UTF-8' not in locale.getlocale():

if __name__ == "__main__":
# Run the CLI
cli.main()
cli.main(sys.argv[1:])

23 changes: 23 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# System
from shutil import rmtree

# Local modules
from ubuntudesign.documentation_builder.cli import main, parse_arguments


def test_parse_arguments():
arguments = parse_arguments([])

assert type(arguments) == dict

def test_main():
main(
[
'--base-directory',
'tests/fixtures/builder/base/',
'--output-path',
'doesnt/matter'
]
)
rmtree('doesnt')

10 changes: 5 additions & 5 deletions ubuntudesign/documentation_builder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .builder import Builder


def parse_arguments():
def parse_arguments(arguments):
"""
Parse command-line options for documentation-parser command-line script
"""
Expand Down Expand Up @@ -114,7 +114,7 @@ def parse_arguments():
help="Show the currently installed version of documentation-builder."
)

arguments = vars(parser.parse_args())
arguments = vars(parser.parse_args(arguments))

if arguments['version']:
print(
Expand All @@ -130,15 +130,15 @@ def parse_arguments():
return {name: value for name, value in arguments.items() if value}


def main():
def main(system_arguments):
"""
The starting point for the documentation-parser.
Intended to be run through the command-line.
"""

arguments = parse_arguments()
arguments = parse_arguments(system_arguments)
Builder(**arguments)


if __name__ == "__main__":
main()
main(sys.argv[1:])

0 comments on commit 2ac15f0

Please sign in to comment.