@@ -5993,7 +5993,9 @@ def test_zero_or_more_optional(self):
59935993 args = parser .parse_args ([])
59945994 self .assertEqual (NS (x = []), args )
59955995
5996- def test_double_dash (self ):
5996+
5997+ class TestDoubleDash (TestCase ):
5998+ def test_single_argument_option (self ):
59975999 parser = argparse .ArgumentParser (exit_on_error = False )
59986000 parser .add_argument ('-f' , '--foo' )
59996001 parser .add_argument ('bar' , nargs = '*' )
@@ -6017,6 +6019,7 @@ def test_double_dash(self):
60176019 args = parser .parse_args (['a' , '--' , 'b' , '--' , 'c' , '--foo' , 'd' ])
60186020 self .assertEqual (NS (foo = None , bar = ['a' , 'b' , '--' , 'c' , '--foo' , 'd' ]), args )
60196021
6022+ def test_multiple_argument_option (self ):
60206023 parser = argparse .ArgumentParser (exit_on_error = False )
60216024 parser .add_argument ('-f' , '--foo' , nargs = '*' )
60226025 parser .add_argument ('bar' , nargs = '*' )
@@ -6039,6 +6042,7 @@ def test_double_dash(self):
60396042 self .assertEqual (NS (foo = ['c' ], bar = ['a' , 'b' ]), args )
60406043 self .assertEqual (argv , ['--' , 'd' ])
60416044
6045+ def test_multiple_double_dashes (self ):
60426046 parser = argparse .ArgumentParser (exit_on_error = False )
60436047 parser .add_argument ('foo' )
60446048 parser .add_argument ('bar' , nargs = '*' )
@@ -6054,9 +6058,10 @@ def test_double_dash(self):
60546058 args = parser .parse_args (['--' , '--' , 'a' , '--' , 'b' , 'c' ])
60556059 self .assertEqual (NS (foo = '--' , bar = ['a' , '--' , 'b' , 'c' ]), args )
60566060
6061+ def test_remainder (self ):
60576062 parser = argparse .ArgumentParser (exit_on_error = False )
60586063 parser .add_argument ('foo' )
6059- parser .add_argument ('bar' , nargs = argparse . REMAINDER )
6064+ parser .add_argument ('bar' , nargs = '...' )
60606065
60616066 args = parser .parse_args (['--' , 'a' , 'b' , 'c' ])
60626067 self .assertEqual (NS (foo = 'a' , bar = ['b' , 'c' ]), args )
@@ -6067,6 +6072,40 @@ def test_double_dash(self):
60676072 args = parser .parse_args (['a' , '--' , 'b' , '--' , 'c' ])
60686073 self .assertEqual (NS (foo = 'a' , bar = ['b' , '--' , 'c' ]), args )
60696074
6075+ parser = argparse .ArgumentParser (exit_on_error = False )
6076+ parser .add_argument ('--foo' )
6077+ parser .add_argument ('bar' , nargs = '...' )
6078+ args = parser .parse_args (['--foo' , 'a' , '--' , 'b' , '--' , 'c' ])
6079+ self .assertEqual (NS (foo = 'a' , bar = ['--' , 'b' , '--' , 'c' ]), args )
6080+
6081+ def test_subparser (self ):
6082+ parser = argparse .ArgumentParser (exit_on_error = False )
6083+ parser .add_argument ('foo' )
6084+ subparsers = parser .add_subparsers ()
6085+ parser1 = subparsers .add_parser ('run' )
6086+ parser1 .add_argument ('-f' )
6087+ parser1 .add_argument ('bar' , nargs = '*' )
6088+
6089+ args = parser .parse_args (['x' , 'run' , 'a' , 'b' , '-f' , 'c' ])
6090+ self .assertEqual (NS (foo = 'x' , f = 'c' , bar = ['a' , 'b' ]), args )
6091+ args = parser .parse_args (['x' , 'run' , 'a' , 'b' , '--' , '-f' , 'c' ])
6092+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , 'b' , '-f' , 'c' ]), args )
6093+ args = parser .parse_args (['x' , 'run' , 'a' , '--' , 'b' , '-f' , 'c' ])
6094+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , 'b' , '-f' , 'c' ]), args )
6095+ args = parser .parse_args (['x' , 'run' , '--' , 'a' , 'b' , '-f' , 'c' ])
6096+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , 'b' , '-f' , 'c' ]), args )
6097+ args = parser .parse_args (['x' , '--' , 'run' , 'a' , 'b' , '-f' , 'c' ])
6098+ self .assertEqual (NS (foo = 'x' , f = 'c' , bar = ['a' , 'b' ]), args )
6099+ args = parser .parse_args (['--' , 'x' , 'run' , 'a' , 'b' , '-f' , 'c' ])
6100+ self .assertEqual (NS (foo = 'x' , f = 'c' , bar = ['a' , 'b' ]), args )
6101+ args = parser .parse_args (['x' , 'run' , '--' , 'a' , '--' , 'b' ])
6102+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , '--' , 'b' ]), args )
6103+ args = parser .parse_args (['x' , '--' , 'run' , '--' , 'a' , '--' , 'b' ])
6104+ self .assertEqual (NS (foo = 'x' , f = None , bar = ['a' , '--' , 'b' ]), args )
6105+ self .assertRaisesRegex (argparse .ArgumentError ,
6106+ "invalid choice: '--'" ,
6107+ parser .parse_args , ['--' , 'x' , '--' , 'run' , 'a' , 'b' ])
6108+
60706109
60716110# ===========================
60726111# parse_intermixed_args tests
0 commit comments