@@ -279,20 +279,29 @@ def test_autcomp_custom_func_list_and_dict_arg(cmd2_app):
279279 cmd2_app .completion_matches == ['S01E02' , 'S01E03' , 'S02E01' , 'S02E03' ]
280280
281281
282- def test_argparse_remainder_completion (cmd2_app ):
282+ def test_argparse_remainder_flag_completion (cmd2_app ):
283283 import cmd2
284284 import argparse
285285
286- # First test a positional with nargs=argparse.REMAINDER
286+ # Test flag completion as first arg of positional with nargs=argparse.REMAINDER
287+ text = '--h'
288+ line = 'help command {}' .format (text )
289+ endidx = len (line )
290+ begidx = endidx - len (text )
291+
292+ # --h should not complete into --help because we are in the argparse.REMAINDER section
293+ assert complete_tester (text , line , begidx , endidx , cmd2_app ) is None
294+
295+ # Test flag completion within an already started positional with nargs=argparse.REMAINDER
287296 text = '--h'
288297 line = 'help command subcommand {}' .format (text )
289298 endidx = len (line )
290299 begidx = endidx - len (text )
291300
292- # --h should not complete into --help because we are in the argparse.REMAINDER sections
301+ # --h should not complete into --help because we are in the argparse.REMAINDER section
293302 assert complete_tester (text , line , begidx , endidx , cmd2_app ) is None
294303
295- # Now test a flag with nargs=argparse.REMAINDER
304+ # Test a flag with nargs=argparse.REMAINDER
296305 parser = argparse .ArgumentParser ()
297306 parser .add_argument ('-f' , nargs = argparse .REMAINDER )
298307
@@ -304,18 +313,24 @@ def test_argparse_remainder_completion(cmd2_app):
304313 endidx = len (line )
305314 begidx = endidx - len (text )
306315
307- # --h should not complete into --help because we are in the argparse.REMAINDER sections
316+ # --h should not complete into --help because we are in the argparse.REMAINDER section
308317 assert complete_tester (text , line , begidx , endidx , cmd2_app ) is None
309318
310319
311320def test_completion_after_double_dash (cmd2_app ):
312- # Test -- as the last token before an argparse.REMAINDER sections
321+ """
322+ Test completion after --, which argparse says (all args after -- are non-options)
323+ All of these tests occur outside of an argparse.REMAINDER section since those tests
324+ are handled in test_argparse_remainder_flag_completion
325+ """
326+
327+ # Test -- as the last token
313328 text = '--'
314329 line = 'help {}' .format (text )
315330 endidx = len (line )
316331 begidx = endidx - len (text )
317332
318- # Since -- is the last token in a non-remainder section , then it should show flag choices
333+ # Since -- is the last token, then it should show flag choices
319334 first_match = complete_tester (text , line , begidx , endidx , cmd2_app )
320335 assert first_match is not None and '--help' in cmd2_app .completion_matches
321336
@@ -325,5 +340,5 @@ def test_completion_after_double_dash(cmd2_app):
325340 endidx = len (line )
326341 begidx = endidx - len (text )
327342
328- # Since -- appeared before the -- being completed, no more flags should be completed
343+ # Since -- appeared before the -- being completed, nothing should be completed
329344 assert complete_tester (text , line , begidx , endidx , cmd2_app ) is None
0 commit comments