Title: [159977] trunk/Tools
Revision
159977
Author
commit-qu...@webkit.org
Date
2013-12-02 15:52:34 -0800 (Mon, 02 Dec 2013)

Log Message

Remove the stderr_write attribute from StyleProcessorConfiguration
https://bugs.webkit.org/show_bug.cgi?id=124703

Patch by László Langó <la...@inf.u-szeged.hu> on 2013-12-02
Reviewed by Ryosuke Niwa.

Remove the stderr_write attribute from this class in checker and
replace its use with calls to a logging module logger. We Should
use logging module instead of writing to stderr directly.

* Scripts/webkitpy/style/checker.py: Change stderr_write attribute to logging module logger.
(check_webkit_style_configuration):
(CheckerDispatcher.dispatch): Remove FIXME comment.
(StyleProcessorConfiguration):
(StyleProcessorConfiguration.__init__):
(StyleProcessorConfiguration.write_style_error):
* Scripts/webkitpy/style/checker_unittest.py: Update test to the modification.
There is an "ERROR" prefix in log messiges from now.
(StyleProcessorConfigurationTest):
(StyleProcessorConfigurationTest._style_checker_configuration):
(StyleProcessorConfigurationTest.test_init):
(StyleProcessorConfigurationTest.test_write_style_error_emacs):
(StyleProcessorConfigurationTest.test_write_style_error_vs7):
(StyleProcessor_EndToEndTest.with):
(StyleProcessor_EndToEndTest.test_init):
(StyleProcessor_EndToEndTest.test_process):
(StyleProcessor_CodeCoverageTest.setUp):
* Scripts/webkitpy/style/error_handlers.py: Remove stderr_write usage and replace with logging module logger.
(DefaultStyleErrorHandler.__call__):
* Scripts/webkitpy/style/error_handlers_unittest.py: Update test to the modification.
There is an "ERROR" prefix in log messiges from now.
(DefaultStyleErrorHandlerTest):
(DefaultStyleErrorHandlerTest.setUp):
(DefaultStyleErrorHandlerTest._mock_increment_error_count):
(DefaultStyleErrorHandlerTest._style_checker_configuration):
(DefaultStyleErrorHandlerTest._check_initialized):
(DefaultStyleErrorHandlerTest.test_non_reportable_error):
(DefaultStyleErrorHandlerTest.test_max_reports_per_category):
(DefaultStyleErrorHandlerTest.test_line_numbers):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (159976 => 159977)


--- trunk/Tools/ChangeLog	2013-12-02 23:48:35 UTC (rev 159976)
+++ trunk/Tools/ChangeLog	2013-12-02 23:52:34 UTC (rev 159977)
@@ -1,3 +1,44 @@
+2013-12-02  László Langó  <la...@inf.u-szeged.hu>
+
+        Remove the stderr_write attribute from StyleProcessorConfiguration
+        https://bugs.webkit.org/show_bug.cgi?id=124703
+
+        Reviewed by Ryosuke Niwa.
+
+        Remove the stderr_write attribute from this class in checker and
+        replace its use with calls to a logging module logger. We Should 
+        use logging module instead of writing to stderr directly.
+
+        * Scripts/webkitpy/style/checker.py: Change stderr_write attribute to logging module logger.
+        (check_webkit_style_configuration):
+        (CheckerDispatcher.dispatch): Remove FIXME comment.
+        (StyleProcessorConfiguration):
+        (StyleProcessorConfiguration.__init__):
+        (StyleProcessorConfiguration.write_style_error):
+        * Scripts/webkitpy/style/checker_unittest.py: Update test to the modification.
+        There is an "ERROR" prefix in log messiges from now.
+        (StyleProcessorConfigurationTest):
+        (StyleProcessorConfigurationTest._style_checker_configuration):
+        (StyleProcessorConfigurationTest.test_init):
+        (StyleProcessorConfigurationTest.test_write_style_error_emacs):
+        (StyleProcessorConfigurationTest.test_write_style_error_vs7):
+        (StyleProcessor_EndToEndTest.with):
+        (StyleProcessor_EndToEndTest.test_init):
+        (StyleProcessor_EndToEndTest.test_process):
+        (StyleProcessor_CodeCoverageTest.setUp):
+        * Scripts/webkitpy/style/error_handlers.py: Remove stderr_write usage and replace with logging module logger.
+        (DefaultStyleErrorHandler.__call__):
+        * Scripts/webkitpy/style/error_handlers_unittest.py: Update test to the modification.
+        There is an "ERROR" prefix in log messiges from now.
+        (DefaultStyleErrorHandlerTest):
+        (DefaultStyleErrorHandlerTest.setUp):
+        (DefaultStyleErrorHandlerTest._mock_increment_error_count):
+        (DefaultStyleErrorHandlerTest._style_checker_configuration):
+        (DefaultStyleErrorHandlerTest._check_initialized):
+        (DefaultStyleErrorHandlerTest.test_non_reportable_error):
+        (DefaultStyleErrorHandlerTest.test_max_reports_per_category):
+        (DefaultStyleErrorHandlerTest.test_line_numbers):
+
 2013-12-02  Brian J. Burg  <b...@cs.washington.edu>
 
         Add _javascript_ style checker and teach checker.py about .js files

