Browse Source

Adding a few tests for console.py

pull/3/head
Ryan Reed 2 years ago
parent
commit
b2e292dc24
2 changed files with 46 additions and 2 deletions
  1. +2
    -2
      src/transpose/console.py
  2. +44
    -0
      tests/test_console.py

+ 2
- 2
src/transpose/console.py View File

@ -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__":


+ 44
- 0
tests/test_console.py View File

@ -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"

Loading…
Cancel
Save