diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-10-13 10:15:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 19:15:43 +0200 |
commit | fd2be6da2ffec2301a58aefa92f17f0c567fbc55 (patch) | |
tree | adcd1ee8f2476a365c087390bc970dc5b0112825 /Lib/test/test_argparse.py | |
parent | f8473f6f7603f8cccccc3307d4cb853587be41b3 (diff) | |
download | cpython-git-fd2be6da2ffec2301a58aefa92f17f0c567fbc55.tar.gz |
bpo-24444: fix an error in argparse help when help for an option is blank (GH-28050) (GH-28931)
(cherry picked from commit 6fafc25aea8689048314b5bf7a9bb986bb1ce238)
Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r-- | Lib/test/test_argparse.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 0927281f69..6680feb016 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -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(), |