diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-07-30 11:10:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-30 11:10:06 -0400 |
commit | a5e52820df8da804347ef5a59519758f547bcb0f (patch) | |
tree | 0a61caf33de2637ea17143cd2f6cd63331a90cbb /tests/test_argparse_custom.py | |
parent | f419192b71f816952b4f160c6b97986a5b8c9fd9 (diff) | |
parent | 6ab2578ae14d4198f2d1c973c168d43611c7c1f3 (diff) | |
download | cmd2-git-a5e52820df8da804347ef5a59519758f547bcb0f.tar.gz |
Merge pull request #743 from python-cmd2/choices_exception
Added more validation to add_argument wrapper
Diffstat (limited to 'tests/test_argparse_custom.py')
-rw-r--r-- | tests/test_argparse_custom.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/tests/test_argparse_custom.py b/tests/test_argparse_custom.py index 6c6879c8..f5d45fd1 100644 --- a/tests/test_argparse_custom.py +++ b/tests/test_argparse_custom.py @@ -39,7 +39,7 @@ def fake_func(): pass -@pytest.mark.parametrize('args, is_valid', [ +@pytest.mark.parametrize('kwargs, is_valid', [ ({'choices': []}, True), ({'choices_function': fake_func}, True), ({'choices_method': fake_func}, True), @@ -50,14 +50,27 @@ def fake_func(): ({'choices_method': fake_func, 'completer_function': fake_func}, False), ({'choices_method': fake_func, 'completer_method': fake_func}, False), ]) -def test_apcustom_invalid_args(args, is_valid): +def test_apcustom_choices_params_count(kwargs, is_valid): parser = Cmd2ArgumentParser(prog='test') try: - parser.add_argument('name', **args) + parser.add_argument('name', **kwargs) assert is_valid except ValueError as ex: assert not is_valid - assert 'Only one of the following may be used' in str(ex) + assert 'Only one of the following parameters' in str(ex) + + +@pytest.mark.parametrize('kwargs', [ + ({'choices_function': fake_func}), + ({'choices_method': fake_func}), + ({'completer_function': fake_func}), + ({'completer_method': fake_func}) +]) +def test_apcustom_no_choices_when_nargs_is_0(kwargs): + with pytest.raises(TypeError) as excinfo: + parser = Cmd2ArgumentParser(prog='test') + parser.add_argument('name', action='store_true', **kwargs) + assert 'None of the following parameters can be used' in str(excinfo.value) def test_apcustom_usage(): |