Test args
This commit is contained in:
parent
f45f551bdf
commit
392703e3cb
2 changed files with 24 additions and 2 deletions
|
@ -2,10 +2,10 @@ import argparse
|
||||||
from md_pdf import __version__
|
from md_pdf import __version__
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args(args=None):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-v", "--verbose", help="Set verbosity level (repeat argument)", action="count", default=0)
|
parser.add_argument("-v", "--verbose", help="Set verbosity level (repeat argument)", action="count", default=0)
|
||||||
parser.add_argument("--update-csl", help="Update CSL files", action="store_true")
|
parser.add_argument("--update-csl", help="Update CSL files", action="store_true")
|
||||||
parser.add_argument("--version", action="version", version="%(prog)s {}".format(__version__))
|
parser.add_argument("--version", action="version", version="%(prog)s {}".format(__version__))
|
||||||
parser.add_help = True
|
parser.add_help = True
|
||||||
return parser.parse_args()
|
return parser.parse_args(args=args)
|
||||||
|
|
22
tests/test_args.py
Normal file
22
tests/test_args.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
from tests import BaseTestCase
|
||||||
|
from md_pdf.args import parse_args
|
||||||
|
|
||||||
|
|
||||||
|
class ArgParserTestCase(BaseTestCase):
|
||||||
|
def test_allows_no_args(self):
|
||||||
|
args = parse_args([])
|
||||||
|
self.assertFalse(args.update_csl)
|
||||||
|
self.assertEqual(args.verbose, 0)
|
||||||
|
|
||||||
|
def test_adds_verbosity(self):
|
||||||
|
args = parse_args(['-v'])
|
||||||
|
self.assertEqual(args.verbose, 1)
|
||||||
|
|
||||||
|
def test_chains_verbosity(self):
|
||||||
|
for i in range(1, 10):
|
||||||
|
args = parse_args(['-' + ('v' * i)])
|
||||||
|
self.assertEqual(args.verbose, i)
|
||||||
|
|
||||||
|
def test_csl_update(self):
|
||||||
|
args = parse_args(['--update-csl'])
|
||||||
|
self.assertTrue(args.update_csl)
|
Reference in a new issue