Title: [124131] trunk/Tools
Revision
124131
Author
[email protected]
Date
2012-07-30 18:02:13 -0700 (Mon, 30 Jul 2012)

Log Message

nrwt: split test-finding code out from manager.py
https://bugs.webkit.org/show_bug.cgi?id=92693

Reviewed by Ryosuke Niwa.

In the interest of making manager.py smaller, this patch moves
the code that actually takes the command line arguments and
--test-file lists of tests to run and expands them into an
actual list of tests out into a separate module.

* Scripts/webkitpy/layout_tests/controllers/finder.py: Added.
(LayoutTestFinder):
(LayoutTestFinder.__init__):
(LayoutTestFinder.find_tests):
(LayoutTestFinder._strip_test_dir_prefixes):
(LayoutTestFinder._strip_test_dir_prefix):
(LayoutTestFinder._read_test_names_from_file):
* Scripts/webkitpy/layout_tests/controllers/manager.py:
(Manager._collect_tests):
(Manager._handle_finished_test):
* Scripts/webkitpy/layout_tests/models/test_expectations.py:
(strip_comments):

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (124130 => 124131)


--- trunk/Tools/ChangeLog	2012-07-31 00:58:19 UTC (rev 124130)
+++ trunk/Tools/ChangeLog	2012-07-31 01:02:13 UTC (rev 124131)
@@ -1,3 +1,28 @@
+2012-07-30  Dirk Pranke  <[email protected]>
+
+        nrwt: split test-finding code out from manager.py
+        https://bugs.webkit.org/show_bug.cgi?id=92693
+
+        Reviewed by Ryosuke Niwa.
+
+        In the interest of making manager.py smaller, this patch moves
+        the code that actually takes the command line arguments and
+        --test-file lists of tests to run and expands them into an
+        actual list of tests out into a separate module.
+
+        * Scripts/webkitpy/layout_tests/controllers/finder.py: Added.
+        (LayoutTestFinder):
+        (LayoutTestFinder.__init__):
+        (LayoutTestFinder.find_tests):
+        (LayoutTestFinder._strip_test_dir_prefixes):
+        (LayoutTestFinder._strip_test_dir_prefix):
+        (LayoutTestFinder._read_test_names_from_file):
+        * Scripts/webkitpy/layout_tests/controllers/manager.py:
+        (Manager._collect_tests):
+        (Manager._handle_finished_test):
+        * Scripts/webkitpy/layout_tests/models/test_expectations.py:
+        (strip_comments):
+
 2012-07-30  Adam Barth  <[email protected]>
 
         commit-queue is corrupting ChangeLogs

Added: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/finder.py (0 => 124131)


--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/finder.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/finder.py	2012-07-31 01:02:13 UTC (rev 124131)
@@ -0,0 +1,94 @@
+# Copyright (C) 2012 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.
+
+# FIXME: rename this to layout_test_finder.py.
+
+import errno
+import logging
+import re
+
+
+_log = logging.getLogger(__name__)
+
+
+class LayoutTestFinder(object):
+    def __init__(self, port):
+        self._port = port
+        self._filesystem = self._port.host.filesystem
+        self.LAYOUT_TESTS_DIRECTORY = 'LayoutTests'
+
+    def find_tests(self, options, args):
+        paths = self._strip_test_dir_prefixes(args)
+        if options.test_list:
+            paths += self._strip_test_dir_prefixes(self._read_test_names_from_file(options.test_list, self._port.TEST_PATH_SEPARATOR))
+        paths = set(paths)
+        test_files = self._port.tests(paths)
+        return (paths, test_files)
+
+    def _strip_test_dir_prefixes(self, paths):
+        return [self._strip_test_dir_prefix(path) for path in paths if path]
+
+    def _strip_test_dir_prefix(self, path):
+        # Handle both "LayoutTests/foo/bar.html" and "LayoutTests\foo\bar.html" if
+        # the filesystem uses '\\' as a directory separator.
+        if path.startswith(self.LAYOUT_TESTS_DIRECTORY + self._port.TEST_PATH_SEPARATOR):
+            return path[len(self.LAYOUT_TESTS_DIRECTORY + self._port.TEST_PATH_SEPARATOR):]
+        if path.startswith(self.LAYOUT_TESTS_DIRECTORY + self._filesystem.sep):
+            return path[len(self.LAYOUT_TESTS_DIRECTORY + self._filesystem.sep):]
+        return path
+
+    def _read_test_names_from_file(self, filenames, test_path_separator):
+        fs = self._filesystem
+        tests = []
+        for filename in filenames:
+            try:
+                if test_path_separator != fs.sep:
+                    filename = filename.replace(test_path_separator, fs.sep)
+                file_contents = fs.read_text_file(filename).split('\n')
+                for line in file_contents:
+                    line = self._strip_comments(line)
+                    if line:
+                        tests.append(line)
+            except IOError, e:
+                if e.errno == errno.ENOENT:
+                    _log.critical('')
+                    _log.critical('--test-list file "%s" not found' % file)
+                raise
+        return tests
+
+    @staticmethod
+    def _strip_comments(line):
+        commentIndex = line.find('//')
+        if commentIndex is -1:
+            commentIndex = len(line)
+
+        line = re.sub(r'\s+', ' ', line[:commentIndex].strip())
+        if line == '':
+            return None
+        else:
+            return line

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py (124130 => 124131)


--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py	2012-07-31 00:58:19 UTC (rev 124130)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py	2012-07-31 01:02:13 UTC (rev 124131)
@@ -46,6 +46,7 @@
 
 from webkitpy.common import message_pool
 from webkitpy.layout_tests.controllers import worker
+from webkitpy.layout_tests.controllers.finder import LayoutTestFinder
 from webkitpy.layout_tests.controllers.test_result_writer import TestResultWriter
 from webkitpy.layout_tests.layout_package import json_layout_results_generator
 from webkitpy.layout_tests.layout_package import json_results_generator
@@ -330,30 +331,8 @@
         self._current_result_summary = None
 
     def _collect_tests(self, args):
-        """Find all the files to test.
+        self._paths, self._test_files = LayoutTestFinder(self._port).find_tests(self._options, args)
 
-        Args:
-          args: list of test arguments from the command line
-
-        """
-        paths = self._strip_test_dir_prefixes(args)
-        if self._options.test_list:
-            paths += self._strip_test_dir_prefixes(read_test_files(self._filesystem, self._options.test_list, self._port.TEST_PATH_SEPARATOR))
-        self._paths = set(paths)
-        self._test_files = self._port.tests(paths)
-
-    def _strip_test_dir_prefixes(self, paths):
-        return [self._strip_test_dir_prefix(path) for path in paths if path]
-
-    def _strip_test_dir_prefix(self, path):
-        # Handle both "LayoutTests/foo/bar.html" and "LayoutTests\foo\bar.html" if
-        # the filesystem uses '\\' as a directory separator.
-        if path.startswith(self.LAYOUT_TESTS_DIRECTORY + self._port.TEST_PATH_SEPARATOR):
-            return path[len(self.LAYOUT_TESTS_DIRECTORY + self._port.TEST_PATH_SEPARATOR):]
-        if path.startswith(self.LAYOUT_TESTS_DIRECTORY + self._filesystem.sep):
-            return path[len(self.LAYOUT_TESTS_DIRECTORY + self._filesystem.sep):]
-        return path
-
     def _is_http_test(self, test):
         return self.HTTP_SUBDIR in test or self.WEBSOCKET_SUBDIR in test
 
@@ -1131,25 +1110,6 @@
         self._update_summary_with_result(self._current_result_summary, result)
 
 
-def read_test_files(fs, filenames, test_path_separator):
-    tests = []
-    for filename in filenames:
-        try:
-            if test_path_separator != fs.sep:
-                filename = filename.replace(test_path_separator, fs.sep)
-            file_contents = fs.read_text_file(filename).split('\n')
-            for line in file_contents:
-                line = test_expectations.strip_comments(line)
-                if line:
-                    tests.append(line)
-        except IOError, e:
-            if e.errno == errno.ENOENT:
-                _log.critical('')
-                _log.critical('--test-list file "%s" not found' % filename)
-            raise
-    return tests
-
-
 # FIXME: These two free functions belong either on manager (since it's the only one
 # which uses them) or in a different file (if they need to be re-used).
 def test_key(port, test_name):

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py (124130 => 124131)


--- trunk/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py	2012-07-31 00:58:19 UTC (rev 124130)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py	2012-07-31 01:02:13 UTC (rev 124131)
@@ -96,23 +96,6 @@
     return set(suffixes)
 
 
-# FIXME: This method is no longer used here in this module. Remove remaining callsite in manager.py and this method.
-def strip_comments(line):
-    """Strips comments from a line and return None if the line is empty
-    or else the contents of line with leading and trailing spaces removed
-    and all other whitespace collapsed"""
-
-    commentIndex = line.find('//')
-    if commentIndex is -1:
-        commentIndex = len(line)
-
-    line = re.sub(r'\s+', ' ', line[:commentIndex].strip())
-    if line == '':
-        return None
-    else:
-        return line
-
-
 class ParseError(Exception):
     def __init__(self, warnings):
         super(ParseError, self).__init__()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to