summaryrefslogtreecommitdiff
path: root/Lib/test/test_argparse.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-08-25 14:30:49 -0700
committerBerker Peksag <berker.peksag@gmail.com>2019-08-26 00:30:49 +0300
commit31ea447ffe591736af1d7a3178c0f7ca3eb50d70 (patch)
tree805a0008da12afe57497eae7c98c15680326099e /Lib/test/test_argparse.py
parentf2b468dd6d0bdbe2e87c0ca7515800a115e95e54 (diff)
downloadcpython-git-31ea447ffe591736af1d7a3178c0f7ca3eb50d70.tar.gz
bpo-29553: Fix ArgumentParser.format_usage() for mutually exclusive groups (GH-14976)
Co-authored-by: Andrew Nester <andrew.nester.dev@gmail.com> Co-authored-by: Flavian Hautbois <flavianh@sicara.com> (cherry picked from commit da27d9b9dc44913ffee8f28d9638985eaaa03755)
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 51f0effaf2..3cdaff61c7 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -2772,6 +2772,46 @@ class TestMutuallyExclusiveOptionalsAndPositionalsMixed(MEMixin, TestCase):
-c c help
'''
+class TestMutuallyExclusiveNested(MEMixin, TestCase):
+
+ def get_parser(self, required):
+ parser = ErrorRaisingArgumentParser(prog='PROG')
+ group = parser.add_mutually_exclusive_group(required=required)
+ group.add_argument('-a')
+ group.add_argument('-b')
+ group2 = group.add_mutually_exclusive_group(required=required)
+ group2.add_argument('-c')
+ group2.add_argument('-d')
+ group3 = group2.add_mutually_exclusive_group(required=required)
+ group3.add_argument('-e')
+ group3.add_argument('-f')
+ return parser
+
+ usage_when_not_required = '''\
+ usage: PROG [-h] [-a A | -b B | [-c C | -d D | [-e E | -f F]]]
+ '''
+ usage_when_required = '''\
+ usage: PROG [-h] (-a A | -b B | (-c C | -d D | (-e E | -f F)))
+ '''
+
+ help = '''\
+
+ optional arguments:
+ -h, --help show this help message and exit
+ -a A
+ -b B
+ -c C
+ -d D
+ -e E
+ -f F
+ '''
+
+ # We are only interested in testing the behavior of format_usage().
+ test_failures_when_not_required = None
+ test_failures_when_required = None
+ test_successes_when_not_required = None
+ test_successes_when_required = None
+
# =================================================
# Mutually exclusive group in parent parser tests
# =================================================