From b2e292dc24184f7e4e004ca72e6938b5ece3d5eb Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Sun, 3 Jul 2022 18:18:43 -0400 Subject: [PATCH] Adding a few tests for console.py --- src/transpose/console.py | 4 ++-- tests/test_console.py | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/test_console.py diff --git a/src/transpose/console.py b/src/transpose/console.py index 97bdc18..abd02a0 100644 --- a/src/transpose/console.py +++ b/src/transpose/console.py @@ -24,7 +24,7 @@ def entry_point() -> None: t.store(name=args.name) -def parse_arguments(): +def parse_arguments(args=None): base_parser = argparse.ArgumentParser(add_help=False) parser = argparse.ArgumentParser( parents=[base_parser], @@ -70,7 +70,7 @@ def parse_arguments(): help="The path to the directory to be stored", ) - return parser.parse_args() + return parser.parse_args(args) if __name__ == "__main__": diff --git a/tests/test_console.py b/tests/test_console.py new file mode 100644 index 0000000..4fe4b30 --- /dev/null +++ b/tests/test_console.py @@ -0,0 +1,44 @@ +import pytest + +from transpose.console import parse_arguments + + +def test_parse_arguments(): + # Missing required argument - action + with pytest.raises(SystemExit): + parse_arguments() + + +def test_parse_arguments_apply(): + # Missing required argument - target_path (Apply) + with pytest.raises(SystemExit): + args = parse_arguments(["apply"]) + + args = parse_arguments(["apply", "/tmp/some/path"]) + assert args.action == "apply" + assert args.target_path == "/tmp/some/path" + + +def test_parse_arguments_store(): + # Missing required argument - name (Store) + with pytest.raises(SystemExit): + args = parse_arguments(["store"]) + + # Missing required argument - target_path (Store) + with pytest.raises(SystemExit): + args = parse_arguments(["store", "My Name"]) + + args = parse_arguments(["store", "My Name", "/tmp/some/path"]) + assert args.action == "store" + assert args.name == "My Name" + assert args.target_path == "/tmp/some/path" + + +def test_parse_arguments_restore(): + # Missing required argument - target_path (Restore) + with pytest.raises(SystemExit): + args = parse_arguments(["restore"]) + + args = parse_arguments(["restore", "/tmp/some/path"]) + assert args.action == "restore" + assert args.target_path == "/tmp/some/path"