diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2023-02-19 04:33:46 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2023-02-19 04:33:46 -0600 |
commit | b2fbb532e359985142a71354b5b648ae560a80ac (patch) | |
tree | 89ef6ea7a9e39f94845d5eca7855e1e32489759e /tests/test_arg_parser.py | |
parent | c4bafa375d8aa387201a6f622aff3d22f1753b31 (diff) |
add final arg parser tests, refactor pyssg error msgs
Diffstat (limited to 'tests/test_arg_parser.py')
-rw-r--r-- | tests/test_arg_parser.py | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/tests/test_arg_parser.py b/tests/test_arg_parser.py index 45263ce..1a5b48c 100644 --- a/tests/test_arg_parser.py +++ b/tests/test_arg_parser.py @@ -1,16 +1,43 @@ +import sys import pytest +from unittest.mock import patch from argparse import ArgumentParser +# these tests don't really show any coverage, so not sure how useful they're +# but I'm including them as at least these should work @pytest.mark.parametrize('args, arg_name, exp_result', [ (['--version'], 'version', True), (['-v'], 'version', True), + # config really just inputs a string (['--config', 'value'], 'config', 'value'), (['-c', 'value'], 'config', 'value'), + (['--copy-default-config'], 'copy_default_config', True), + (['--init'], 'init', True), + (['-i'], 'init', True), + (['--build'], 'build', True), + (['-b'], 'build', True), + (['--debug'], 'debug', True) ]) -def test_individual_args(args: list[str], - arg_name: str, - exp_result: str | bool, - arg_parser: ArgumentParser) -> None: - parsed_args: dict[str, str | bool] = vars(arg_parser.parse_args(args)) - assert parsed_args[arg_name] == exp_result +def test_valid_args(args: list[str], + arg_name: str, + exp_result: str | bool, + arg_parser: ArgumentParser) -> None: + with patch.object(sys, 'argv', ['pyssg'] + args): + parsed_args: dict[str, str | bool] = vars(arg_parser.parse_args()) + assert parsed_args[arg_name] == exp_result + + +@pytest.mark.parametrize('args', [ + (['--something-random']), + (['-z']), + (['hello']), + (['help']), + (['h']) +]) +def test_invalid_args(args: list[str], + arg_parser: ArgumentParser) -> None: + with pytest.raises(SystemExit) as system_exit: + arg_parser.parse_args(args) + assert system_exit.type == SystemExit + assert system_exit.value.code == 2 |