From 6e0b200661291cc9acba5a2a33ee0f059a10f56d Mon Sep 17 00:00:00 2001 From: The Metaist Date: Thu, 12 Sep 2024 22:31:16 -0400 Subject: [PATCH] add: arg tests (#1) --- test/test_args.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/test_args.py b/test/test_args.py index 95fabb9..02e9a05 100644 --- a/test/test_args.py +++ b/test/test_args.py @@ -1,8 +1,37 @@ """Test arg parsing.""" +# std +from pathlib import Path +from shlex import split + +# lib +import pytest + +# pkg from cosmofy.args import Args def test_empty() -> None: """Empty args.""" assert Args.parse([]) == Args() + + +def test_basic() -> None: + """Basic flags.""" + assert Args.parse( + split("--clone --args '-m foo' --output bar/baz src/repo") + ) == Args(clone=True, args="-m foo", output=Path("bar/baz"), add=["src/repo"]) + + +def test_disable_cache() -> None: + """Disable cache.""" + assert Args.parse(split("--cache 0")) == Args(cache=None) + assert Args.parse(split("--cache false")) == Args(cache=None) + assert Args.parse(split("--cache False")) == Args(cache=None) + assert Args.parse(split("--cache FALSE")) == Args(cache=None) + + +def test_bad_arg() -> None: + """Bad arg.""" + with pytest.raises(ValueError): + Args.parse(["--unknown"])