diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-03-02 17:14:42 -0500 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-03-02 17:21:25 -0500 |
| commit | 5732bc3cc7a9e97b496006c90eaf07a55ee35095 (patch) | |
| tree | b92111657b64943bb3114820a712908fe5d79d80 /tests | |
| parent | cc9d96a7c5309bec64856e4dd9554d2cee235d23 (diff) | |
| download | cmd2-git-5732bc3cc7a9e97b496006c90eaf07a55ee35095.tar.gz | |
Fixed issue where argparse choices could not be CompletionItems
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_argparse_completer.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py index 75f24b3e..6002a856 100644 --- a/tests/test_argparse_completer.py +++ b/tests/test_argparse_completer.py @@ -107,6 +107,7 @@ class ArgparseCompleterTester(cmd2.Cmd): int_choices = [-1, 1, -2, 2, 0, -12] static_choices_list = ['static', 'choices', 'stop', 'here'] choices_from_provider = ['choices', 'provider', 'probably', 'improved'] + completion_item_choices = [CompletionItem('choice_1', 'A description'), CompletionItem('choice_2', 'Another description')] def choices_provider(self) -> List[str]: """Method that provides choices""" @@ -150,6 +151,7 @@ class ArgparseCompleterTester(cmd2.Cmd): nargs=argparse.ONE_OR_MORE, ) choices_parser.add_argument('-i', '--int', type=int, help='a flag with an int type', choices=int_choices) + choices_parser.add_argument('--completion_items', help='choices are CompletionItems', choices=completion_item_choices) # Positional args for choices command choices_parser.add_argument("list_pos", help="a positional populated with a choices list", choices=static_choices_list) @@ -729,6 +731,23 @@ def test_completion_items(ac_app, num_aliases, show_description): assert 'help' in first_result_line +def test_completion_item_choices(ac_app): + text = '' + line = 'choices --completion_items {}'.format(text) + endidx = len(line) + begidx = endidx - len(text) + + first_match = complete_tester(text, line, begidx, endidx, ac_app) + assert first_match is not None + assert len(ac_app.completion_matches) == len(ac_app.completion_item_choices) + assert len(ac_app.display_matches) == len(ac_app.completion_item_choices) + + # Make sure a completion table was created + first_result_line = normalize(ac_app.formatted_completions)[1] + assert 'choice_1' in first_result_line + assert 'A description' in first_result_line + + @pytest.mark.parametrize( 'args, completions', [ |
