Changeset 159977 in webkit


Ignore:
Timestamp:
Dec 2, 2013 3:52:34 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by László Langó <lango@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):

Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r159969 r159977  
     12013-12-02  László Langó  <lango@inf.u-szeged.hu>
     2
     3        Remove the stderr_write attribute from StyleProcessorConfiguration
     4        https://bugs.webkit.org/show_bug.cgi?id=124703
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Remove the stderr_write attribute from this class in checker and
     9        replace its use with calls to a logging module logger. We Should
     10        use logging module instead of writing to stderr directly.
     11
     12        * Scripts/webkitpy/style/checker.py: Change stderr_write attribute to logging module logger.
     13        (check_webkit_style_configuration):
     14        (CheckerDispatcher.dispatch): Remove FIXME comment.
     15        (StyleProcessorConfiguration):
     16        (StyleProcessorConfiguration.__init__):
     17        (StyleProcessorConfiguration.write_style_error):
     18        * Scripts/webkitpy/style/checker_unittest.py: Update test to the modification.
     19        There is an "ERROR" prefix in log messiges from now.
     20        (StyleProcessorConfigurationTest):
     21        (StyleProcessorConfigurationTest._style_checker_configuration):
     22        (StyleProcessorConfigurationTest.test_init):
     23        (StyleProcessorConfigurationTest.test_write_style_error_emacs):
     24        (StyleProcessorConfigurationTest.test_write_style_error_vs7):
     25        (StyleProcessor_EndToEndTest.with):
     26        (StyleProcessor_EndToEndTest.test_init):
     27        (StyleProcessor_EndToEndTest.test_process):
     28        (StyleProcessor_CodeCoverageTest.setUp):
     29        * Scripts/webkitpy/style/error_handlers.py: Remove stderr_write usage and replace with logging module logger.
     30        (DefaultStyleErrorHandler.__call__):
     31        * Scripts/webkitpy/style/error_handlers_unittest.py: Update test to the modification.
     32        There is an "ERROR" prefix in log messiges from now.
     33        (DefaultStyleErrorHandlerTest):
     34        (DefaultStyleErrorHandlerTest.setUp):
     35        (DefaultStyleErrorHandlerTest._mock_increment_error_count):
     36        (DefaultStyleErrorHandlerTest._style_checker_configuration):
     37        (DefaultStyleErrorHandlerTest._check_initialized):
     38        (DefaultStyleErrorHandlerTest.test_non_reportable_error):
     39        (DefaultStyleErrorHandlerTest.test_max_reports_per_category):
     40        (DefaultStyleErrorHandlerTest.test_line_numbers):
     41
    1422013-12-02  Brian J. Burg  <burg@cs.washington.edu>
    243
  • trunk/Tools/Scripts/webkitpy/style/checker.py

    r159969 r159977  
    399399               max_reports_per_category=_MAX_REPORTS_PER_CATEGORY,
    400400               min_confidence=options.min_confidence,
    401                output_format=options.output_format,
    402                stderr_write=sys.stderr.write)
     401               output_format=options.output_format)
    403402
    404403
     
    655654
    656655
    657 # FIXME: Remove the stderr_write attribute from this class and replace
    658 #        its use with calls to a logging module logger.
    659656class StyleProcessorConfiguration(object):
    660657
     
    667664      max_reports_per_category: The maximum number of errors to report
    668665                                per category, per file.
    669 
    670       stderr_write: A function that takes a string as a parameter and
    671                     serves as stderr.write.
    672666
    673667    """
     
    677671                 max_reports_per_category,
    678672                 min_confidence,
    679                  output_format,
    680                  stderr_write):
     673                 output_format):
    681674        """Create a StyleProcessorConfiguration instance.
    682675
     
    697690                         and "vs7" which Microsoft Visual Studio 7 can parse.
    698691
    699           stderr_write: A function that takes a string as a parameter and
    700                         serves as stderr.write.
    701 
    702692        """
    703693        self._filter_configuration = filter_configuration
     
    706696        self.max_reports_per_category = max_reports_per_category
    707697        self.min_confidence = min_confidence
    708         self.stderr_write = stderr_write
    709698
    710699    def is_reportable(self, category, confidence_in_error, file_path):
     
    736725        """Write a style error to the configured stderr."""
    737726        if self._output_format == 'vs7':
    738             format_string = "%s(%s):  %s  [%s] [%d]\n"
     727            format_string = "%s(%s):  %s  [%s] [%d]"
    739728        else:
    740             format_string = "%s:%s:  %s  [%s] [%d]\n"
    741 
    742         self.stderr_write(format_string % (file_path,
     729            format_string = "%s:%s:  %s  [%s] [%d]"
     730
     731        _log.error(format_string % (file_path,
    743732                                           line_number,
    744733                                           message,
  • trunk/Tools/Scripts/webkitpy/style/checker_unittest.py

    r159969 r159977  
    597597
    598598
    599 class StyleProcessorConfigurationTest(unittest.TestCase):
     599class StyleProcessorConfigurationTest(LoggingTestCase):
    600600
    601601    """Tests the StyleProcessorConfiguration class."""
    602 
    603     def setUp(self):
    604         self._error_messages = []
    605         """The messages written to _mock_stderr_write() of this class."""
    606 
    607     def _mock_stderr_write(self, message):
    608         self._error_messages.append(message)
    609602
    610603    def _style_checker_configuration(self, output_format="vs7"):
     
    617610                   max_reports_per_category={"whitespace/newline": 1},
    618611                   min_confidence=3,
    619                    output_format=output_format,
    620                    stderr_write=self._mock_stderr_write)
     612                   output_format=output_format)
    621613
    622614    def test_init(self):
     
    627619        self.assertEqual(configuration.max_reports_per_category,
    628620                          {"whitespace/newline": 1})
    629         self.assertEqual(configuration.stderr_write, self._mock_stderr_write)
    630621        self.assertEqual(configuration.min_confidence, 3)
    631622
     
    653644        """Test the write_style_error() method."""
    654645        self._call_write_style_error("emacs")
    655         self.assertEqual(self._error_messages,
    656                           ["foo.h:100:  message  [whitespace/tab] [5]\n"])
     646        self.assertLog(["ERROR: foo.h:100:  message  [whitespace/tab] [5]\n"])
    657647
    658648    def test_write_style_error_vs7(self):
    659649        """Test the write_style_error() method."""
    660650        self._call_write_style_error("vs7")
    661         self.assertEqual(self._error_messages,
    662                           ["foo.h(100):  message  [whitespace/tab] [5]\n"])
     651        self.assertLog(["ERROR: foo.h(100):  message  [whitespace/tab] [5]\n"])
    663652
    664653
     
    666655
    667656    """Test the StyleProcessor class with an emphasis on end-to-end tests."""
    668 
    669     def setUp(self):
    670         LoggingTestCase.setUp(self)
    671         self._messages = []
    672 
    673     def _mock_stderr_write(self, message):
    674         """Save a message so it can later be asserted."""
    675         self._messages.append(message)
    676657
    677658    def test_init(self):
     
    681662                            max_reports_per_category={},
    682663                            min_confidence=3,
    683                             output_format="vs7",
    684                             stderr_write=self._mock_stderr_write)
     664                            output_format="vs7")
    685665        processor = StyleProcessor(configuration)
    686666
    687667        self.assertEqual(processor.error_count, 0)
    688         self.assertEqual(self._messages, [])
    689668
    690669    def test_process(self):
     
    693672                            max_reports_per_category={},
    694673                            min_confidence=3,
    695                             output_format="vs7",
    696                             stderr_write=self._mock_stderr_write)
     674                            output_format="vs7")
    697675        processor = StyleProcessor(configuration)
    698676
    699677        processor.process(lines=['line1', 'Line with tab:\t'],
    700678                          file_path='foo.txt')
     679
    701680        self.assertEqual(processor.error_count, 1)
    702         expected_messages = ['foo.txt(2):  Line contains tab character.  '
     681        expected_messages = ['ERROR: foo.txt(2):  Line contains tab character.  '
    703682                             '[whitespace/tab] [5]\n']
    704         self.assertEqual(self._messages, expected_messages)
     683        self.assertLog(expected_messages)
    705684
    706685
     
    764743                            max_reports_per_category={"whitespace/newline": 1},
    765744                            min_confidence=3,
    766                             output_format="vs7",
    767                             stderr_write=self._swallow_stderr_message)
     745                            output_format="vs7")
    768746
    769747        mock_carriage_checker_class = self._create_carriage_checker_class()
  • trunk/Tools/Scripts/webkitpy/style/error_handlers.py

    r111864 r159977  
    5050
    5151
     52import logging
    5253import sys
     54
     55
     56_log = logging.getLogger(__name__)
    5357
    5458
     
    160164                                              message=message)
    161165        if category_total == max_reports:
    162             self._configuration.stderr_write("Suppressing further [%s] reports "
    163                                              "for this file.\n" % category)
     166            _log.error("Suppressing further [%s] reports "
     167                                             "for this file." % category)
    164168        return True
  • trunk/Tools/Scripts/webkitpy/style/error_handlers_unittest.py

    r140510 r159977  
    2929from error_handlers import DefaultStyleErrorHandler
    3030from filter import FilterConfiguration
     31from webkitpy.common.system.logtesting import LoggingTestCase
    3132
    3233
    33 class DefaultStyleErrorHandlerTest(unittest.TestCase):
     34class DefaultStyleErrorHandlerTest(LoggingTestCase):
    3435
    3536    """Tests the DefaultStyleErrorHandler class."""
    3637
    3738    def setUp(self):
    38         self._error_messages = []
     39        super(DefaultStyleErrorHandlerTest, self).setUp()
    3940        self._error_count = 0
    4041
     
    4849        self._error_count += 1
    4950
    50     def _mock_stderr_write(self, message):
    51         self._error_messages.append(message)
    52 
    5351    def _style_checker_configuration(self):
    5452        """Return a StyleProcessorConfiguration instance for testing."""
     
    6058                   max_reports_per_category={"whitespace/tab": 2},
    6159                   min_confidence=3,
    62                    output_format="vs7",
    63                    stderr_write=self._mock_stderr_write)
     60                   output_format="vs7")
    6461
    6562    def _error_handler(self, configuration, line_numbers=None):
     
    7269        """Check that count and error messages are initialized."""
    7370        self.assertEqual(0, self._error_count)
    74         self.assertEqual(0, len(self._error_messages))
    7571
    7672    def _call_error_handler(self, handle_error, confidence, line_number=100):
     
    133129
    134130        self.assertEqual(0, self._error_count)
    135         self.assertEqual([], self._error_messages)
    136131
    137132    # Also serves as a reportable error test.
     
    147142        self._call_error_handler(error_handler, confidence)
    148143        self.assertEqual(1, self._error_count)
    149         self.assertEqual(1, len(self._error_messages))
    150         self.assertEqual(self._error_messages,
    151                           ["foo.h(100):  message  [whitespace/tab] [5]\n"])
     144        self.assertLog(["ERROR: foo.h(100):  message  [whitespace/tab] [5]\n"])
    152145
    153146        # Second call: suppression message reported.
     
    156149        # message (but not as an addition to the error count).
    157150        self.assertEqual(2, self._error_count)
    158         self.assertEqual(3, len(self._error_messages))
    159         self.assertEqual(self._error_messages[-2],
    160                           "foo.h(100):  message  [whitespace/tab] [5]\n")
    161         self.assertEqual(self._error_messages[-1],
    162                           "Suppressing further [whitespace/tab] reports "
    163                           "for this file.\n")
     151        expected_message = ["ERROR: foo.h(100):  message  [whitespace/tab] [5]\n",
     152                            "ERROR: Suppressing further [whitespace/tab] reports for this file.\n"]
     153        self.assertLog(expected_message)
    164154
    165155        # Third call: no report.
    166156        self._call_error_handler(error_handler, confidence)
    167157        self.assertEqual(3, self._error_count)
    168         self.assertEqual(3, len(self._error_messages))
     158        self.assertLog([])
    169159
    170160    def test_line_numbers(self):
     
    179169        self._call_error_handler(error_handler, confidence, line_number=60)
    180170        self.assertEqual(0, self._error_count)
    181         self.assertEqual([], self._error_messages)
     171        self.assertLog([])
    182172
    183173        # Error on modified line: error.
    184174        self._call_error_handler(error_handler, confidence, line_number=50)
    185175        self.assertEqual(1, self._error_count)
    186         self.assertEqual(self._error_messages,
    187                           ["foo.h(50):  message  [whitespace/tab] [5]\n"])
     176        self.assertLog(["ERROR: foo.h(50):  message  [whitespace/tab] [5]\n"])
    188177
    189178        # Error on non-modified line after turning off line filtering: error.
     
    191180        self._call_error_handler(error_handler, confidence, line_number=60)
    192181        self.assertEqual(2, self._error_count)
    193         self.assertEqual(self._error_messages,
    194                           ['foo.h(50):  message  [whitespace/tab] [5]\n',
    195                            'foo.h(60):  message  [whitespace/tab] [5]\n',
    196                            'Suppressing further [whitespace/tab] reports for this file.\n'])
     182        self.assertLog(['ERROR: foo.h(60):  message  [whitespace/tab] [5]\n',
     183                        'ERROR: Suppressing further [whitespace/tab] reports for this file.\n'])
Note: See TracChangeset for help on using the changeset viewer.