@@ -2283,6 +2283,7 @@ class TestNegativeNumber(ParserTestCase):
22832283 ('--complex -1e-3j' , NS (int = None , float = None , complex = - 0.001j )),
22842284 ]
22852285
2286+ @force_not_colorized_test_class
22862287class TestArgumentAndSubparserSuggestions (TestCase ):
22872288 """Test error handling and suggestion when a user makes a typo"""
22882289
@@ -6147,6 +6148,7 @@ def spam(string_to_convert):
61476148# Check that deprecated arguments output warning
61486149# ==============================================
61496150
6151+ @force_not_colorized_test_class
61506152class TestDeprecatedArguments (TestCase ):
61516153
61526154 def test_deprecated_option (self ):
@@ -7370,6 +7372,45 @@ def test_subparser_prog_is_stored_without_color(self):
73707372 help_text = demo_parser .format_help ()
73717373 self .assertNotIn ('\x1b [' , help_text )
73727374
7375+ def test_error_and_warning_keywords_colorized (self ):
7376+ parser = argparse .ArgumentParser (prog = 'PROG' )
7377+ parser .add_argument ('foo' )
7378+
7379+ with self .assertRaises (SystemExit ):
7380+ with captured_stderr () as stderr :
7381+ parser .parse_args ([])
7382+
7383+ err = stderr .getvalue ()
7384+ error_color = self .theme .error
7385+ reset = self .theme .reset
7386+ self .assertIn (f'{ error_color } error:{ reset } ' , err )
7387+
7388+ with captured_stderr () as stderr :
7389+ parser ._warning ('test warning' )
7390+
7391+ warn = stderr .getvalue ()
7392+ warning_color = self .theme .warning
7393+ self .assertIn (f'{ warning_color } warning:{ reset } ' , warn )
7394+
7395+ def test_error_and_warning_not_colorized_when_disabled (self ):
7396+ parser = argparse .ArgumentParser (prog = 'PROG' , color = False )
7397+ parser .add_argument ('foo' )
7398+
7399+ with self .assertRaises (SystemExit ):
7400+ with captured_stderr () as stderr :
7401+ parser .parse_args ([])
7402+
7403+ err = stderr .getvalue ()
7404+ self .assertNotIn ('\x1b [' , err )
7405+ self .assertIn ('error:' , err )
7406+
7407+ with captured_stderr () as stderr :
7408+ parser ._warning ('test warning' )
7409+
7410+ warn = stderr .getvalue ()
7411+ self .assertNotIn ('\x1b [' , warn )
7412+ self .assertIn ('warning:' , warn )
7413+
73737414
73747415class TestModule (unittest .TestCase ):
73757416 def test_deprecated__version__ (self ):
0 commit comments