@@ -3398,12 +3398,11 @@ def test_help_subparser_all_mutually_exclusive_group_members_suppressed(self):
33983398 '''
33993399 self .assertEqual (cmd_foo .format_help (), textwrap .dedent (expected ))
34003400
3401- def test_empty_group (self ):
3401+ def test_usage_empty_group (self ):
34023402 # See issue 26952
3403- parser = argparse . ArgumentParser ( )
3403+ parser = ErrorRaisingArgumentParser ( prog = 'PROG' )
34043404 group = parser .add_mutually_exclusive_group ()
3405- with self .assertRaises (ValueError ):
3406- parser .parse_args (['-h' ])
3405+ self .assertEqual (parser .format_usage (), 'usage: PROG [-h]\n ' )
34073406
34083407 def test_nested_mutex_groups (self ):
34093408 parser = argparse .ArgumentParser (prog = 'PROG' )
@@ -3671,25 +3670,29 @@ def get_parser(self, required):
36713670 group .add_argument ('-b' , action = 'store_true' , help = 'b help' )
36723671 parser .add_argument ('-y' , action = 'store_true' , help = 'y help' )
36733672 group .add_argument ('-c' , action = 'store_true' , help = 'c help' )
3673+ parser .add_argument ('-z' , action = 'store_true' , help = 'z help' )
36743674 return parser
36753675
36763676 failures = ['-a -b' , '-b -c' , '-a -c' , '-a -b -c' ]
36773677 successes = [
3678- ('-a' , NS (a = True , b = False , c = False , x = False , y = False )),
3679- ('-b' , NS (a = False , b = True , c = False , x = False , y = False )),
3680- ('-c' , NS (a = False , b = False , c = True , x = False , y = False )),
3681- ('-a -x' , NS (a = True , b = False , c = False , x = True , y = False )),
3682- ('-y -b' , NS (a = False , b = True , c = False , x = False , y = True )),
3683- ('-x -y -c' , NS (a = False , b = False , c = True , x = True , y = True )),
3678+ ('-a' , NS (a = True , b = False , c = False , x = False , y = False , z = False )),
3679+ ('-b' , NS (a = False , b = True , c = False , x = False , y = False , z = False )),
3680+ ('-c' , NS (a = False , b = False , c = True , x = False , y = False , z = False )),
3681+ ('-a -x' , NS (a = True , b = False , c = False , x = True , y = False , z = False )),
3682+ ('-y -b' , NS (a = False , b = True , c = False , x = False , y = True , z = False )),
3683+ ('-x -y -c' , NS (a = False , b = False , c = True , x = True , y = True , z = False )),
36843684 ]
36853685 successes_when_not_required = [
3686- ('' , NS (a = False , b = False , c = False , x = False , y = False )),
3687- ('-x' , NS (a = False , b = False , c = False , x = True , y = False )),
3688- ('-y' , NS (a = False , b = False , c = False , x = False , y = True )),
3686+ ('' , NS (a = False , b = False , c = False , x = False , y = False , z = False )),
3687+ ('-x' , NS (a = False , b = False , c = False , x = True , y = False , z = False )),
3688+ ('-y' , NS (a = False , b = False , c = False , x = False , y = True , z = False )),
36893689 ]
36903690
3691- usage_when_required = usage_when_not_required = '''\
3692- usage: PROG [-h] [-x] [-a] [-b] [-y] [-c]
3691+ usage_when_not_required = '''\
3692+ usage: PROG [-h] [-x] [-a | -b | -c] [-y] [-z]
3693+ '''
3694+ usage_when_required = '''\
3695+ usage: PROG [-h] [-x] (-a | -b | -c) [-y] [-z]
36933696 '''
36943697 help = '''\
36953698
@@ -3700,6 +3703,7 @@ def get_parser(self, required):
37003703 -b b help
37013704 -y y help
37023705 -c c help
3706+ -z z help
37033707 '''
37043708
37053709
@@ -3753,23 +3757,27 @@ def get_parser(self, required):
37533757 group .add_argument ('a' , nargs = '?' , help = 'a help' )
37543758 group .add_argument ('-b' , action = 'store_true' , help = 'b help' )
37553759 group .add_argument ('-c' , action = 'store_true' , help = 'c help' )
3760+ parser .add_argument ('-z' , action = 'store_true' , help = 'z help' )
37563761 return parser
37573762
37583763 failures = ['X A -b' , '-b -c' , '-c X A' ]
37593764 successes = [
3760- ('X A' , NS (a = 'A' , b = False , c = False , x = 'X' , y = False )),
3761- ('X -b' , NS (a = None , b = True , c = False , x = 'X' , y = False )),
3762- ('X -c' , NS (a = None , b = False , c = True , x = 'X' , y = False )),
3763- ('X A -y' , NS (a = 'A' , b = False , c = False , x = 'X' , y = True )),
3764- ('X -y -b' , NS (a = None , b = True , c = False , x = 'X' , y = True )),
3765+ ('X A' , NS (a = 'A' , b = False , c = False , x = 'X' , y = False , z = False )),
3766+ ('X -b' , NS (a = None , b = True , c = False , x = 'X' , y = False , z = False )),
3767+ ('X -c' , NS (a = None , b = False , c = True , x = 'X' , y = False , z = False )),
3768+ ('X A -y' , NS (a = 'A' , b = False , c = False , x = 'X' , y = True , z = False )),
3769+ ('X -y -b' , NS (a = None , b = True , c = False , x = 'X' , y = True , z = False )),
37653770 ]
37663771 successes_when_not_required = [
3767- ('X' , NS (a = None , b = False , c = False , x = 'X' , y = False )),
3768- ('X -y' , NS (a = None , b = False , c = False , x = 'X' , y = True )),
3772+ ('X' , NS (a = None , b = False , c = False , x = 'X' , y = False , z = False )),
3773+ ('X -y' , NS (a = None , b = False , c = False , x = 'X' , y = True , z = False )),
37693774 ]
37703775
3771- usage_when_required = usage_when_not_required = '''\
3772- usage: PROG [-h] [-y] [-b] [-c] x [a]
3776+ usage_when_not_required = '''\
3777+ usage: PROG [-h] [-y] [-z] x [-b | -c | a]
3778+ '''
3779+ usage_when_required = '''\
3780+ usage: PROG [-h] [-y] [-z] x (-b | -c | a)
37733781 '''
37743782 help = '''\
37753783
@@ -3782,6 +3790,7 @@ def get_parser(self, required):
37823790 -y y help
37833791 -b b help
37843792 -c c help
3793+ -z z help
37853794 '''
37863795
37873796
@@ -4989,9 +4998,9 @@ def test_mutex_groups_with_mixed_optionals_positionals_wrap(self):
49894998 g .add_argument ('positional' , nargs = '?' )
49904999
49915000 usage = textwrap .dedent ('''\
4992- usage: PROG [-h] [-v | -q | -x [EXTRA_LONG_OPTION_NAME] |
4993- -y [YET_ANOTHER_LONG_OPTION ] |
4994- positional]
5001+ usage: PROG [-h]
5002+ [-v | -q | -x [EXTRA_LONG_OPTION_NAME ] |
5003+ -y [YET_ANOTHER_LONG_OPTION] | positional]
49955004 ''' )
49965005 self .assertEqual (parser .format_usage (), usage )
49975006
0 commit comments