summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-08-05 22:40:09 -0400
committerGitHub <noreply@github.com>2019-08-05 22:40:09 -0400
commit0f9fcfcd95ee7fd30ebddabbf2068d8ddb725364 (patch)
treea792e8fa8536ee380b3c9bc6b5ee738d5dc4119b /tests
parent4aa8370092d1aba5edaf77bf9a867b23adf4aa97 (diff)
parent0ffe33dc19128ae138c495d6896b538105dcf5b9 (diff)
downloadcmd2-git-0f9fcfcd95ee7fd30ebddabbf2068d8ddb725364.tar.gz
Merge pull request #750 from python-cmd2/support_custom_actions
Added functions to manually add choice providing functions to an argparse action
Diffstat (limited to 'tests')
-rw-r--r--tests/test_argparse_custom.py25
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():