@@ -5720,7 +5720,9 @@ def test_zero_or_more_optional(self):
57205720 args = parser .parse_args ([])
57215721 self .assertEqual (NS (x = []), args )
57225722
5723- def test_double_dash (self ):
5723+
5724+ class TestDoubleDash (TestCase ):
5725+ def test_single_argument_option (self ):
57245726 parser = argparse .ArgumentParser (exit_on_error = False )
57255727 parser .add_argument ('-f' , '--foo' )
57265728 parser .add_argument ('bar' , nargs = '*' )
@@ -5744,6 +5746,7 @@ def test_double_dash(self):
57445746 args = parser .parse_args (['a' , '--' , 'b' , '--' , 'c' , '--foo' , 'd' ])
57455747 self .assertEqual (NS (foo = None , bar = ['a' , 'b' , '--' , 'c' , '--foo' , 'd' ]), args )
57465748
5749+ def test_multiple_argument_option (self ):
57475750 parser = argparse .ArgumentParser (exit_on_error = False )
57485751 parser .add_argument ('-f' , '--foo' , nargs = '*' )
57495752 parser .add_argument ('bar' , nargs = '*' )
@@ -5766,6 +5769,7 @@ def test_double_dash(self):
57665769 self .assertEqual (NS (foo = ['c' ], bar = ['a' , 'b' ]), args )
57675770 self .assertEqual (argv , ['--' , 'd' ])
57685771
5772+ def test_multiple_double_dashes (self ):
57695773 parser = argparse .ArgumentParser (exit_on_error = False )
57705774 parser .add_argument ('foo' )
57715775 parser .add_argument ('bar' , nargs = '*' )
@@ -5781,9 +5785,10 @@ def test_double_dash(self):
57815785 args = parser .parse_args (['--' , '--' , 'a' , '--' , 'b' , 'c' ])
57825786 self .assertEqual (NS (foo = '--' , bar = ['a' , '--' , 'b' , 'c' ]), args )
57835787
5788+ def test_remainder (self ):
57845789 parser = argparse .ArgumentParser (exit_on_error = False )
57855790 parser .add_argument ('foo' )
5786- parser .add_argument ('bar' , nargs = argparse . REMAINDER )
5791+ parser .add_argument ('bar' , nargs = '...' )
57875792
57885793 args = parser .parse_args (['--' , 'a' , 'b' , 'c' ])
57895794 self .assertEqual (NS (foo = 'a' , bar = ['b' , 'c' ]), args )
@@ -5794,6 +5799,40 @@ def test_double_dash(self):
57945799 args = parser .parse_args (['a' , '--' , 'b' , '--' , 'c' ])
57955800 self .assertEqual (NS (foo = 'a' , bar = ['b' , '--' , 'c' ]), args )
57965801
5802+ parser = argparse .ArgumentParser (exit_on_error = False )
5803+ parser .add_argument ('--foo' )
5804+ parser .add_argument ('bar' , nargs = '...' )
5805+ args = parser .parse_args (['--foo' , 'a' , '--' , 'b' , '--' , 'c' ])
5806+ self .assertEqual (NS (foo = 'a' , bar = ['--' , 'b' , '--' , 'c' ]), args )
5807+
5808+ def test_subparser (self ):
5809+ parser = argparse .ArgumentParser (exit_on_error = False )
5810+ parser .add_argument ('foo' )
5811+ subparsers = parser .add_subparsers ()
5812+ parser1 = subparsers .add_parser ('run' )
5813+ parser1 .add_argument ('-f' )
5814+ parser1 .add_argument ('bar' , nargs = '*' )
5815+
5816+ args = parser .parse_args (['x' , 'run' , 'a' , 'b' , '-f' , 'c' ])
5817+ self .assertEqual (NS (foo = 'x' , f = 'c' , bar = ['a' , 'b' ]), args )
5818+ args = parser .parse_args (['x' , 'run' , 'a' , 'b' , '--' , '-f' , 'c' ])
5819+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , 'b' , '-f' , 'c' ]), args )
5820+ args = parser .parse_args (['x' , 'run' , 'a' , '--' , 'b' , '-f' , 'c' ])
5821+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , 'b' , '-f' , 'c' ]), args )
5822+ args = parser .parse_args (['x' , 'run' , '--' , 'a' , 'b' , '-f' , 'c' ])
5823+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , 'b' , '-f' , 'c' ]), args )
5824+ args = parser .parse_args (['x' , '--' , 'run' , 'a' , 'b' , '-f' , 'c' ])
5825+ self .assertEqual (NS (foo = 'x' , f = 'c' , bar = ['a' , 'b' ]), args )
5826+ args = parser .parse_args (['--' , 'x' , 'run' , 'a' , 'b' , '-f' , 'c' ])
5827+ self .assertEqual (NS (foo = 'x' , f = 'c' , bar = ['a' , 'b' ]), args )
5828+ args = parser .parse_args (['x' , 'run' , '--' , 'a' , '--' , 'b' ])
5829+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , '--' , 'b' ]), args )
5830+ args = parser .parse_args (['x' , '--' , 'run' , '--' , 'a' , '--' , 'b' ])
5831+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , '--' , 'b' ]), args )
5832+ self .assertRaisesRegex (argparse .ArgumentError ,
5833+ "invalid choice: '--'" ,
5834+ parser .parse_args , ['--' , 'x' , '--' , 'run' , 'a' , 'b' ])
5835+
57975836
57985837# ===========================
57995838# parse_intermixed_args tests
0 commit comments