Modified: trunk/Tools/Scripts/webkitpy/style/checker.py (159976 => 159977)


--- trunk/Tools/Scripts/webkitpy/style/checker.py	2013-12-02 23:48:35 UTC (rev 159976)
+++ trunk/Tools/Scripts/webkitpy/style/checker.py	2013-12-02 23:52:34 UTC (rev 159977)
@@ -398,8 +398,7 @@
     return StyleProcessorConfiguration(filter_configuration=filter_configuration,
                max_reports_per_category=_MAX_REPORTS_PER_CATEGORY,
                min_confidence=options.min_confidence,
-               output_format=options.output_format,
-               stderr_write=sys.stderr.write)
+               output_format=options.output_format)
 
 
 def _create_log_handlers(stream):
@@ -654,8 +653,6 @@
         return checker
 
 
-# FIXME: Remove the stderr_write attribute from this class and replace
-#        its use with calls to a logging module logger.
 class StyleProcessorConfiguration(object):
 
     """Stores configuration values for the StyleProcessor class.
@@ -667,17 +664,13 @@
       max_reports_per_category: The maximum number of errors to report
                                 per category, per file.
 
-      stderr_write: A function that takes a string as a parameter and
-                    serves as stderr.write.
-
     """
 
     def __init__(self,
                  filter_configuration,
                  max_reports_per_category,
                  min_confidence,
-                 output_format,
-                 stderr_write):
+                 output_format):
         """Create a StyleProcessorConfiguration instance.
 
         Args:
@@ -696,16 +689,12 @@
                          output formats are "emacs" which emacs can parse
                          and "vs7" which Microsoft Visual Studio 7 can parse.
 
-          stderr_write: A function that takes a string as a parameter and
-                        serves as stderr.write.
-
         """
         self._filter_configuration = filter_configuration
         self._output_format = output_format
 
         self.max_reports_per_category = max_reports_per_category
         self.min_confidence = min_confidence
