Skip to content

Commit

Permalink
Refactor main tests and pass argv explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Jan 9, 2014
1 parent bdac1ea commit 45e486c
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 151 deletions.
29 changes: 20 additions & 9 deletions doc2dash/__main__.py
@@ -1,3 +1,5 @@
from __future__ import absolute_import, division, print_function

import argparse
import errno
import logging
Expand All @@ -17,8 +19,10 @@
)


def main():
"""Main cli entry point."""
def main(argv):
"""
Main cli entry point.
"""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'source',
Expand Down Expand Up @@ -73,7 +77,7 @@ def main():
'--index-page', '-I',
help='set index html file for docset'
)
args = parser.parse_args()
args = parser.parse_args(args=argv)

if args.icon and not args.icon.endswith('.png'):
print('Please supply a PNG icon.')
Expand Down Expand Up @@ -126,7 +130,9 @@ def main():


def determine_log_level(args):
"""We use logging's levels as an easy-to-use verbosity controller."""
"""
We use logging's levels as an easy-to-use verbosity controller.
"""
if args.verbose and args.quiet:
raise ValueError("Supplying both --quiet and --verbose doesn't make "
"sense.")
Expand All @@ -140,7 +146,9 @@ def determine_log_level(args):


def setup_paths(args):
"""Determine source and destination using the results of argparse."""
"""
Determine source and destination using the results of argparse.
"""
source = args.source
if not args.name:
args.name = os.path.split(source)[-1]
Expand All @@ -166,10 +174,10 @@ def setup_paths(args):


def prepare_docset(args, dest):
"""Create boilerplate files & directories and copy vanilla docs inside.
"""
Create boilerplate files & directories and copy vanilla docs inside.
Return a tuple of path to resources and connection to sqlite db.
"""
resources = os.path.join(dest, 'Contents/Resources/')
docs = os.path.join(resources, 'Documents')
Expand Down Expand Up @@ -203,8 +211,11 @@ def prepare_docset(args, dest):


def add_icon(icon, dest):
"""Add icon to docset"""
"""
Add icon to docset
"""
shutil.copy2(icon, os.path.join(dest, 'icon.png'))


if __name__ == '__main__':
main() # pragma: nocover
main(sys.argv[1:]) # pragma: nocover

0 comments on commit 45e486c

Please sign in to comment.