diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-16 18:45:54 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-16 18:45:54 -0400 |
commit | 7e8d25db8a27c732e3f59b614dda2a91d76254aa (patch) | |
tree | 54440de6df9ce69bb3fc7cc1c61211e46cd7879d /tests/test_argparse_completer.py | |
parent | 348b86655ac6133179f7d94ca9558e0ae404a548 (diff) | |
download | cmd2-git-7e8d25db8a27c732e3f59b614dda2a91d76254aa.tar.gz |
Added unit tests to cover invalid subcommand names in completions
Diffstat (limited to 'tests/test_argparse_completer.py')
-rw-r--r-- | tests/test_argparse_completer.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py index 19ec551b..e690f90a 100644 --- a/tests/test_argparse_completer.py +++ b/tests/test_argparse_completer.py @@ -250,7 +250,10 @@ def test_help(ac_app, command): @pytest.mark.parametrize('command, text, completions', [ ('', 'mu', ['music ']), ('music', 'cre', ['create ']), - ('music create', '', ['jazz', 'rock']) + ('music', 'creab', []), + ('music create', '', ['jazz', 'rock']), + ('music crea', 'jazz', []), + ('music create', 'foo', []) ]) def test_complete_help(ac_app, command, text, completions): line = 'help {} {}'.format(command, text) @@ -266,6 +269,26 @@ def test_complete_help(ac_app, command, text, completions): assert ac_app.completion_matches == sorted(completions, key=ac_app.default_sort_key) +@pytest.mark.parametrize('subcommand, text, completions', [ + ('create', '', ['jazz', 'rock']), + ('create', 'ja', ['jazz ']), + ('create', 'foo', []), + ('creab', 'ja', []) +]) +def test_subcommand_completions(ac_app, subcommand, text, completions): + line = 'music {} {}'.format(subcommand, text) + endidx = len(line) + begidx = endidx - len(text) + + first_match = complete_tester(text, line, begidx, endidx, ac_app) + if completions: + assert first_match is not None + else: + assert first_match is None + + assert ac_app.completion_matches == sorted(completions, key=ac_app.default_sort_key) + + @pytest.mark.parametrize('command_and_args, text, completions', [ # Complete all flags (suppressed will not show) ('flag', '-', ['--append_const_flag', '--append_flag', '--count_flag', '--help', '--normal_flag', |