-        self.stderr_write = stderr_write
 
     def is_reportable(self, category, confidence_in_error, file_path):
         """Return whether an error is reportable.
@@ -735,11 +724,11 @@
                           message):
         """Write a style error to the configured stderr."""
         if self._output_format == 'vs7':
-            format_string = "%s(%s):  %s  [%s] [%d]\n"
+            format_string = "%s(%s):  %s  [%s] [%d]"
         else:
-            format_string = "%s:%s:  %s  [%s] [%d]\n"
+            format_string = "%s:%s:  %s  [%s] [%d]"
 
-        self.stderr_write(format_string % (file_path,
+        _log.error(format_string % (file_path,
                                            line_number,
                                            message,
                                            category,

Modified: trunk/Tools/Scripts/webkitpy/style/checker_unittest.py (159976 => 159977)


--- trunk/Tools/Scripts/webkitpy/style/checker_unittest.py	2013-12-02 23:48:35 UTC (rev 159976)
+++ trunk/Tools/Scripts/webkitpy/style/checker_unittest.py	2013-12-02 23:52:34 UTC (rev 159977)
@@ -596,17 +596,10 @@
             self.assert_checker_none(path)
 
 
-class StyleProcessorConfigurationTest(unittest.TestCase):
+class StyleProcessorConfigurationTest(LoggingTestCase):
 
     """Tests the StyleProcessorConfiguration class."""
 
-    def setUp(self):
-        self._error_messages = []
-        """The messages written to _mock_stderr_write() of this class."""
-
-    def _mock_stderr_write(self, message):
-        self._error_messages.append(message)
-
     def _style_checker_configuration(self, output_format="vs7"):
         """Return a StyleProcessorConfiguration instance for testing."""
         base_rules = ["-whitespace", "+whitespace/tab"]
@@ -616,8 +609,7 @@
                    filter_configuration=filter_configuration,
                    max_reports_per_category={"whitespace/newline": 1},
                    min_confidence=3,
-                   output_format=output_format,
-                   stderr_write=self._mock_stderr_write)
+                   output_format=output_format)
 
     def test_init(self):
         """Test the __init__() method."""
@@ -626,7 +618,6 @@
         # Check that __init__ sets the "public" data attributes correctly.
         self.assertEqual(configuration.max_reports_per_category,
                           {"whitespace/newline": 1})
-        self.assertEqual(configuration.stderr_write, self._mock_stderr_write)
         self.assertEqual(configuration.min_confidence, 3)
 
     def test_is_reportable(self):
@@ -652,56 +643,44 @@
     def test_write_style_error_emacs(self):
         """Test the write_style_error() method."""
         self._call_write_style_error("emacs")
-        self.assertEqual(self._error_messages,
-                          ["foo.h:100:  message  [whitespace/tab] [5]\n"])
+        self.assertLog(["ERROR: foo.h:100:  message  [whitespace/tab] [5]\n"])
 
     def test_write_style_error_vs7(self):
         """Test the write_style_error() method."""
         self._call_write_style_error("vs7")
-        self.assertEqual(self._error_messages,
-                          ["foo.h(100):  message  [whitespace/tab] [5]\n"])
+        self.assertLog(["ERROR: foo.h(100):  message  [whitespace/tab] [5]\n"])
 
 
 class StyleProcessor_EndToEndTest(LoggingTestCase):
 
     """Test the StyleProcessor class with an emphasis on end-to-end tests."""
 
-    def setUp(self):
-        LoggingTestCase.setUp(self)
-        self._messages = []
-
-    def _mock_stderr_write(self, message):
-        """Save a message so it can later be asserted."""
-        self._messages.append(message)
-
     def test_init(self):
         """Test __init__ constructor."""
         configuration = StyleProcessorConfiguration(
                             filter_configuration=FilterConfiguration(),
                             max_reports_per_category={},
                             min_confidence=3,
-                            output_format="vs7",
-                            stderr_write=self._mock_stderr_write)
+                            output_format="vs7")
         processor = StyleProcessor(configuration)
 
         self.assertEqual(processor.error_count, 0)
-        self.assertEqual(self._messages, [])
 
     def test_process(self):
         configuration = StyleProcessorConfiguration(
                             filter_configuration=FilterConfiguration(),
                             max_reports_per_category={},
                             min_confidence=3,
-                            output_format="vs7",
-                            stderr_write=self._mock_stderr_write)
+                            output_format="vs7")
         processor = StyleProcessor(configuration)
 
         processor.process(lines=['line1', 'Line with tab:\t'],
                           file_path='foo.txt')
+
         self.assertEqual(processor.error_count, 1)
-        expected_messages = ['foo.txt(2):  Line contains tab character.  '
+        expected_messages = ['ERROR: foo.txt(2):  Line contains tab character.  '
                              '[whitespace/tab] [5]\n']
-        self.assertEqual(self._messages, expected_messages)
+        self.assertLog(expected_messages)
 
 
 class StyleProcessor_CodeCoverageTest(LoggingTestCase):
@@ -763,8 +742,7 @@
                             filter_configuration=FilterConfiguration(),
                             max_reports_per_category={"whitespace/newline": 1},
                             min_confidence=3,
-                            output_format="vs7",
-                            stderr_write=self._swallow_stderr_message)
+                            output_format="vs7")
 
         mock_carriage_checker_class = self._create_carriage_checker_class()
         mock_dispatcher = self.MockDispatcher()

Modified: trunk/Tools/Scripts/webkitpy/style/error_handlers.py (159976 => 159977)


--- trunk/Tools/Scripts/webkitpy/style/error_handlers.py	2013-12-02 23:48:35 UTC (rev 159976)
+++ trunk/Tools/Scripts/webkitpy/style/error_handlers.py	2013-12-02 23:52:34 UTC (rev 159977)
@@ -49,9 +49,13 @@
 """
 
 
+import logging
 import sys
 
 
+_log = logging.getLogger(__name__)
+
+
 class DefaultStyleErrorHandler(object):
 
     """The default style error handler."""
@@ -159,6 +163,6 @@
                                               line_number=line_number,
                                               message=message)
         if category_total == max_reports:
-            self._configuration.stderr_write("Suppressing further [%s] reports "
-                                             "for this file.\n" % category)
+            _log.error("Suppressing further [%s] reports "
+                                             "for this file." % category)
         return True

Modified: trunk/Tools/Scripts/webkitpy/style/error_handlers_unittest.py (159976 => 159977)


--- trunk/Tools/Scripts/webkitpy/style/error_handlers_unittest.py	2013-12-02 23:48:35 UTC (rev 159976)
+++ trunk/Tools/Scripts/webkitpy/style/error_handlers_unittest.py	2013-12-02 23:52:34 UTC (rev 159977)
@@ -28,14 +28,15 @@
 from checker import StyleProcessorConfiguration
 from error_handlers import DefaultStyleErrorHandler
 from filter import FilterConfiguration
