Changeset 54234 in webkit
- Timestamp:
- Feb 2, 2010 7:28:11 AM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r54206 r54234 1 2010-02-02 Chris Jerdonek <cjerdonek@webkit.org> 2 3 Reviewed by Shinichiro Hamaji. 4 5 Moved filter-related check-webkit-style code into a separate 6 filter module. 7 8 https://bugs.webkit.org/show_bug.cgi?id=34408 9 10 This is preparatory refactoring for Bug 33684, which will allow 11 file and folder-specific filter rules. 12 13 * Scripts/webkitpy/style/checker.py: 14 - Removed CategoryFilter class (moved to filter.py). 15 16 * Scripts/webkitpy/style/checker_unittest.py: 17 - Removed CategoryFilter unit tests (moved to filter_unittest.py). 18 19 * Scripts/webkitpy/style/filter.py: Added. 20 - Added CategoryFilter class (moved from checker.py). 21 22 * Scripts/webkitpy/style/filter_unittest.py: Added. 23 - Added CategoryFilter unit tests (moved from checker_unittest.py). 24 25 * Scripts/webkitpy/style/unittests.py: 26 - Added reference to filter_unittest.py. 27 1 28 2010-02-01 Chris Jerdonek <cjerdonek@webkit.org> 2 29 -
trunk/WebKitTools/Scripts/webkitpy/style/checker.py
r54206 r54234 38 38 from error_handlers import DefaultStyleErrorHandler 39 39 from error_handlers import PatchStyleErrorHandler 40 from filter import CategoryFilter 40 41 from processors.common import check_no_carriage_return 41 42 from processors.common import categories as CommonCategories … … 109 110 110 111 111 # FIXME: Check that the keys are in _style_categories().112 #113 112 # The maximum number of errors to report per file, per category. 114 113 # If a category is not a key, then it has no maximum. … … 201 200 202 201 return usage 203 204 205 class CategoryFilter(object):206 207 """Filters whether to check style categories."""208 209 def __init__(self, filter_rules=None):210 """Create a category filter.211 212 This method performs argument validation but does not strip213 leading or trailing white space.214 215 Args:216 filter_rules: A list of strings that are filter rules, which217 are strings beginning with the plus or minus218 symbol (+/-). The list should include any219 default filter rules at the beginning.220 Defaults to the empty list.221 222 Raises:223 ValueError: Invalid filter rule if a rule does not start with224 plus ("+") or minus ("-").225 226 """227 if filter_rules is None:228 filter_rules = []229 230 for rule in filter_rules:231 if not (rule.startswith('+') or rule.startswith('-')):232 raise ValueError('Invalid filter rule "%s": every rule '233 'rule in the --filter flag must start '234 'with + or -.' % rule)235 236 self._filter_rules = filter_rules237 self._should_check_category = {} # Cached dictionary of category to True/False238 239 def __str__(self):240 return ",".join(self._filter_rules)241 242 # Useful for unit testing.243 def __eq__(self, other):244 """Return whether this CategoryFilter instance is equal to another."""245 return self._filter_rules == other._filter_rules246 247 # Useful for unit testing.248 def __ne__(self, other):249 # Python does not automatically deduce from __eq__().250 return not (self == other)251 252 def should_check(self, category):253 """Return whether the category should be checked.254 255 The rules for determining whether a category should be checked256 are as follows. By default all categories should be checked.257 Then apply the filter rules in order from first to last, with258 later flags taking precedence.259 260 A filter rule applies to a category if the string after the261 leading plus/minus (+/-) matches the beginning of the category262 name. A plus (+) means the category should be checked, while a263 minus (-) means the category should not be checked.264 265 """266 if category in self._should_check_category:267 return self._should_check_category[category]268 269 should_check = True # All categories checked by default.270 for rule in self._filter_rules:271 if not category.startswith(rule[1:]):272 continue273 should_check = rule.startswith('+')274 self._should_check_category[category] = should_check # Update cache.275 return should_check276 202 277 203 -
trunk/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
r54206 r54234 38 38 39 39 import checker as style 40 from checker import CategoryFilter41 40 from checker import ProcessorDispatcher 42 41 from checker import ProcessorOptions 43 42 from checker import StyleChecker 43 from filter import CategoryFilter 44 44 from processors.cpp import CppProcessor 45 45 from processors.text import TextProcessor 46 47 class CategoryFilterTest(unittest.TestCase):48 49 """Tests CategoryFilter class."""50 51 def test_init(self):52 """Test __init__ constructor."""53 self.assertRaises(ValueError, CategoryFilter, ["no_prefix"])54 CategoryFilter() # No ValueError: works55 CategoryFilter(["+"]) # No ValueError: works56 CategoryFilter(["-"]) # No ValueError: works57 58 def test_str(self):59 """Test __str__ "to string" operator."""60 filter = CategoryFilter(["+a", "-b"])61 self.assertEquals(str(filter), "+a,-b")62 63 def test_eq(self):64 """Test __eq__ equality function."""65 filter1 = CategoryFilter(["+a", "+b"])66 filter2 = CategoryFilter(["+a", "+b"])67 filter3 = CategoryFilter(["+b", "+a"])68 69 # == calls __eq__.70 self.assertTrue(filter1 == filter2)71 self.assertFalse(filter1 == filter3) # Cannot test with assertNotEqual.72 73 def test_ne(self):74 """Test __ne__ inequality function."""75 # != calls __ne__.76 # By default, __ne__ always returns true on different objects.77 # Thus, just check the distinguishing case to verify that the78 # code defines __ne__.79 self.assertFalse(CategoryFilter() != CategoryFilter())80 81 def test_should_check(self):82 """Test should_check() method."""83 filter = CategoryFilter()84 self.assertTrue(filter.should_check("everything"))85 # Check a second time to exercise cache.86 self.assertTrue(filter.should_check("everything"))87 88 filter = CategoryFilter(["-"])89 self.assertFalse(filter.should_check("anything"))90 # Check a second time to exercise cache.91 self.assertFalse(filter.should_check("anything"))92 93 filter = CategoryFilter(["-", "+ab"])94 self.assertTrue(filter.should_check("abc"))95 self.assertFalse(filter.should_check("a"))96 97 filter = CategoryFilter(["+", "-ab"])98 self.assertFalse(filter.should_check("abc"))99 self.assertTrue(filter.should_check("a"))100 46 101 47 -
trunk/WebKitTools/Scripts/webkitpy/style/unittests.py
r54206 r54234 38 38 from checker_unittest import * 39 39 from error_handlers_unittest import * 40 from filter_unittest import * 40 41 from processors.common_unittest import * 41 42 from processors.cpp_unittest import *
Note: See TracChangeset
for help on using the changeset viewer.