summaryrefslogtreecommitdiff
path: root/tests/test_argparse_completer.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-10 16:46:36 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-10 16:46:36 -0400
commit2ef1f27bdd599a47f34f186fddb3b5550352e04b (patch)
tree43face94b0e44d1cc0b520193587d8c025ff6977 /tests/test_argparse_completer.py
parent734fee811025a8f1a68d985907649937ac42a629 (diff)
downloadcmd2-git-2ef1f27bdd599a47f34f186fddb3b5550352e04b.tar.gz
Added unit tests
Diffstat (limited to 'tests/test_argparse_completer.py')
-rw-r--r--tests/test_argparse_completer.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py
index cf4ac7b3..5c6b750f 100644
--- a/tests/test_argparse_completer.py
+++ b/tests/test_argparse_completer.py
@@ -21,7 +21,8 @@ choices_from_method = ['choices', 'method', 'most', 'improved']
set_value_choices = ['set', 'value', 'choices']
one_or_more_choices = ['one', 'or', 'more', 'choices']
-optional_choices = ['optional', 'choices']
+optional_choices = ['a', 'few', 'optional', 'choices']
+range_choices = ['some', 'range', 'choices']
remainder_choices = ['remainder', 'choices']
completions_from_function = ['completions', 'function', 'fairly', 'complete']
@@ -195,6 +196,8 @@ class AutoCompleteTester(cmd2.Cmd):
choices=one_or_more_choices)
nargs_parser.add_argument("--optional", help="a flag with an optional value", nargs=argparse.OPTIONAL,
choices=optional_choices)
+ nargs_parser.add_argument("--range", help="a flag with nargs range", nargs=(1, 2),
+ choices=range_choices)
nargs_parser.add_argument("--remainder", help="a flag wanting remaining", nargs=argparse.REMAINDER,
choices=remainder_choices)
@@ -446,6 +449,19 @@ def test_completion_items(ac_app, num_aliases, show_description):
('--one_or_more', one_or_more_choices),
('--one_or_more one', ['or', 'more', 'choices']),
+ # Flag with nargs = OPTIONAL
+ ('--optional', optional_choices),
+
+ # Only one arg allowed for an OPTIONAL to completions are now empty
+ ('--optional optional', []),
+
+ # Flag with nargs range (1, 2)
+ ('--range', range_choices),
+ ('--range some', ['range', 'choices']),
+
+ # Already used 2 args so no more completions
+ ('--range some range', []),
+
# Flag with nargs = REMAINDER
('--remainder', remainder_choices),
('--remainder remainder ', ['choices ']),