+from webkitpy.common.system.logtesting import LoggingTestCase
 
 
-class DefaultStyleErrorHandlerTest(unittest.TestCase):
+class DefaultStyleErrorHandlerTest(LoggingTestCase):
 
     """Tests the DefaultStyleErrorHandler class."""
 
     def setUp(self):
-        self._error_messages = []
+        super(DefaultStyleErrorHandlerTest, self).setUp()
         self._error_count = 0
 
     _category = "whitespace/tab"
@@ -47,9 +48,6 @@
     def _mock_increment_error_count(self):
         self._error_count += 1
 
-    def _mock_stderr_write(self, message):
-        self._error_messages.append(message)
-
     def _style_checker_configuration(self):
         """Return a StyleProcessorConfiguration instance for testing."""
         base_rules = ["-whitespace", "+whitespace/tab"]
@@ -59,8 +57,7 @@
                    filter_configuration=filter_configuration,
                    max_reports_per_category={"whitespace/tab": 2},
                    min_confidence=3,
-                   output_format="vs7",
-                   stderr_write=self._mock_stderr_write)
+                   output_format="vs7")
 
     def _error_handler(self, configuration, line_numbers=None):
         return DefaultStyleErrorHandler(configuration=configuration,
@@ -71,7 +68,6 @@
     def _check_initialized(self):
         """Check that count and error messages are initialized."""
         self.assertEqual(0, self._error_count)
-        self.assertEqual(0, len(self._error_messages))
 
     def _call_error_handler(self, handle_error, confidence, line_number=100):
         """Call the given error handler with a test error."""
@@ -132,7 +128,6 @@
         self._call_error_handler(error_handler, confidence)
 
         self.assertEqual(0, self._error_count)
-        self.assertEqual([], self._error_messages)
 
     # Also serves as a reportable error test.
     def test_max_reports_per_category(self):
@@ -146,26 +141,21 @@
         # First call: usual reporting.
         self._call_error_handler(error_handler, confidence)
         self.assertEqual(1, self._error_count)
-        self.assertEqual(1, len(self._error_messages))
-        self.assertEqual(self._error_messages,
-                          ["foo.h(100):  message  [whitespace/tab] [5]\n"])
+        self.assertLog(["ERROR: foo.h(100):  message  [whitespace/tab] [5]\n"])
 
         # Second call: suppression message reported.
         self._call_error_handler(error_handler, confidence)
         # The "Suppressing further..." message counts as an additional
         # message (but not as an addition to the error count).
         self.assertEqual(2, self._error_count)
-        self.assertEqual(3, len(self._error_messages))
-        self.assertEqual(self._error_messages[-2],
-                          "foo.h(100):  message  [whitespace/tab] [5]\n")
-        self.assertEqual(self._error_messages[-1],
-                          "Suppressing further [whitespace/tab] reports "
-                          "for this file.\n")
+        expected_message = ["ERROR: foo.h(100):  message  [whitespace/tab] [5]\n",
+                            "ERROR: Suppressing further [whitespace/tab] reports for this file.\n"]
+        self.assertLog(expected_message)
 
         # Third call: no report.
         self._call_error_handler(error_handler, confidence)
         self.assertEqual(3, self._error_count)
-        self.assertEqual(3, len(self._error_messages))
+        self.assertLog([])
 
     def test_line_numbers(self):
         """Test the line_numbers parameter."""
@@ -178,19 +168,16 @@
         # Error on non-modified line: no error.
         self._call_error_handler(error_handler, confidence, line_number=60)
         self.assertEqual(0, self._error_count)
-        self.assertEqual([], self._error_messages)
+        self.assertLog([])
 
         # Error on modified line: error.
         self._call_error_handler(error_handler, confidence, line_number=50)
         self.assertEqual(1, self._error_count)
-        self.assertEqual(self._error_messages,
-                          ["foo.h(50):  message  [whitespace/tab] [5]\n"])
+        self.assertLog(["ERROR: foo.h(50):  message  [whitespace/tab] [5]\n"])
 
         # Error on non-modified line after turning off line filtering: error.
         error_handler.turn_off_line_filtering()
         self._call_error_handler(error_handler, confidence, line_number=60)
         self.assertEqual(2, self._error_count)
-        self.assertEqual(self._error_messages,
-                          ['foo.h(50):  message  [whitespace/tab] [5]\n',
-                           'foo.h(60):  message  [whitespace/tab] [5]\n',
-                           'Suppressing further [whitespace/tab] reports for this file.\n'])
+        self.assertLog(['ERROR: foo.h(60):  message  [whitespace/tab] [5]\n',
+                        'ERROR: Suppressing further [whitespace/tab] reports for this file.\n'])
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to