Skip to content

Commit 5ba525a

Browse files
Update test
1 parent f2c813a commit 5ba525a

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

Lib/test/test_argparse.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7128,7 +7128,9 @@ class TestColorized(TestCase):
71287128
def setUp(self):
71297129
super().setUp()
71307130
# Ensure color even if ran with NO_COLOR=1
7131+
original_can_colorize = _colorize.can_colorize
71317132
_colorize.can_colorize = lambda *args, **kwargs: True
7133+
self.addCleanup(setattr, _colorize, 'can_colorize', original_can_colorize)
71327134
self.theme = _colorize.get_theme(force_color=True).argparse
71337135

71347136
def test_argparse_color(self):
@@ -7355,29 +7357,18 @@ def __init__(self, prog):
73557357
{short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset} foo help
73567358
'''))
73577359

7358-
7359-
class TestColorEnvironment(TestCase):
7360-
"""Tests for color behavior with environment variable changes."""
7361-
7362-
def test_subparser_respects_no_color_environment(self):
7363-
# Cleanup to ensure environment is properly reset
7364-
self.addCleanup(os.environ.pop, 'FORCE_COLOR', None)
7365-
self.addCleanup(os.environ.pop, 'NO_COLOR', None)
7366-
7367-
# Create parser with FORCE_COLOR, capturing colored prog
7368-
os.environ['FORCE_COLOR'] = '1'
7369-
parser = argparse.ArgumentParser(prog='complex')
7360+
def test_subparser_prog_is_stored_without_color(self):
7361+
parser = argparse.ArgumentParser(prog='complex', color=True)
73707362
sub = parser.add_subparsers(dest='command')
73717363
demo_parser = sub.add_parser('demo')
73727364

7373-
# Switch to NO_COLOR environment
7374-
os.environ.pop('FORCE_COLOR', None)
7375-
os.environ['NO_COLOR'] = '1'
7365+
self.assertNotIn('\x1b[', demo_parser.prog)
73767366

7377-
# Subparser help should have no color codes
7367+
demo_parser.color = False
73787368
help_text = demo_parser.format_help()
73797369
self.assertNotIn('\x1b[', help_text)
73807370

7371+
73817372
class TestModule(unittest.TestCase):
73827373
def test_deprecated__version__(self):
73837374
with self.assertWarnsRegex(

0 commit comments

Comments
 (0)