Skip to content

Commit fd9c85c

Browse files
hugovkambv
authored andcommitted
Update test_argparse to use theme not color and fix bug
1 parent c4808c8 commit fd9c85c

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

Lib/_colorize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class Argparse(ThemeSection):
144144
summary_long_option: str = ANSIColors.CYAN
145145
summary_short_option: str = ANSIColors.GREEN
146146
summary_label: str = ANSIColors.YELLOW
147+
summary_action: str = ANSIColors.GREEN
147148
long_option: str = ANSIColors.BOLD_CYAN
148149
short_option: str = ANSIColors.BOLD_GREEN
149150
label: str = ANSIColors.BOLD_YELLOW

Lib/argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def _get_actions_usage_parts(self, actions, groups):
458458
elif not action.option_strings:
459459
default = self._get_default_metavar_for_positional(action)
460460
part = (
461-
t.summary_short_option
461+
t.summary_action
462462
+ self._format_args(action, default)
463463
+ t.reset
464464
)

Lib/test/test_argparse.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7058,7 +7058,7 @@ def setUp(self):
70587058
super().setUp()
70597059
# Ensure color even if ran with NO_COLOR=1
70607060
_colorize.can_colorize = lambda *args, **kwargs: True
7061-
self.ansi = _colorize.ANSIColors()
7061+
self.theme = _colorize.get_theme(force_color=True).argparse
70627062

70637063
def test_argparse_color(self):
70647064
# Arrange: create a parser with a bit of everything
@@ -7120,13 +7120,17 @@ def test_argparse_color(self):
71207120
sub2 = subparsers.add_parser("sub2", deprecated=True, help="sub2 help")
71217121
sub2.add_argument("--baz", choices=("X", "Y", "Z"), help="baz help")
71227122

7123-
heading = self.ansi.BOLD_BLUE
7124-
label, label_b = self.ansi.YELLOW, self.ansi.BOLD_YELLOW
7125-
long, long_b = self.ansi.CYAN, self.ansi.BOLD_CYAN
7126-
pos, pos_b = short, short_b = self.ansi.GREEN, self.ansi.BOLD_GREEN
7127-
sub = self.ansi.BOLD_GREEN
7128-
prog = self.ansi.BOLD_MAGENTA
7129-
reset = self.ansi.RESET
7123+
prog = self.theme.prog
7124+
heading = self.theme.heading
7125+
long = self.theme.summary_long_option
7126+
short = self.theme.summary_short_option
7127+
label = self.theme.summary_label
7128+
pos = self.theme.summary_action
7129+
long_b = self.theme.long_option
7130+
short_b = self.theme.short_option
7131+
label_b = self.theme.label
7132+
pos_b = self.theme.action
7133+
reset = self.theme.reset
71307134

71317135
# Act
71327136
help_text = parser.format_help()
@@ -7171,9 +7175,9 @@ def test_argparse_color(self):
71717175
{heading}subcommands:{reset}
71727176
valid subcommands
71737177
7174-
{sub}{{sub1,sub2}}{reset} additional help
7175-
{sub}sub1{reset} sub1 help
7176-
{sub}sub2{reset} sub2 help
7178+
{pos_b}{{sub1,sub2}}{reset} additional help
7179+
{pos_b}sub1{reset} sub1 help
7180+
{pos_b}sub2{reset} sub2 help
71777181
"""
71787182
),
71797183
)
@@ -7187,10 +7191,10 @@ def test_argparse_color_usage(self):
71877191
prog="PROG",
71887192
usage="[prefix] %(prog)s [suffix]",
71897193
)
7190-
heading = self.ansi.BOLD_BLUE
7191-
prog = self.ansi.BOLD_MAGENTA
7192-
reset = self.ansi.RESET
7193-
usage = self.ansi.MAGENTA
7194+
heading = self.theme.heading
7195+
prog = self.theme.prog
7196+
reset = self.theme.reset
7197+
usage = self.theme.prog_extra
71947198

71957199
# Act
71967200
help_text = parser.format_help()

0 commit comments

Comments
 (0)