@@ -279,20 +279,29 @@ def test_autcomp_custom_func_list_and_dict_arg(cmd2_app):
279
279
cmd2_app .completion_matches == ['S01E02' , 'S01E03' , 'S02E01' , 'S02E03' ]
280
280
281
281
282
- def test_argparse_remainder_completion (cmd2_app ):
282
+ def test_argparse_remainder_flag_completion (cmd2_app ):
283
283
import cmd2
284
284
import argparse
285
285
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
287
296
text = '--h'
288
297
line = 'help command subcommand {}' .format (text )
289
298
endidx = len (line )
290
299
begidx = endidx - len (text )
291
300
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
293
302
assert complete_tester (text , line , begidx , endidx , cmd2_app ) is None
294
303
295
- # Now test a flag with nargs=argparse.REMAINDER
304
+ # Test a flag with nargs=argparse.REMAINDER
296
305
parser = argparse .ArgumentParser ()
297
306
parser .add_argument ('-f' , nargs = argparse .REMAINDER )
298
307
@@ -304,18 +313,24 @@ def test_argparse_remainder_completion(cmd2_app):
304
313
endidx = len (line )
305
314
begidx = endidx - len (text )
306
315
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
308
317
assert complete_tester (text , line , begidx , endidx , cmd2_app ) is None
309
318
310
319
311
320
def 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
313
328
text = '--'
314
329
line = 'help {}' .format (text )
315
330
endidx = len (line )
316
331
begidx = endidx - len (text )
317
332
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
319
334
first_match = complete_tester (text , line , begidx , endidx , cmd2_app )
320
335
assert first_match is not None and '--help' in cmd2_app .completion_matches
321
336
@@ -325,5 +340,5 @@ def test_completion_after_double_dash(cmd2_app):
325
340
endidx = len (line )
326
341
begidx = endidx - len (text )
327
342
328
- # Since -- appeared before the -- being completed, no more flags should be completed
343
+ # Since -- appeared before the -- being completed, nothing should be completed
329
344
assert complete_tester (text , line , begidx , endidx , cmd2_app ) is None
0 commit comments