mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] GH-130645: Default to color help in argparse (GH-136809) (#136886)
GH-130645: Default to color help in argparse (GH-136809)
(cherry picked from commit acbe896cb1)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
parent
2f7684ceee
commit
17c5959aa3
6 changed files with 39 additions and 25 deletions
|
|
@ -18,7 +18,11 @@
|
|||
import warnings
|
||||
|
||||
from enum import StrEnum
|
||||
from test.support import captured_stderr
|
||||
from test.support import (
|
||||
captured_stderr,
|
||||
force_not_colorized,
|
||||
force_not_colorized_test_class,
|
||||
)
|
||||
from test.support import import_helper
|
||||
from test.support import os_helper
|
||||
from test.support import script_helper
|
||||
|
|
@ -1007,6 +1011,7 @@ def test_parse_enum_value(self):
|
|||
args = parser.parse_args(['--color', 'red'])
|
||||
self.assertEqual(args.color, self.Color.RED)
|
||||
|
||||
@force_not_colorized
|
||||
def test_help_message_contains_enum_choices(self):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--color', choices=self.Color, help='Choose a color')
|
||||
|
|
@ -2403,6 +2408,7 @@ def test_modified_invalid_action(self):
|
|||
# Subparsers tests
|
||||
# ================
|
||||
|
||||
@force_not_colorized_test_class
|
||||
class TestAddSubparsers(TestCase):
|
||||
"""Test the add_subparsers method"""
|
||||
|
||||
|
|
@ -3009,6 +3015,7 @@ def test_nested_argument_group(self):
|
|||
# Parent parser tests
|
||||
# ===================
|
||||
|
||||
@force_not_colorized_test_class
|
||||
class TestParentParsers(TestCase):
|
||||
"""Tests that parsers can be created with parent parsers"""
|
||||
|
||||
|
|
@ -3216,6 +3223,7 @@ def test_mutex_groups_parents(self):
|
|||
# Mutually exclusive group tests
|
||||
# ==============================
|
||||
|
||||
@force_not_colorized_test_class
|
||||
class TestMutuallyExclusiveGroupErrors(TestCase):
|
||||
|
||||
def test_invalid_add_argument_group(self):
|
||||
|
|
@ -3344,21 +3352,25 @@ def test_successes_when_required(self):
|
|||
actual_ns = parse_args(args_string.split())
|
||||
self.assertEqual(actual_ns, expected_ns)
|
||||
|
||||
@force_not_colorized
|
||||
def test_usage_when_not_required(self):
|
||||
format_usage = self.get_parser(required=False).format_usage
|
||||
expected_usage = self.usage_when_not_required
|
||||
self.assertEqual(format_usage(), textwrap.dedent(expected_usage))
|
||||
|
||||
@force_not_colorized
|
||||
def test_usage_when_required(self):
|
||||
format_usage = self.get_parser(required=True).format_usage
|
||||
expected_usage = self.usage_when_required
|
||||
self.assertEqual(format_usage(), textwrap.dedent(expected_usage))
|
||||
|
||||
@force_not_colorized
|
||||
def test_help_when_not_required(self):
|
||||
format_help = self.get_parser(required=False).format_help
|
||||
help = self.usage_when_not_required + self.help
|
||||
self.assertEqual(format_help(), textwrap.dedent(help))
|
||||
|
||||
@force_not_colorized
|
||||
def test_help_when_required(self):
|
||||
format_help = self.get_parser(required=True).format_help
|
||||
help = self.usage_when_required + self.help
|
||||
|
|
@ -4030,11 +4042,13 @@ def _test(self, tester, parser_text):
|
|||
tester.maxDiff = None
|
||||
tester.assertEqual(expected_text, parser_text)
|
||||
|
||||
@force_not_colorized
|
||||
def test_format(self, tester):
|
||||
parser = self._get_parser(tester)
|
||||
format = getattr(parser, 'format_%s' % self.func_suffix)
|
||||
self._test(tester, format())
|
||||
|
||||
@force_not_colorized
|
||||
def test_print(self, tester):
|
||||
parser = self._get_parser(tester)
|
||||
print_ = getattr(parser, 'print_%s' % self.func_suffix)
|
||||
|
|
@ -4047,6 +4061,7 @@ def test_print(self, tester):
|
|||
setattr(sys, self.std_name, old_stream)
|
||||
self._test(tester, parser_text)
|
||||
|
||||
@force_not_colorized
|
||||
def test_print_file(self, tester):
|
||||
parser = self._get_parser(tester)
|
||||
print_ = getattr(parser, 'print_%s' % self.func_suffix)
|
||||
|
|
@ -4788,6 +4803,7 @@ class TestHelpUsageMetavarsSpacesParentheses(HelpTestCase):
|
|||
version = ''
|
||||
|
||||
|
||||
@force_not_colorized_test_class
|
||||
class TestHelpUsageNoWhitespaceCrash(TestCase):
|
||||
|
||||
def test_all_suppressed_mutex_followed_by_long_arg(self):
|
||||
|
|
@ -5469,6 +5485,7 @@ def custom_type(string):
|
|||
version = ''
|
||||
|
||||
|
||||
@force_not_colorized_test_class
|
||||
class TestHelpCustomHelpFormatter(TestCase):
|
||||
maxDiff = None
|
||||
|
||||
|
|
@ -5765,6 +5782,7 @@ def test_conflict_error(self):
|
|||
self.assertRaises(argparse.ArgumentError,
|
||||
parser.add_argument, '--spam')
|
||||
|
||||
@force_not_colorized
|
||||
def test_resolve_error(self):
|
||||
get_parser = argparse.ArgumentParser
|
||||
parser = get_parser(prog='PROG', conflict_handler='resolve')
|
||||
|
|
@ -6031,6 +6049,7 @@ def test_argument_error(self):
|
|||
|
||||
class TestArgumentTypeError(TestCase):
|
||||
|
||||
@force_not_colorized
|
||||
def test_argument_type_error(self):
|
||||
|
||||
def spam(string):
|
||||
|
|
@ -6829,6 +6848,7 @@ def setUp(self):
|
|||
metavar = '<http[s]://example:1234>'
|
||||
self.parser.add_argument('--proxy', metavar=metavar)
|
||||
|
||||
@force_not_colorized
|
||||
def test_help_with_metavar(self):
|
||||
help_text = self.parser.format_help()
|
||||
self.assertEqual(help_text, textwrap.dedent('''\
|
||||
|
|
@ -6994,6 +7014,7 @@ def test_os_error(self):
|
|||
self.parser.parse_args, ['@no-such-file'])
|
||||
|
||||
|
||||
@force_not_colorized_test_class
|
||||
class TestProgName(TestCase):
|
||||
source = textwrap.dedent('''\
|
||||
import argparse
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue