summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_argparse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-10-11 08:43:29 (GMT)
committerGitHub <noreply@github.com>2024-10-11 08:43:29 (GMT)
commit18c74497681e0107d7cde53e63ea42feb38f2176 (patch)
tree94d9b01f05b6900d934e90957980ea30966ea89d /Lib/test/test_argparse.py
parent0135848059162ad81478a7776fec622d68a36524 (diff)
downloadcpython-18c74497681e0107d7cde53e63ea42feb38f2176.zip
cpython-18c74497681e0107d7cde53e63ea42feb38f2176.tar.gz
cpython-18c74497681e0107d7cde53e63ea42feb38f2176.tar.bz2
gh-61011: Fix inheritance of nested mutually exclusive groups in argparse (GH-125210)
Previously, all nested mutually exclusive groups lost their connection to the group containing them and were displayed as belonging directly to the parser. Co-authored-by: Danica J. Sutherland <djsutherland@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r--Lib/test/test_argparse.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index c9e79eb..1ebbc21 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -2942,6 +2942,35 @@ class TestParentParsers(TestCase):
def test_wrong_type_parents(self):
self.assertRaises(TypeError, ErrorRaisingArgumentParser, parents=[1])
+ def test_mutex_groups_parents(self):
+ parent = ErrorRaisingArgumentParser(add_help=False)
+ g = parent.add_argument_group(title='g', description='gd')
+ g.add_argument('-w')
+ g.add_argument('-x')
+ m = g.add_mutually_exclusive_group()
+ m.add_argument('-y')
+ m.add_argument('-z')
+ parser = ErrorRaisingArgumentParser(prog='PROG', parents=[parent])
+
+ self.assertRaises(ArgumentParserError, parser.parse_args,
+ ['-y', 'Y', '-z', 'Z'])
+
+ parser_help = parser.format_help()
+ self.assertEqual(parser_help, textwrap.dedent('''\
+ usage: PROG [-h] [-w W] [-x X] [-y Y | -z Z]
+
+ options:
+ -h, --help show this help message and exit
+
+ g:
+ gd
+
+ -w W
+ -x X
+ -y Y
+ -z Z
+ '''))
+
# ==============================
# Mutually exclusive group tests
# ==============================