|
22 | 22 | captured_stderr, |
23 | 23 | force_not_colorized, |
24 | 24 | force_not_colorized_test_class, |
| 25 | + swap_attr, |
25 | 26 | ) |
26 | 27 | from test.support import import_helper |
27 | 28 | from test.support import os_helper |
@@ -7128,7 +7129,8 @@ class TestColorized(TestCase): |
7128 | 7129 | def setUp(self): |
7129 | 7130 | super().setUp() |
7130 | 7131 | # Ensure color even if ran with NO_COLOR=1 |
7131 | | - _colorize.can_colorize = lambda *args, **kwargs: True |
| 7132 | + self.enterContext(swap_attr(_colorize, 'can_colorize', |
| 7133 | + lambda *args, **kwargs: True)) |
7132 | 7134 | self.theme = _colorize.get_theme(force_color=True).argparse |
7133 | 7135 |
|
7134 | 7136 | def test_argparse_color(self): |
@@ -7355,6 +7357,17 @@ def __init__(self, prog): |
7355 | 7357 | {short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset} foo help |
7356 | 7358 | ''')) |
7357 | 7359 |
|
| 7360 | + def test_subparser_prog_is_stored_without_color(self): |
| 7361 | + parser = argparse.ArgumentParser(prog='complex', color=True) |
| 7362 | + sub = parser.add_subparsers(dest='command') |
| 7363 | + demo_parser = sub.add_parser('demo') |
| 7364 | + |
| 7365 | + self.assertNotIn('\x1b[', demo_parser.prog) |
| 7366 | + |
| 7367 | + demo_parser.color = False |
| 7368 | + help_text = demo_parser.format_help() |
| 7369 | + self.assertNotIn('\x1b[', help_text) |
| 7370 | + |
7358 | 7371 |
|
7359 | 7372 | class TestModule(unittest.TestCase): |
7360 | 7373 | def test_deprecated__version__(self): |
|
0 commit comments