From 5639b38da32c2ca7768cc526901c698c612e865d Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Mon, 22 Feb 2021 21:38:15 +0100 Subject: [PATCH] test parse_args --- blag/blag.py | 6 +++--- tests/test_blag.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/blag/blag.py b/blag/blag.py index 884025c..a01a6af 100644 --- a/blag/blag.py +++ b/blag/blag.py @@ -32,12 +32,12 @@ def main(args=None): args.func(args) -def parse_args(args): +def parse_args(args=None): """Parse command line arguments. Paramters --------- - args : + args : List[str] optional parameters, used for testing Returns @@ -76,7 +76,7 @@ def parse_args(args): quickstart_parser = commands.add_parser('quickstart') quickstart_parser.set_defaults(func=quickstart) - return parser.parse_args() + return parser.parse_args(args) def get_config(configfile): diff --git a/tests/test_blag.py b/tests/test_blag.py index 01855d8..3fff868 100644 --- a/tests/test_blag.py +++ b/tests/test_blag.py @@ -16,3 +16,36 @@ def test_generate_feed(outdir): articles = [] blag.generate_feed(articles, outdir, ' ', ' ', ' ', ' ') assert os.path.exists(f'{outdir}/atom.xml') + + +def test_parse_args_build(): + # test default args + args = blag.parse_args(['build']) + assert args.input_dir == 'content' + assert args.output_dir == 'build' + assert args.template_dir == 'templates' + assert args.static_dir == 'static' + + # input dir + args = blag.parse_args(['build', '-i', 'foo']) + assert args.input_dir == 'foo' + args = blag.parse_args(['build', '--input-dir', 'foo']) + assert args.input_dir == 'foo' + + # output dir + args = blag.parse_args(['build', '-o', 'foo']) + assert args.output_dir == 'foo' + args = blag.parse_args(['build', '--output-dir', 'foo']) + assert args.output_dir == 'foo' + + # template dir + args = blag.parse_args(['build', '-t', 'foo']) + assert args.template_dir == 'foo' + args = blag.parse_args(['build', '--template-dir', 'foo']) + assert args.template_dir == 'foo' + + # static dir + args = blag.parse_args(['build', '-s', 'foo']) + assert args.static_dir == 'foo' + args = blag.parse_args(['build', '--static-dir', 'foo']) + assert args.static_dir == 'foo'