Skip to content

Commit 84f290b

Browse files
committed
Increasing code coverage
1 parent 082fcc1 commit 84f290b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_completion.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,30 @@ def test_add_opening_quote_delimited_space_in_prefix(cmd2_app):
716716
os.path.commonprefix(cmd2_app.completion_matches) == expected_common_prefix and \
717717
cmd2_app.display_matches == expected_display
718718

719+
def test_argparse_remainder_completion(cmd2_app):
720+
# First test a positional with nargs=argparse.REMAINDER
721+
text = '--h'
722+
line = 'help command subcommand {}'.format(text)
723+
endidx = len(line)
724+
begidx = endidx - len(text)
725+
726+
# --h should not complete into --help because we are in the argparse.REMAINDER sections
727+
assert complete_tester(text, line, begidx, endidx, cmd2_app) is None
728+
729+
# Now test a flag with nargs=argparse.REMAINDER
730+
parser = argparse.ArgumentParser()
731+
parser.add_argument('-f', nargs=argparse.REMAINDER)
732+
733+
# Overwrite eof's parser for this test
734+
cmd2.Cmd.do_eof.argparser = parser
735+
736+
text = '--h'
737+
line = 'eof -f {}'.format(text)
738+
endidx = len(line)
739+
begidx = endidx - len(text)
740+
741+
# --h should not complete into --help because we are in the argparse.REMAINDER sections
742+
assert complete_tester(text, line, begidx, endidx, cmd2_app) is None
719743

720744
@pytest.fixture
721745
def sc_app():

0 commit comments

Comments
 (0)