diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-10-10 19:09:22 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-10-10 19:09:22 -0400 |
commit | ebd6668db1a4a1dfcf2937559f2fbe5a4f58dc48 (patch) | |
tree | 84ca344b8f0c1fb489d3ecea30a7e6392f0500d8 /tests/test_autocompletion.py | |
parent | 9b43502ab70d1bd013a4cdede4805c2c0819c8c4 (diff) | |
download | cmd2-git-ebd6668db1a4a1dfcf2937559f2fbe5a4f58dc48.tar.gz |
Fixed issue where flag at beginning of REMAINDER section was tab completing
Diffstat (limited to 'tests/test_autocompletion.py')
-rw-r--r-- | tests/test_autocompletion.py | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/tests/test_autocompletion.py b/tests/test_autocompletion.py index 34155d88..7285af5c 100644 --- a/tests/test_autocompletion.py +++ b/tests/test_autocompletion.py @@ -279,20 +279,29 @@ def test_autcomp_custom_func_list_and_dict_arg(cmd2_app): cmd2_app.completion_matches == ['S01E02', 'S01E03', 'S02E01', 'S02E03'] -def test_argparse_remainder_completion(cmd2_app): +def test_argparse_remainder_flag_completion(cmd2_app): import cmd2 import argparse - # First test a positional with nargs=argparse.REMAINDER + # Test flag completion as first arg of positional with nargs=argparse.REMAINDER + text = '--h' + line = 'help command {}'.format(text) + endidx = len(line) + begidx = endidx - len(text) + + # --h should not complete into --help because we are in the argparse.REMAINDER section + assert complete_tester(text, line, begidx, endidx, cmd2_app) is None + + # Test flag completion within an already started positional with nargs=argparse.REMAINDER text = '--h' line = 'help command subcommand {}'.format(text) endidx = len(line) begidx = endidx - len(text) - # --h should not complete into --help because we are in the argparse.REMAINDER sections + # --h should not complete into --help because we are in the argparse.REMAINDER section assert complete_tester(text, line, begidx, endidx, cmd2_app) is None - # Now test a flag with nargs=argparse.REMAINDER + # Test a flag with nargs=argparse.REMAINDER parser = argparse.ArgumentParser() parser.add_argument('-f', nargs=argparse.REMAINDER) @@ -304,18 +313,24 @@ def test_argparse_remainder_completion(cmd2_app): endidx = len(line) begidx = endidx - len(text) - # --h should not complete into --help because we are in the argparse.REMAINDER sections + # --h should not complete into --help because we are in the argparse.REMAINDER section assert complete_tester(text, line, begidx, endidx, cmd2_app) is None def test_completion_after_double_dash(cmd2_app): - # Test -- as the last token before an argparse.REMAINDER sections + """ + Test completion after --, which argparse says (all args after -- are non-options) + All of these tests occur outside of an argparse.REMAINDER section since those tests + are handled in test_argparse_remainder_flag_completion + """ + + # Test -- as the last token text = '--' line = 'help {}'.format(text) endidx = len(line) begidx = endidx - len(text) - # Since -- is the last token in a non-remainder section, then it should show flag choices + # Since -- is the last token, then it should show flag choices first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and '--help' in cmd2_app.completion_matches @@ -325,5 +340,5 @@ def test_completion_after_double_dash(cmd2_app): endidx = len(line) begidx = endidx - len(text) - # Since -- appeared before the -- being completed, no more flags should be completed + # Since -- appeared before the -- being completed, nothing should be completed assert complete_tester(text, line, begidx, endidx, cmd2_app) is None |