mirror of
https://github.com/python/cpython.git
synced 2025-08-09 11:29:45 +00:00
[3.12] gh-61011: Fix inheritance of nested mutually exclusive groups in argparse (GH-125210) (GH-125309)
Previously, all nested mutually exclusive groups lost their connection
to the group containing them and were displayed as belonging directly
to the parser.
(cherry picked from commit 18c7449768
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Danica J. Sutherland <djsutherland@users.noreply.github.com>
This commit is contained in:
parent
4c40381023
commit
23cefd9f4c
4 changed files with 39 additions and 1 deletions
|
@ -2880,6 +2880,35 @@ class TestParentParsers(TestCase):
|
|||
-x X
|
||||
'''.format(progname, ' ' if progname else '' )))
|
||||
|
||||
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
|
||||
# ==============================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue