Title: [96144] trunk/Tools
Revision
96144
Author
le...@chromium.org
Date
2011-09-27 12:55:27 -0700 (Tue, 27 Sep 2011)

Log Message

watchlist: Add the filename pattern for definitions.
https://bugs.webkit.org/show_bug.cgi?id=68917

Reviewed by Adam Barth.

* Scripts/webkitpy/common/watchlist/filenamepattern.py: Added.
* Scripts/webkitpy/common/watchlist/filenamepattern_unittest.py: Added.
* Scripts/webkitpy/common/watchlist/watchlist.py: Added the filename pattern
for definitions.
* Scripts/webkitpy/common/watchlist/watchlist_unittest.py: Added tests.
* Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py: Typo fix.

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (96143 => 96144)


--- trunk/Tools/ChangeLog	2011-09-27 19:53:49 UTC (rev 96143)
+++ trunk/Tools/ChangeLog	2011-09-27 19:55:27 UTC (rev 96144)
@@ -1,3 +1,17 @@
+2011-09-27  David Levin  <le...@chromium.org>
+
+        watchlist: Add the filename pattern for definitions.
+        https://bugs.webkit.org/show_bug.cgi?id=68917
+
+        Reviewed by Adam Barth.
+
+        * Scripts/webkitpy/common/watchlist/filenamepattern.py: Added.
+        * Scripts/webkitpy/common/watchlist/filenamepattern_unittest.py: Added.
+        * Scripts/webkitpy/common/watchlist/watchlist.py: Added the filename pattern
+        for definitions.
+        * Scripts/webkitpy/common/watchlist/watchlist_unittest.py: Added tests.
+        * Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py: Typo fix.
+
 2011-09-27  Adam Barth  <aba...@webkit.org>
 
         garden-o-matic results view should sort test and builder names

Copied: trunk/Tools/Scripts/webkitpy/common/watchlist/filenamepattern.py (from rev 96142, trunk/Tools/Scripts/webkitpy/common/watchlist/watchlist.py) (0 => 96144)


--- trunk/Tools/Scripts/webkitpy/common/watchlist/filenamepattern.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/common/watchlist/filenamepattern.py	2011-09-27 19:55:27 UTC (rev 96144)
@@ -0,0 +1,37 @@
+# Copyright (C) 2011 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import re
+
+
+class FilenamePattern:
+    def __init__(self, regex):
+        self._regex = re.compile(regex + '$')
+
+    def match(self, path, diff_file):
+        return self._regex.match(path)

Copied: trunk/Tools/Scripts/webkitpy/common/watchlist/filenamepattern_unittest.py (from rev 96142, trunk/Tools/Scripts/webkitpy/common/watchlist/watchlist.py) (0 => 96144)


--- trunk/Tools/Scripts/webkitpy/common/watchlist/filenamepattern_unittest.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/common/watchlist/filenamepattern_unittest.py	2011-09-27 19:55:27 UTC (rev 96144)
@@ -0,0 +1,49 @@
+# Copyright (C) 2011 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import unittest
+from webkitpy.common.watchlist.filenamepattern import FilenamePattern
+
+
+class FileNamePatternTest(unittest.TestCase):
+    def test_filename_pattern_literal(self):
+        filename_pattern = FilenamePattern(r'MyFileName\.cpp')
+
+        # Note the follow filenames are not regex.
+        self.assertTrue(filename_pattern.match('MyFileName.cpp', None))
+        self.assertFalse(filename_pattern.match('MyFileName.cppa', None))
+        self.assertFalse(filename_pattern.match('aMyFileName.cpp', None))
+        self.assertFalse(filename_pattern.match('MyFileNamebcpp', None))
+
+    def test_filename_pattern_substring(self):
+        filename_pattern = FilenamePattern(r'.*\\MyFileName\..*')
+
+        # Note the follow filenames are not regex.
+        self.assertTrue(filename_pattern.match(r'\\MyFileName.cpp', None))
+        self.assertTrue(filename_pattern.match(r'a\\MyFileName.h', None))
+        self.assertFalse(filename_pattern.match(r'\\aMyFileName.cpp', None))

