Changeset 57905 in webkit
- Timestamp:
- Apr 20, 2010 12:34:05 PM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r57898 r57905 1 2010-04-20 Chris Jerdonek <cjerdonek@webkit.org> 2 3 Reviewed by Shinichiro Hamaji. 4 5 For check-webkit-style, implemented __eq__() and __ne__() (the 6 built-in equality and inequality methods) for the 7 DefaultStyleErrorHandler class. 8 9 https://bugs.webkit.org/show_bug.cgi?id=37850 10 11 This will facilitate unit-testing for a subsequent patch, 12 namely for https://bugs.webkit.org/show_bug.cgi?id=37850 13 14 * Scripts/webkitpy/style/error_handlers.py: 15 - Added __eq__() and __ne__() to the DefaultStyleErrorHandler 16 class. 17 18 * Scripts/webkitpy/style/error_handlers_unittest.py: 19 - Added unit tests for __eq__() and __ne__(). 20 - Also included a minor clean-up refactoring of combining the 21 StyleErrorHandlerTestBase class (which has not needed to 22 be separate due to previous changes) into the 23 DefaultStyleErrorHandlerTest class. 24 1 25 2010-04-20 Jakub Wieczorek <jwieczorek@webkit.org> 2 26 -
trunk/WebKitTools/Scripts/webkitpy/style/error_handlers.py
r57066 r57905 87 87 self._category_totals = {} 88 88 89 # Useful for unit testing. 90 def __eq__(self, other): 91 """Return whether this instance is equal to another.""" 92 if self._configuration != other._configuration: 93 return False 94 if self._file_path != other._file_path: 95 return False 96 if self._increment_error_count != other._increment_error_count: 97 return False 98 if self._line_numbers != other._line_numbers: 99 return False 100 101 return True 102 103 # Useful for unit testing. 104 def __ne__(self, other): 105 # Python does not automatically deduce __ne__ from __eq__. 106 return not self.__eq__(other) 107 89 108 def _add_reportable_error(self, category): 90 109 """Increment the error count and return the new category total.""" -
trunk/WebKitTools/Scripts/webkitpy/style/error_handlers_unittest.py
r57066 r57905 30 30 from filter import FilterConfiguration 31 31 32 class StyleErrorHandlerTestBase(unittest.TestCase): 32 33 class DefaultStyleErrorHandlerTest(unittest.TestCase): 34 35 """Tests the DefaultStyleErrorHandler class.""" 33 36 34 37 def setUp(self): 35 38 self._error_messages = [] 36 39 self._error_count = 0 40 41 _category = "whitespace/tab" 42 """The category name for the tests in this class.""" 43 44 _file_path = "foo.h" 45 """The file path for the tests in this class.""" 37 46 38 47 def _mock_increment_error_count(self): … … 54 63 stderr_write=self._mock_stderr_write) 55 64 56 57 class DefaultStyleErrorHandlerTest(StyleErrorHandlerTestBase): 58 59 """Tests DefaultStyleErrorHandler class.""" 60 61 _category = "whitespace/tab" 62 """The category name for the tests in this class.""" 63 64 _file_path = "foo.h" 65 """The file path for the tests in this class.""" 65 def _error_handler(self, configuration, line_numbers=None): 66 return DefaultStyleErrorHandler(configuration=configuration, 67 file_path=self._file_path, 68 increment_error_count=self._mock_increment_error_count, 69 line_numbers=line_numbers) 66 70 67 71 def _check_initialized(self): … … 69 73 self.assertEquals(0, self._error_count) 70 74 self.assertEquals(0, len(self._error_messages)) 71 72 def _error_handler(self, configuration, line_numbers=None):73 return DefaultStyleErrorHandler(configuration=configuration,74 file_path=self._file_path,75 increment_error_count=self._mock_increment_error_count,76 line_numbers=line_numbers)77 75 78 76 def _call_error_handler(self, handle_error, confidence, line_number=100): … … 82 80 confidence=confidence, 83 81 message="message") 82 83 def test_eq__true_return_value(self): 84 """Test the __eq__() method for the return value of True.""" 85 handler1 = self._error_handler(configuration=None) 86 handler2 = self._error_handler(configuration=None) 87 88 self.assertTrue(handler1.__eq__(handler2)) 89 90 def test_eq__false_return_value(self): 91 """Test the __eq__() method for the return value of False.""" 92 def make_handler(configuration=self._style_checker_configuration(), 93 file_path='foo.txt', increment_error_count=lambda: True, 94 line_numbers=[100]): 95 return DefaultStyleErrorHandler(configuration=configuration, 96 file_path=file_path, 97 increment_error_count=increment_error_count, 98 line_numbers=line_numbers) 99 100 handler = make_handler() 101 102 # Establish a baseline for our comparisons below. 103 self.assertTrue(handler.__eq__(make_handler())) 104 105 # Verify that a difference in any argument causes equality to fail. 106 self.assertFalse(handler.__eq__(make_handler(configuration=None))) 107 self.assertFalse(handler.__eq__(make_handler(file_path='bar.txt'))) 108 self.assertFalse(handler.__eq__(make_handler(increment_error_count=None))) 109 self.assertFalse(handler.__eq__(make_handler(line_numbers=[50]))) 110 111 def test_ne(self): 112 """Test the __ne__() method.""" 113 # By default, __ne__ always returns true on different objects. 114 # Thus, check just the distinguishing case to verify that the 115 # code defines __ne__. 116 handler1 = self._error_handler(configuration=None) 117 handler2 = self._error_handler(configuration=None) 118 119 self.assertFalse(handler1.__ne__(handler2)) 84 120 85 121 def test_non_reportable_error(self):
Note: See TracChangeset
for help on using the changeset viewer.