@@ -2997,6 +2997,13 @@ def test_group_prefix_chars_default(self):
2997
2997
self .assertEqual (msg , str (cm .warning ))
2998
2998
self .assertEqual (cm .filename , __file__ )
2999
2999
3000
+ def test_nested_argument_group (self ):
3001
+ parser = argparse .ArgumentParser ()
3002
+ g = parser .add_argument_group ()
3003
+ self .assertRaisesRegex (ValueError ,
3004
+ 'argument groups cannot be nested' ,
3005
+ g .add_argument_group )
3006
+
3000
3007
# ===================
3001
3008
# Parent parser tests
3002
3009
# ===================
@@ -3297,6 +3304,14 @@ def test_empty_group(self):
3297
3304
with self .assertRaises (ValueError ):
3298
3305
parser .parse_args (['-h' ])
3299
3306
3307
+ def test_nested_mutex_groups (self ):
3308
+ parser = argparse .ArgumentParser (prog = 'PROG' )
3309
+ g = parser .add_mutually_exclusive_group ()
3310
+ g .add_argument ("--spam" )
3311
+ self .assertRaisesRegex (ValueError ,
3312
+ 'mutually exclusive groups cannot be nested' ,
3313
+ g .add_mutually_exclusive_group )
3314
+
3300
3315
class MEMixin (object ):
3301
3316
3302
3317
def test_failures_when_not_required (self ):
@@ -3664,55 +3679,6 @@ def get_parser(self, required):
3664
3679
-c c help
3665
3680
'''
3666
3681
3667
- class TestMutuallyExclusiveNested (MEMixin , TestCase ):
3668
-
3669
- # Nesting mutually exclusive groups is an undocumented feature
3670
- # that came about by accident through inheritance and has been
3671
- # the source of many bugs. It is deprecated and this test should
3672
- # eventually be removed along with it.
3673
-
3674
- def get_parser (self , required ):
3675
- parser = ErrorRaisingArgumentParser (prog = 'PROG' )
3676
- group = parser .add_mutually_exclusive_group (required = required )
3677
- group .add_argument ('-a' )
3678
- group .add_argument ('-b' )
3679
- with warnings .catch_warnings ():
3680
- warnings .simplefilter ('ignore' , DeprecationWarning )
3681
- group2 = group .add_mutually_exclusive_group (required = required )
3682
- group2 .add_argument ('-c' )
3683
- group2 .add_argument ('-d' )
3684
- with warnings .catch_warnings ():
3685
- warnings .simplefilter ('ignore' , DeprecationWarning )
3686
- group3 = group2 .add_mutually_exclusive_group (required = required )
3687
- group3 .add_argument ('-e' )
3688
- group3 .add_argument ('-f' )
3689
- return parser
3690
-
3691
- usage_when_not_required = '''\
3692
- usage: PROG [-h] [-a A | -b B | [-c C | -d D | [-e E | -f F]]]
3693
- '''
3694
- usage_when_required = '''\
3695
- usage: PROG [-h] (-a A | -b B | (-c C | -d D | (-e E | -f F)))
3696
- '''
3697
-
3698
- help = '''\
3699
-
3700
- options:
3701
- -h, --help show this help message and exit
3702
- -a A
3703
- -b B
3704
- -c C
3705
- -d D
3706
- -e E
3707
- -f F
3708
- '''
3709
-
3710
- # We are only interested in testing the behavior of format_usage().
3711
- test_failures_when_not_required = None
3712
- test_failures_when_required = None
3713
- test_successes_when_not_required = None
3714
- test_successes_when_required = None
3715
-
3716
3682
3717
3683
class TestMutuallyExclusiveOptionalOptional (MEMixin , TestCase ):
3718
3684
def get_parser (self , required = None ):
@@ -4883,25 +4849,6 @@ def test_all_suppressed_mutex_with_optional_nargs(self):
4883
4849
usage = 'usage: PROG [-h]\n '
4884
4850
self .assertEqual (parser .format_usage (), usage )
4885
4851
4886
- def test_nested_mutex_groups (self ):
4887
- parser = argparse .ArgumentParser (prog = 'PROG' )
4888
- g = parser .add_mutually_exclusive_group ()
4889
- g .add_argument ("--spam" )
4890
- with warnings .catch_warnings ():
4891
- warnings .simplefilter ('ignore' , DeprecationWarning )
4892
- gg = g .add_mutually_exclusive_group ()
4893
- gg .add_argument ("--hax" )
4894
- gg .add_argument ("--hox" , help = argparse .SUPPRESS )
4895
- gg .add_argument ("--hex" )
4896
- g .add_argument ("--eggs" )
4897
- parser .add_argument ("--num" )
4898
-
4899
- usage = textwrap .dedent ('''\
4900
- usage: PROG [-h] [--spam SPAM | [--hax HAX | --hex HEX] | --eggs EGGS]
4901
- [--num NUM]
4902
- ''' )
4903
- self .assertEqual (parser .format_usage (), usage )
4904
-
4905
4852
def test_long_mutex_groups_wrap (self ):
4906
4853
parser = argparse .ArgumentParser (prog = 'PROG' )
4907
4854
g = parser .add_mutually_exclusive_group ()
0 commit comments