@@ -5383,7 +5383,9 @@ def test_zero_or_more_optional(self):
53835383 args = parser .parse_args ([])
53845384 self .assertEqual (NS (x = []), args )
53855385
5386- def test_double_dash (self ):
5386+
5387+ class TestDoubleDash (TestCase ):
5388+ def test_single_argument_option (self ):
53875389 parser = argparse .ArgumentParser (exit_on_error = False )
53885390 parser .add_argument ('-f' , '--foo' )
53895391 parser .add_argument ('bar' , nargs = '*' )
@@ -5407,6 +5409,7 @@ def test_double_dash(self):
54075409 args = parser .parse_args (['a' , '--' , 'b' , '--' , 'c' , '--foo' , 'd' ])
54085410 self .assertEqual (NS (foo = None , bar = ['a' , 'b' , '--' , 'c' , '--foo' , 'd' ]), args )
54095411
5412+ def test_multiple_argument_option (self ):
54105413 parser = argparse .ArgumentParser (exit_on_error = False )
54115414 parser .add_argument ('-f' , '--foo' , nargs = '*' )
54125415 parser .add_argument ('bar' , nargs = '*' )
@@ -5429,6 +5432,7 @@ def test_double_dash(self):
54295432 self .assertEqual (NS (foo = ['c' ], bar = ['a' , 'b' ]), args )
54305433 self .assertEqual (argv , ['--' , 'd' ])
54315434
5435+ def test_multiple_double_dashes (self ):
54325436 parser = argparse .ArgumentParser (exit_on_error = False )
54335437 parser .add_argument ('foo' )
54345438 parser .add_argument ('bar' , nargs = '*' )
@@ -5444,9 +5448,10 @@ def test_double_dash(self):
54445448 args = parser .parse_args (['--' , '--' , 'a' , '--' , 'b' , 'c' ])
54455449 self .assertEqual (NS (foo = '--' , bar = ['a' , '--' , 'b' , 'c' ]), args )
54465450
5451+ def test_remainder (self ):
54475452 parser = argparse .ArgumentParser (exit_on_error = False )
54485453 parser .add_argument ('foo' )
5449- parser .add_argument ('bar' , nargs = argparse . REMAINDER )
5454+ parser .add_argument ('bar' , nargs = '...' )
54505455
54515456 args = parser .parse_args (['--' , 'a' , 'b' , 'c' ])
54525457 self .assertEqual (NS (foo = 'a' , bar = ['b' , 'c' ]), args )
@@ -5457,6 +5462,40 @@ def test_double_dash(self):
54575462 args = parser .parse_args (['a' , '--' , 'b' , '--' , 'c' ])
54585463 self .assertEqual (NS (foo = 'a' , bar = ['b' , '--' , 'c' ]), args )
54595464
5465+ parser = argparse .ArgumentParser (exit_on_error = False )
5466+ parser .add_argument ('--foo' )
5467+ parser .add_argument ('bar' , nargs = '...' )
5468+ args = parser .parse_args (['--foo' , 'a' , '--' , 'b' , '--' , 'c' ])
5469+ self .assertEqual (NS (foo = 'a' , bar = ['--' , 'b' , '--' , 'c' ]), args )
5470+
5471+ def test_subparser (self ):
5472+ parser = argparse .ArgumentParser (exit_on_error = False )
5473+ parser .add_argument ('foo' )
5474+ subparsers = parser .add_subparsers ()
5475+ parser1 = subparsers .add_parser ('run' )
5476+ parser1 .add_argument ('-f' )
5477+ parser1 .add_argument ('bar' , nargs = '*' )
5478+
5479+ args = parser .parse_args (['x' , 'run' , 'a' , 'b' , '-f' , 'c' ])
5480+ self .assertEqual (NS (foo = 'x' , f = 'c' , bar = ['a' , 'b' ]), args )
5481+ args = parser .parse_args (['x' , 'run' , 'a' , 'b' , '--' , '-f' , 'c' ])
5482+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , 'b' , '-f' , 'c' ]), args )
5483+ args = parser .parse_args (['x' , 'run' , 'a' , '--' , 'b' , '-f' , 'c' ])
5484+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , 'b' , '-f' , 'c' ]), args )
5485+ args = parser .parse_args (['x' , 'run' , '--' , 'a' , 'b' , '-f' , 'c' ])
5486+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , 'b' , '-f' , 'c' ]), args )
5487+ args = parser .parse_args (['x' , '--' , 'run' , 'a' , 'b' , '-f' , 'c' ])
5488+ self .assertEqual (NS (foo = 'x' , f = 'c' , bar = ['a' , 'b' ]), args )
5489+ args = parser .parse_args (['--' , 'x' , 'run' , 'a' , 'b' , '-f' , 'c' ])
5490+ self .assertEqual (NS (foo = 'x' , f = 'c' , bar = ['a' , 'b' ]), args )
5491+ args = parser .parse_args (['x' , 'run' , '--' , 'a' , '--' , 'b' ])
5492+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , '--' , 'b' ]), args )
5493+ args = parser .parse_args (['x' , '--' , 'run' , '--' , 'a' , '--' , 'b' ])
5494+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , '--' , 'b' ]), args )
5495+ self .assertRaisesRegex (argparse .ArgumentError ,
5496+ "invalid choice: '--'" ,
5497+ parser .parse_args , ['--' , 'x' , '--' , 'run' , 'a' , 'b' ])
5498+
54605499
54615500# ===========================
54625501# parse_intermixed_args tests
0 commit comments