Changeset 76150 in webkit


Ignore:
Timestamp:
Jan 19, 2011 12:28:45 PM (13 years ago)
Author:
dpranke@chromium.org
Message:

2011-01-19 Dirk Pranke <dpranke@chromium.org>

Reviewed by Tony Chang.

Change more modules in the layout-tests code to use the
filesystem wrapper for cleaner unit testing.

This patch also adds the glob() wrapper to the filesystem
abstraction.

https://bugs.webkit.org/show_bug.cgi?id=52604

  • Scripts/webkitpy/layout_tests/port/test_files.py:
  • Scripts/webkitpy/layout_tests/port/test_files_unittest.py:
  • Scripts/webkitpy/layout_tests/test_types/test_type_base.py:
  • Scripts/webkitpy/layout_tests/layout_package/dump_render_tree_thread.py:
  • Scripts/webkitpy/common/system/filesystem.py:
  • Scripts/webkitpy/common/system/filesystem_mock.py:
Location:
trunk/Tools
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r76140 r76150  
     12011-01-19  Dirk Pranke  <dpranke@chromium.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        Change more modules in the layout-tests code to use the
     6        filesystem wrapper for cleaner unit testing.
     7
     8        This patch also adds the glob() wrapper to the filesystem
     9        abstraction.
     10       
     11        https://bugs.webkit.org/show_bug.cgi?id=52604
     12
     13        * Scripts/webkitpy/layout_tests/port/test_files.py:
     14        * Scripts/webkitpy/layout_tests/port/test_files_unittest.py:
     15        * Scripts/webkitpy/layout_tests/test_types/test_type_base.py:
     16        * Scripts/webkitpy/layout_tests/layout_package/dump_render_tree_thread.py:
     17        * Scripts/webkitpy/common/system/filesystem.py:
     18        * Scripts/webkitpy/common/system/filesystem_mock.py:
     19
    1202011-01-19  Levi Weintraub  <leviw@chromium.org>
    221
  • trunk/Tools/Scripts/webkitpy/common/system/filesystem.py

    r76050 r76150  
    3434import errno
    3535import exceptions
     36import glob
    3637import os
    3738import shutil
     
    4647
    4748    def basename(self, path):
     49        """Wraps os.path.basename()."""
    4850        return os.path.basename(path)
    4951
     
    5456
    5557    def dirname(self, path):
     58        """Wraps os.path.dirname()."""
    5659        return os.path.dirname(path)
    5760
     
    6568            for (path_to_file, _, filenames) in os.walk(path)
    6669            for filename in filenames]
     70
     71    def glob(self, path):
     72        """Wraps glob.glob()."""
     73        return glob.glob(path)
    6774
    6875    def isfile(self, path):
     
    126133
    127134    def normpath(self, path):
     135        """Wraps os.path.normpath()."""
    128136        return os.path.normpath(path)
    129137
     
    189197
    190198    def splitext(self, path):
    191         """Return (dirname, basename + ext)."""
     199        """Return (dirname + os.sep + basename, '.' + ext)"""
    192200        return os.path.splitext(path)
    193201
  • trunk/Tools/Scripts/webkitpy/common/system/filesystem_mock.py

    r76050 r76150  
    7777        return [file for file in self.files if file.startswith(path)]
    7878
     79    def glob(self, path):
     80        # FIXME: This only handles a wildcard '*' at the end of the path.
     81        # Maybe it should handle more?
     82        if path[-1] == '*':
     83            return [f for f in self.files if f.startswith(path[:-1])]
     84        else:
     85            return [f for f in self.files if f == path]
     86
    7987    def isfile(self, path):
    8088        return path in self.files and self.files[path] is not None
  • trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/dump_render_tree_thread.py

    r75114 r76150  
    8787    """
    8888    failures = []
     89    fs = port._filesystem
    8990
    9091    if test_output.crash:
     
    9798        _log.debug("%s Stacktrace for %s:\n%s" % (worker_name, test_name,
    9899                                                  test_output.error))
    99         filename = os.path.join(options.results_directory, test_name)
    100         filename = os.path.splitext(filename)[0] + "-stack.txt"
    101         port.maybe_make_directory(os.path.split(filename)[0])
    102         with codecs.open(filename, "wb", "utf-8") as file:
    103             file.write(test_output.error)
     100        filename = fs.join(options.results_directory, test_name)
     101        filename = fs.splitext(filename)[0] + "-stack.txt"
     102        fs.maybe_make_directory(fs.dirname(filename))
     103        fs.write_text_file(filename, test_output.error)
    104104    elif test_output.error:
    105105        _log.debug("%s %s output stderr lines:\n%s" % (worker_name, test_name,
     
    386386        # Append tests we're running to the existing tests_run.txt file.
    387387        # This is created in run_webkit_tests.py:_PrepareListsAndPrintOutput.
    388         tests_run_filename = os.path.join(self._options.results_directory,
     388        tests_run_filename = self._port._filesystem.join(self._options.results_directory,
    389389                                          "tests_run.txt")
    390390        tests_run_file = codecs.open(tests_run_filename, "a", "utf-8")
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/test_files.py

    r72564 r76150  
    5959          to limit the search to. glob patterns are ok.
    6060    """
     61    fs = port._filesystem
    6162    gather_start_time = time.time()
    6263    paths_to_walk = set()
     
    6667        for path in paths:
    6768            # If there's an * in the name, assume it's a glob pattern.
    68             path = os.path.join(port.layout_tests_dir(), path)
     69            path = fs.join(port.layout_tests_dir(), path)
    6970            if path.find('*') > -1:
    70                 filenames = glob.glob(path)
     71                filenames = fs.glob(path)
    7172                paths_to_walk.update(filenames)
    7273            else:
     
    7980    test_files = set()
    8081    for path in paths_to_walk:
    81         if os.path.isfile(path) and _is_test_file(path):
    82             test_files.add(os.path.normpath(path))
     82        if fs.isfile(path) and _is_test_file(fs, path):
     83            test_files.add(fs.normpath(path))
    8384            continue
    8485
     
    9697
    9798            for filename in files:
    98                 if _is_test_file(filename):
    99                     filename = os.path.join(root, filename)
    100                     filename = os.path.normpath(filename)
     99                if _is_test_file(fs, filename):
     100                    filename = fs.join(root, filename)
     101                    filename = fs.normpath(filename)
    101102                    test_files.add(filename)
    102103
     
    107108
    108109
    109 def _has_supported_extension(filename):
     110def _has_supported_extension(fs, filename):
    110111    """Return true if filename is one of the file extensions we want to run a
    111112    test on."""
    112     extension = os.path.splitext(filename)[1]
     113    extension = fs.splitext(filename)[1]
    113114    return extension in _supported_file_extensions
    114115
     
    123124
    124125
    125 def _is_test_file(filename):
     126def _is_test_file(fs, filename):
    126127    """Return true if the filename points to a test file."""
    127     return (_has_supported_extension(filename) and
     128    return (_has_supported_extension(fs, filename) and
    128129            not _is_reference_html_file(filename))
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/test_files_unittest.py

    r72564 r76150  
    6565
    6666    def test_is_test_file(self):
    67         self.assertTrue(test_files._is_test_file('foo.html'))
    68         self.assertTrue(test_files._is_test_file('foo.shtml'))
    69         self.assertFalse(test_files._is_test_file('foo.png'))
    70         self.assertFalse(test_files._is_test_file('foo-expected.html'))
    71         self.assertFalse(test_files._is_test_file('foo-expected-mismatch.html'))
     67        port = base.Port()
     68        fs = port._filesystem
     69        self.assertTrue(test_files._is_test_file(fs, 'foo.html'))
     70        self.assertTrue(test_files._is_test_file(fs, 'foo.shtml'))
     71        self.assertFalse(test_files._is_test_file(fs, 'foo.png'))
     72        self.assertFalse(test_files._is_test_file(fs, 'foo-expected.html'))
     73        self.assertFalse(test_files._is_test_file(fs, 'foo-expected-mismatch.html'))
    7274
    7375
  • trunk/Tools/Scripts/webkitpy/layout_tests/test_types/test_type_base.py

    r73256 r76150  
    3333"""
    3434
    35 from __future__ import with_statement
    36 
    37 import codecs
    3835import cgi
    3936import errno
    4037import logging
    41 import os.path
    4238
    4339_log = logging.getLogger("webkitpy.layout_tests.test_types.test_type_base")
     
    8783        """Creates the output directory (if needed) for a given test
    8884        filename."""
    89         output_filename = os.path.join(self._root_output_dir,
     85        fs = self._port._filesystem
     86        output_filename = fs.join(self._root_output_dir,
    9087            self._port.relative_test_filename(filename))
    91         self._port.maybe_make_directory(os.path.split(output_filename)[0])
     88        fs.maybe_make_directory(fs.dirname(output_filename))
    9289
    9390    def _save_baseline_data(self, filename, data, modifier, encoding,
     
    107104        """
    108105
     106        port = self._port
     107        fs = self._port._filesystem
    109108        if generate_new_baseline:
    110             relative_dir = os.path.dirname(
    111                 self._port.relative_test_filename(filename))
    112             baseline_path = self._port.baseline_path()
    113             output_dir = os.path.join(baseline_path, relative_dir)
    114             output_file = os.path.basename(os.path.splitext(filename)[0] +
     109            relative_dir = fs.dirname(port.relative_test_filename(filename))
     110            baseline_path = port.baseline_path()
     111            output_dir = fs.join(baseline_path, relative_dir)
     112            output_file = fs.basename(fs.splitext(filename)[0] +
    115113                self.FILENAME_SUFFIX_EXPECTED + modifier)
    116             self._port.maybe_make_directory(output_dir)
    117             output_path = os.path.join(output_dir, output_file)
     114            fs.maybe_make_directory(output_dir)
     115            output_path = fs.join(output_dir, output_file)
    118116            _log.debug('writing new baseline result "%s"' % (output_path))
    119117        else:
    120             output_path = self._port.expected_filename(filename, modifier)
     118            output_path = port.expected_filename(filename, modifier)
    121119            _log.debug('resetting baseline result "%s"' % output_path)
    122120
    123         self._port.update_baseline(output_path, data, encoding)
     121        port.update_baseline(output_path, data, encoding)
    124122
    125123    def output_filename(self, filename, modifier):
     
    137135          The absolute windows path to the output filename
    138136        """
    139         output_filename = os.path.join(self._root_output_dir,
     137        fs = self._port._filesystem
     138        output_filename = fs.join(self._root_output_dir,
    140139            self._port.relative_test_filename(filename))
    141         return os.path.splitext(output_filename)[0] + modifier
     140        return fs.splitext(output_filename)[0] + modifier
    142141
    143142    def compare_output(self, port, filename, test_args, actual_test_output,
     
    166165        """This method assumes that byte_array is already encoded
    167166        into the right format."""
    168         open_mode = 'w'
     167        fs = self._port._filesystem
    169168        if encoding is None:
    170             open_mode = 'w+b'
    171         with codecs.open(file_path, open_mode, encoding=encoding) as file:
    172             file.write(contents)
     169            fs.write_binary_file(file_path, contents)
     170            return
     171        fs.write_text_file(file_path, contents)
    173172
    174173    def write_output_files(self, filename, file_type,
Note: See TracChangeset for help on using the changeset viewer.