diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-08-05 17:27:23 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-08-05 17:27:23 -0400 |
commit | 978dcbc027a21d2ad152ac2c4b9f761f8e769fbb (patch) | |
tree | 8c00b2bcae70fb28b300b50d9f6b67aba2f6fbff /tests/test_argparse_custom.py | |
parent | 4aa8370092d1aba5edaf77bf9a867b23adf4aa97 (diff) | |
download | cmd2-git-978dcbc027a21d2ad152ac2c4b9f761f8e769fbb.tar.gz |
Added functions to manually add choice providing functions to an argparse action.
Diffstat (limited to 'tests/test_argparse_custom.py')
-rw-r--r-- | tests/test_argparse_custom.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/tests/test_argparse_custom.py b/tests/test_argparse_custom.py index f5d45fd1..99afe2dd 100644 --- a/tests/test_argparse_custom.py +++ b/tests/test_argparse_custom.py @@ -40,17 +40,15 @@ def fake_func(): @pytest.mark.parametrize('kwargs, is_valid', [ - ({'choices': []}, True), ({'choices_function': fake_func}, True), ({'choices_method': fake_func}, True), ({'completer_function': fake_func}, True), ({'completer_method': fake_func}, True), - ({'choices': [], 'choices_function': fake_func}, False), - ({'choices': [], 'choices_method': fake_func}, False), + ({'choices_function': fake_func, 'choices_method': fake_func}, False), ({'choices_method': fake_func, 'completer_function': fake_func}, False), - ({'choices_method': fake_func, 'completer_method': fake_func}, False), + ({'completer_function': fake_func, 'completer_method': fake_func}, False), ]) -def test_apcustom_choices_params_count(kwargs, is_valid): +def test_apcustom_choices_callable_count(kwargs, is_valid): parser = Cmd2ArgumentParser(prog='test') try: parser.add_argument('name', **kwargs) @@ -66,11 +64,24 @@ def test_apcustom_choices_params_count(kwargs, is_valid): ({'completer_function': fake_func}), ({'completer_method': fake_func}) ]) -def test_apcustom_no_choices_when_nargs_is_0(kwargs): +def test_apcustom_no_choices_callables_alongside_choices(kwargs): + with pytest.raises(TypeError) as excinfo: + parser = Cmd2ArgumentParser(prog='test') + parser.add_argument('name', choices=['my', 'choices', 'list'], **kwargs) + assert 'None of the following parameters can be used alongside a choices parameter' in str(excinfo.value) + + +@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_callables_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) + assert 'None of the following parameters can be used on an action that takes no arguments' in str(excinfo.value) def test_apcustom_usage(): |