diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-07 23:02:00 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-07 23:02:00 -0400 |
commit | d9a48462c90807a4a8e8c5d646a62d1bd883529f (patch) | |
tree | 6adb994c0c7c2302eb1f3c735014051856c0d85c /tests/test_argparse_completer.py | |
parent | 8d3d59801ca690f718ed9814c9e124e27040c141 (diff) | |
download | cmd2-git-d9a48462c90807a4a8e8c5d646a62d1bd883529f.tar.gz |
More unit tests
Diffstat (limited to 'tests/test_argparse_completer.py')
-rw-r--r-- | tests/test_argparse_completer.py | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py index fd43c91c..1b6d1f4b 100644 --- a/tests/test_argparse_completer.py +++ b/tests/test_argparse_completer.py @@ -87,6 +87,18 @@ class AutoCompleteTester(cmd2.Cmd): self.do_help('music') ############################################################################################################ + # Begin code related to flag completion + ############################################################################################################ + flag_parser = Cmd2ArgParser() + flag_parser.add_argument('-n', '--normal_flag', help='A normal flag', action='store_true') + flag_parser.add_argument('-o', '--other_normal_flag', help='The other normal flag', action='store_true') + flag_parser.add_argument('-s', '--suppressed_flag', help=argparse.SUPPRESS, action='store_true') + + @with_argparser(flag_parser) + def do_flag(self, args: argparse.Namespace) -> None: + pass + + ############################################################################################################ # Begin code related to testing choices, choices_function, and choices_method parameters ############################################################################################################ def choices_method(self) -> List[str]: @@ -199,19 +211,30 @@ def test_complete_help(ac_app, command, text, completions): assert first_match is not None and ac_app.completion_matches == completions -@pytest.mark.parametrize('text, completions', [ - ('-', ['--function', '--help', '--list', '--method', '--no_header', '-f', '-h', '-l', '-m', '-n']), - ('--', ['--function', '--help', '--list', '--method', '--no_header']), - ('-f', ['-f ']), - ('--f', ['--function ']), +@pytest.mark.parametrize('used_flags, text, completions', [ + ('', '-', ['--help', '--normal_flag', '--other_normal_flag', '-h', '-n', '-o']), + ('', '--', ['--help', '--normal_flag', '--other_normal_flag']), + ('', '-n', ['-n ']), + ('', '--n', ['--normal_flag ']), + ('', '-s', []), + ('', '--s', []), + ('-h', '-', ['--normal_flag', '--other_normal_flag', '-n', '-o']), + ('-h --normal_flag', '-', ['--other_normal_flag', '-o']), + ('-h --normal_flag', '--', ['--other_normal_flag ']), + ('-h --normal_flag -o', '-', []), ]) -def test_autcomp_flag_completion(ac_app, text, completions): - line = 'choices {}'.format(text) +def test_autcomp_flag_completion(ac_app, used_flags, text, completions): + line = 'flag {} {}'.format(used_flags, text) endidx = len(line) begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, ac_app) - assert first_match is not None and ac_app.completion_matches == completions + if completions: + assert first_match is not None + else: + assert first_match is None + + assert ac_app.completion_matches == completions @pytest.mark.parametrize('flag, text, completions', [ |