mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
GH-75949: Fix argparse dropping '|' in mutually exclusive groups on line wrap (#142312)
This commit is contained in:
parent
61823a5382
commit
5be3405e4e
3 changed files with 49 additions and 4 deletions
|
|
@ -4966,6 +4966,25 @@ def test_long_mutex_groups_wrap(self):
|
|||
''')
|
||||
self.assertEqual(parser.format_usage(), usage)
|
||||
|
||||
def test_mutex_groups_with_mixed_optionals_positionals_wrap(self):
|
||||
# https://github.com/python/cpython/issues/75949
|
||||
# Mutually exclusive groups containing both optionals and positionals
|
||||
# should preserve pipe separators when the usage line wraps.
|
||||
parser = argparse.ArgumentParser(prog='PROG')
|
||||
g = parser.add_mutually_exclusive_group()
|
||||
g.add_argument('-v', '--verbose', action='store_true')
|
||||
g.add_argument('-q', '--quiet', action='store_true')
|
||||
g.add_argument('-x', '--extra-long-option-name', nargs='?')
|
||||
g.add_argument('-y', '--yet-another-long-option', nargs='?')
|
||||
g.add_argument('positional', nargs='?')
|
||||
|
||||
usage = textwrap.dedent('''\
|
||||
usage: PROG [-h] [-v | -q | -x [EXTRA_LONG_OPTION_NAME] |
|
||||
-y [YET_ANOTHER_LONG_OPTION] |
|
||||
positional]
|
||||
''')
|
||||
self.assertEqual(parser.format_usage(), usage)
|
||||
|
||||
|
||||
class TestHelpVariableExpansion(HelpTestCase):
|
||||
"""Test that variables are expanded properly in help messages"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue