Changeset 76150 in webkit
- Timestamp:
- Jan 19, 2011 12:28:45 PM (13 years ago)
- Location:
- trunk/Tools
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r76140 r76150 1 2011-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 1 20 2011-01-19 Levi Weintraub <leviw@chromium.org> 2 21 -
trunk/Tools/Scripts/webkitpy/common/system/filesystem.py
r76050 r76150 34 34 import errno 35 35 import exceptions 36 import glob 36 37 import os 37 38 import shutil … … 46 47 47 48 def basename(self, path): 49 """Wraps os.path.basename().""" 48 50 return os.path.basename(path) 49 51 … … 54 56 55 57 def dirname(self, path): 58 """Wraps os.path.dirname().""" 56 59 return os.path.dirname(path) 57 60 … … 65 68 for (path_to_file, _, filenames) in os.walk(path) 66 69 for filename in filenames] 70 71 def glob(self, path): 72 """Wraps glob.glob().""" 73 return glob.glob(path) 67 74 68 75 def isfile(self, path): … … 126 133 127 134 def normpath(self, path): 135 """Wraps os.path.normpath().""" 128 136 return os.path.normpath(path) 129 137 … … 189 197 190 198 def splitext(self, path): 191 """Return (dirname , basename + ext)."""199 """Return (dirname + os.sep + basename, '.' + ext)""" 192 200 return os.path.splitext(path) 193 201 -
trunk/Tools/Scripts/webkitpy/common/system/filesystem_mock.py
r76050 r76150 77 77 return [file for file in self.files if file.startswith(path)] 78 78 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 79 87 def isfile(self, path): 80 88 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 87 87 """ 88 88 failures = [] 89 fs = port._filesystem 89 90 90 91 if test_output.crash: … … 97 98 _log.debug("%s Stacktrace for %s:\n%s" % (worker_name, test_name, 98 99 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) 104 104 elif test_output.error: 105 105 _log.debug("%s %s output stderr lines:\n%s" % (worker_name, test_name, … … 386 386 # Append tests we're running to the existing tests_run.txt file. 387 387 # 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, 389 389 "tests_run.txt") 390 390 tests_run_file = codecs.open(tests_run_filename, "a", "utf-8") -
trunk/Tools/Scripts/webkitpy/layout_tests/port/test_files.py
r72564 r76150 59 59 to limit the search to. glob patterns are ok. 60 60 """ 61 fs = port._filesystem 61 62 gather_start_time = time.time() 62 63 paths_to_walk = set() … … 66 67 for path in paths: 67 68 # 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) 69 70 if path.find('*') > -1: 70 filenames = glob.glob(path)71 filenames = fs.glob(path) 71 72 paths_to_walk.update(filenames) 72 73 else: … … 79 80 test_files = set() 80 81 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)) 83 84 continue 84 85 … … 96 97 97 98 for filename in files: 98 if _is_test_file(f ilename):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) 101 102 test_files.add(filename) 102 103 … … 107 108 108 109 109 def _has_supported_extension(f ilename):110 def _has_supported_extension(fs, filename): 110 111 """Return true if filename is one of the file extensions we want to run a 111 112 test on.""" 112 extension = os.path.splitext(filename)[1]113 extension = fs.splitext(filename)[1] 113 114 return extension in _supported_file_extensions 114 115 … … 123 124 124 125 125 def _is_test_file(f ilename):126 def _is_test_file(fs, filename): 126 127 """Return true if the filename points to a test file.""" 127 return (_has_supported_extension(f ilename) and128 return (_has_supported_extension(fs, filename) and 128 129 not _is_reference_html_file(filename)) -
trunk/Tools/Scripts/webkitpy/layout_tests/port/test_files_unittest.py
r72564 r76150 65 65 66 66 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')) 72 74 73 75 -
trunk/Tools/Scripts/webkitpy/layout_tests/test_types/test_type_base.py
r73256 r76150 33 33 """ 34 34 35 from __future__ import with_statement36 37 import codecs38 35 import cgi 39 36 import errno 40 37 import logging 41 import os.path42 38 43 39 _log = logging.getLogger("webkitpy.layout_tests.test_types.test_type_base") … … 87 83 """Creates the output directory (if needed) for a given test 88 84 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, 90 87 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)) 92 89 93 90 def _save_baseline_data(self, filename, data, modifier, encoding, … … 107 104 """ 108 105 106 port = self._port 107 fs = self._port._filesystem 109 108 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] + 115 113 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) 118 116 _log.debug('writing new baseline result "%s"' % (output_path)) 119 117 else: 120 output_path = self._port.expected_filename(filename, modifier)118 output_path = port.expected_filename(filename, modifier) 121 119 _log.debug('resetting baseline result "%s"' % output_path) 122 120 123 self._port.update_baseline(output_path, data, encoding)121 port.update_baseline(output_path, data, encoding) 124 122 125 123 def output_filename(self, filename, modifier): … … 137 135 The absolute windows path to the output filename 138 136 """ 139 output_filename = os.path.join(self._root_output_dir, 137 fs = self._port._filesystem 138 output_filename = fs.join(self._root_output_dir, 140 139 self._port.relative_test_filename(filename)) 141 return os.path.splitext(output_filename)[0] + modifier140 return fs.splitext(output_filename)[0] + modifier 142 141 143 142 def compare_output(self, port, filename, test_args, actual_test_output, … … 166 165 """This method assumes that byte_array is already encoded 167 166 into the right format.""" 168 open_mode = 'w'167 fs = self._port._filesystem 169 168 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) 173 172 174 173 def write_output_files(self, filename, file_type,
Note: See TracChangeset
for help on using the changeset viewer.