mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
bpo-24444: fix an error in argparse help when help for an option is blank (GH-28050) (GH-28931)
(cherry picked from commit 6fafc25aea
)
Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
This commit is contained in:
parent
f8473f6f76
commit
fd2be6da2f
3 changed files with 44 additions and 5 deletions
|
@ -2145,6 +2145,42 @@ class TestAddSubparsers(TestCase):
|
|||
wrap\N{NO-BREAK SPACE}at non-breaking spaces
|
||||
'''))
|
||||
|
||||
def test_help_blank(self):
|
||||
# Issue 24444
|
||||
parser = ErrorRaisingArgumentParser(
|
||||
prog='PROG', description='main description')
|
||||
parser.add_argument(
|
||||
'foo',
|
||||
help=' ')
|
||||
self.assertEqual(parser.format_help(), textwrap.dedent('''\
|
||||
usage: PROG [-h] foo
|
||||
|
||||
main description
|
||||
|
||||
positional arguments:
|
||||
foo
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
'''))
|
||||
|
||||
parser = ErrorRaisingArgumentParser(
|
||||
prog='PROG', description='main description')
|
||||
parser.add_argument(
|
||||
'foo', choices=[],
|
||||
help='%(choices)s')
|
||||
self.assertEqual(parser.format_help(), textwrap.dedent('''\
|
||||
usage: PROG [-h] {}
|
||||
|
||||
main description
|
||||
|
||||
positional arguments:
|
||||
{}
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
'''))
|
||||
|
||||
def test_help_alternate_prefix_chars(self):
|
||||
parser = self._get_parser(prefix_chars='+:/')
|
||||
self.assertEqual(parser.format_usage(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue