summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_argparse.py
diff options
context:
space:
mode:
authorSteven Bethard <steven.bethard@gmail.com>2011-01-30 14:05:38 (GMT)
committerSteven Bethard <steven.bethard@gmail.com>2011-01-30 14:05:38 (GMT)
commit7f41b88bb7b978205a438c7eea2b7f6bba6862d0 (patch)
tree0f4b9a22fbcc91aeb5e217e9f859b460d38d3fb0 /Lib/test/test_argparse.py
parent53c460d5fb3f2d5bdd001a7eaf621751faa87ff2 (diff)
downloadcpython-7f41b88bb7b978205a438c7eea2b7f6bba6862d0.zip
cpython-7f41b88bb7b978205a438c7eea2b7f6bba6862d0.tar.gz
cpython-7f41b88bb7b978205a438c7eea2b7f6bba6862d0.tar.bz2
#10680: fix mutually exclusive arguments in argument groups.
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r--Lib/test/test_argparse.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 50a6d49..0bcc762 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -2505,6 +2505,46 @@ class TestMutuallyExclusiveOptionalsMixed(MEMixin, TestCase):
'''
+class TestMutuallyExclusiveInGroup(MEMixin, TestCase):
+
+ def get_parser(self, required=None):
+ parser = ErrorRaisingArgumentParser(prog='PROG')
+ titled_group = parser.add_argument_group(
+ title='Titled group', description='Group description')
+ mutex_group = \
+ titled_group.add_mutually_exclusive_group(required=required)
+ mutex_group.add_argument('--bar', help='bar help')
+ mutex_group.add_argument('--baz', help='baz help')
+ return parser
+
+ failures = ['--bar X --baz Y', '--baz X --bar Y']
+ successes = [
+ ('--bar X', NS(bar='X', baz=None)),
+ ('--baz Y', NS(bar=None, baz='Y')),
+ ]
+ successes_when_not_required = [
+ ('', NS(bar=None, baz=None)),
+ ]
+
+ usage_when_not_required = '''\
+ usage: PROG [-h] [--bar BAR | --baz BAZ]
+ '''
+ usage_when_required = '''\
+ usage: PROG [-h] (--bar BAR | --baz BAZ)
+ '''
+ help = '''\
+
+ optional arguments:
+ -h, --help show this help message and exit
+
+ Titled group:
+ Group description
+
+ --bar BAR bar help
+ --baz BAZ baz help
+ '''
+
+
class TestMutuallyExclusiveOptionalsAndPositionalsMixed(MEMixin, TestCase):
def get_parser(self, required):