Modified: trunk/Tools/Scripts/webkitpy/common/watchlist/watchlist.py (96143 => 96144)


--- trunk/Tools/Scripts/webkitpy/common/watchlist/watchlist.py	2011-09-27 19:53:49 UTC (rev 96143)
+++ trunk/Tools/Scripts/webkitpy/common/watchlist/watchlist.py	2011-09-27 19:55:27 UTC (rev 96144)
@@ -26,6 +26,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+from webkitpy.common.checkout.diff_parser import DiffParser
 
 class WatchList(object):
     def __init__(self):
@@ -33,3 +34,21 @@
 
     def set_definitions(self, definitions):
         self._definitions = definitions
+
+    def find_matching_definitions(self, diff):
+        matching_definitions = set()
+        patch_files = DiffParser(diff.splitlines()).files
+
+        for path, diff_file in patch_files.iteritems():
+            for definition in self._definitions:
+                # If a definition has already matched, there is no need to process it.
+                if definition in matching_definitions:
+                    continue
+
+                # See if the definition matches.
+                for pattern in self._definitions[definition]:
+                    if not pattern.match(path, diff_file):
+                        break
+                else:
+                    matching_definitions.add(definition)
+        return matching_definitions

Copied: trunk/Tools/Scripts/webkitpy/common/watchlist/watchlist_unittest.py (from rev 96142, trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py) (0 => 96144)


--- trunk/Tools/Scripts/webkitpy/common/watchlist/watchlist_unittest.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/common/watchlist/watchlist_unittest.py	2011-09-27 19:55:27 UTC (rev 96144)
@@ -0,0 +1,61 @@
+# Copyright (C) 2011 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#    * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#    * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#    * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+'''Unit tests for watchlist.py.'''
+
+import unittest
+
+from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA
+from webkitpy.common.watchlist.watchlistparser import WatchListParser
+
+
+class WatchListParserTest(unittest.TestCase):
+    def setUp(self):
+        self._watch_list_parser = WatchListParser()
+
+    def test_filename_definition_no_matches(self):
+        watch_list = self._watch_list_parser.parse(
+            '{'
+            '    "DEFINITIONS": {'
+            '        "WatchList1": {'
+            '            "filename": r".*\\MyFileName\\.cpp",'
+            '        },'
+            '     },'
+            '}')
+        self.assertEquals(set([]), watch_list.find_matching_definitions(DIFF_TEST_DATA))
+
+    def test_filename_definition(self):
+        watch_list = self._watch_list_parser.parse(
+            '{'
+            '    "DEFINITIONS": {'
+            '        "WatchList1": {'
+            '            "filename": r"WebCore/rendering/style/StyleFlexibleBoxData\.h",'
+            '        },'
+            '     },'
+            '}')
+        self.assertEquals(set(['WatchList1']), watch_list.find_matching_definitions(DIFF_TEST_DATA))

Modified: trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser.py (96143 => 96144)


--- trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser.py	2011-09-27 19:53:49 UTC (rev 96143)
+++ trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser.py	2011-09-27 19:55:27 UTC (rev 96144)
@@ -28,6 +28,7 @@
 
 import re
 from webkitpy.common.watchlist.watchlist import WatchList
+from webkitpy.common.watchlist.filenamepattern import FilenamePattern
 
 
 class WatchListParser(object):
@@ -36,7 +37,7 @@
 
     def __init__(self):
         self._section_parsers = {self._DEFINITIONS: self._parse_definition_section, }
-        self._definition_pattern_parsers = {}
+        self._definition_pattern_parsers = {'filename': FilenamePattern, }
 
     def parse(self, watch_list_contents):
         watch_list = WatchList()

Modified: trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py (96143 => 96144)


--- trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py	2011-09-27 19:53:49 UTC (rev 96143)
+++ trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py	2011-09-27 19:55:27 UTC (rev 96144)
@@ -26,7 +26,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-'''Unit tests for watchlistsparser.py.'''
+'''Unit tests for watchlistparser.py.'''
 
 import re
 import unittest
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to