summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_argparse.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-09-30 01:05:51 (GMT)
committerGitHub <noreply@github.com>2024-09-30 01:05:51 (GMT)
commit8d3a0fecbe2edb69cf66db82f1c59601aac94651 (patch)
tree64a9053aead9581eb7551e896ebec19dd173fed3 /Lib/test/test_argparse.py
parent67aa68f1b4f0205fb15b03032cb0452d9c5545f0 (diff)
downloadcpython-8d3a0fecbe2edb69cf66db82f1c59601aac94651.zip
cpython-8d3a0fecbe2edb69cf66db82f1c59601aac94651.tar.gz
cpython-8d3a0fecbe2edb69cf66db82f1c59601aac94651.tar.bz2
[3.13] GH-87041: Fix incorrect indentation in argparse help (GH-124230) (#124373)
GH-87041: Fix incorrect indentation in argparse help (GH-124230) In case of usage a long command along with max_help_position more than the length of the command, the command's help was incorrectly started on the new line. (cherry picked from commit 7ee99217345af3010bf05b1f5241c661a5e0ea9b) Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com> Co-authored-by: Pavel Ditenbir <pavel.ditenbir@gmail.com>
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r--Lib/test/test_argparse.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index b1f72a3..753a8da 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -4981,6 +4981,46 @@ class TestHelpMetavarTypeFormatter(HelpTestCase):
version = ''
+class TestHelpUsageLongSubparserCommand(TestCase):
+ """Test that subparser commands are formatted correctly in help"""
+ maxDiff = None
+
+ def test_parent_help(self):
+ def custom_formatter(prog):
+ return argparse.RawTextHelpFormatter(prog, max_help_position=50)
+
+ parent_parser = argparse.ArgumentParser(
+ prog='PROG',
+ formatter_class=custom_formatter
+ )
+
+ cmd_subparsers = parent_parser.add_subparsers(title="commands",
+ metavar='CMD',
+ help='command to use')
+ cmd_subparsers.add_parser("add",
+ help="add something")
+
+ cmd_subparsers.add_parser("remove",
+ help="remove something")
+
+ cmd_subparsers.add_parser("a-very-long-command",
+ help="command that does something")
+
+ parser_help = parent_parser.format_help()
+ self.assertEqual(parser_help, textwrap.dedent('''\
+ usage: PROG [-h] CMD ...
+
+ options:
+ -h, --help show this help message and exit
+
+ commands:
+ CMD command to use
+ add add something
+ remove remove something
+ a-very-long-command command that does something
+ '''))
+
+
# =====================================
# Optional/Positional constructor tests
# =====================================