Skip to content
Merged
Prev Previous commit
Next Next commit
Merge main
  • Loading branch information
savannahostrowski committed Dec 12, 2025
commit 40040ca0c8adff1ad1aa695567c6bb94f6afb82c
34 changes: 34 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7708,6 +7708,40 @@ def test_cmd_markup_special_regex_chars(self):
help_text = parser.format_help()
self.assertIn(f'{prog_extra}grep "foo.*bar" | sort{reset}', help_text)

def test_print_help_uses_target_file_for_color_decision(self):
parser = argparse.ArgumentParser(prog='PROG', color=True)
parser.add_argument('--opt')
output = io.StringIO()
calls = []

def fake_can_colorize(*, file=None):
calls.append(file)
return file is None

with swap_attr(_colorize, 'can_colorize', fake_can_colorize):
parser.print_help(file=output)

self.assertIs(calls[-1], output)
self.assertIn(output, calls)
self.assertNotIn('\x1b[', output.getvalue())

def test_print_usage_uses_target_file_for_color_decision(self):
parser = argparse.ArgumentParser(prog='PROG', color=True)
parser.add_argument('--opt')
output = io.StringIO()
calls = []

def fake_can_colorize(*, file=None):
calls.append(file)
return file is None

with swap_attr(_colorize, 'can_colorize', fake_can_colorize):
parser.print_usage(file=output)

self.assertIs(calls[-1], output)
self.assertIn(output, calls)
self.assertNotIn('\x1b[', output.getvalue())


class TestModule(unittest.TestCase):
def test_deprecated__version__(self):
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.