Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_importer.py

Issue 2012963002: Add and clean up docstrings in webkitpy/w3c. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions 4 # modification, are permitted provided that the following conditions
5 # are met: 5 # are met:
6 # 6 #
7 # 1. Redistributions of source code must retain the above 7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following 8 # copyright notice, this list of conditions and the following
9 # disclaimer. 9 # disclaimer.
10 # 2. Redistributions in binary form must reproduce the above 10 # 2. Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following 11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials 12 # disclaimer in the documentation and/or other materials
13 # provided with the distribution. 13 # provided with the distribution.
14 # 14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY 15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
20 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
24 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 24 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
25 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # SUCH DAMAGE. 26 # SUCH DAMAGE.
27 27
28 """ 28 """
29 This script imports a directory of W3C tests into Blink. 29 This script imports a directory of W3C tests into Blink.
30 30
31 This script will import the tests into WebKit following these rules: 31 This script takes a source repository directory, which it searches for files,
32 then converts and copies files over to a destination directory.
32 33
33 - By default, all tests are imported under LayoutTests/w3c/[repo-name]. 34 Rules for importing:
34 35
35 - By default, only reftests and jstest are imported. This can be overridden 36 * By default, only reference tests and JS tests are imported, (because pixel
36 with a -a or --all argument 37 tests take longer to run). This can be overridden with the --all flag.
37 38
38 - Also by default, if test files by the same name already exist in the 39 * By default, if test files by the same name already exist in the destination
39 destination directory, they are overwritten with the idea that running 40 directory, they are overwritten. This is because this script is used to
40 this script would refresh files periodically. This can also be 41 refresh files periodically. This can be overridden with the --no-overwrite fl ag.
41 overridden by a -n or --no-overwrite flag
42 42
43 - All files are converted to work in Blink: 43 * All files are converted to work in Blink:
44 1. All CSS properties requiring the -webkit- vendor prefix are prefixed 44 1. All CSS properties requiring the -webkit- vendor prefix are prefixed
45 (the list of what needs prefixes is read from Source/core/css/CSSPro perties.in). 45 (the list of what needs prefixes is read from Source/core/css/CSSPropert ies.in).
46 2. Each reftest has its own copy of its reference file following 46 2. Each reftest has its own copy of its reference file following
47 the naming conventions new-run-webkit-tests expects. 47 the naming conventions new-run-webkit-tests expects.
48 3. If a reference files lives outside the directory of the test that 48 3. If a reference files lives outside the directory of the test that
49 uses it, it is checked for paths to support files as it will be 49 uses it, it is checked for paths to support files as it will be
50 imported into a different relative position to the test file 50 imported into a different relative position to the test file
51 (in the same directory). 51 (in the same directory).
52 4. Any tags with the class "instructions" have style="display:none" add ed 52 4. Any tags with the class "instructions" have style="display:none" added
53 to them. Some w3c tests contain instructions to manual testers which we 53 to them. Some w3c tests contain instructions to manual testers which we
54 want to strip out (the test result parser only recognizes pure testh arness.js 54 want to strip out (the test result parser only recognizes pure testharne ss.js
55 output and not those instructions). 55 output and not those instructions).
56 56
57 - Upon completion, script outputs the total number tests imported, broken 57 * Upon completion, script outputs the total number tests imported,
58 down by test type 58 broken down by test type.
59 59
60 - Also upon completion, if we are not importing the files in place, each 60 * Also upon completion, if we are not importing the files in place, each
61 directory where files are imported will have a w3c-import.log file writte n with 61 directory where files are imported will have a w3c-import.log file written wi th
62 a timestamp, the list of CSS properties used that require prefixes, the l ist 62 a timestamp, the list of CSS properties used that require prefixes, the list
63 of imported files, and guidance for future test modification and maintena nce. 63 of imported files, and guidance for future test modification and maintenance.
64 On subsequent imports, this file is read to determine if files have been 64 On subsequent imports, this file is read to determine if files have been
65 removed in the newer changesets. The script removes these files according ly. 65 removed in the newer changesets. The script removes these files accordingly.
66 """ 66 """
67 67
68 import logging 68 import logging
69 import mimetypes 69 import mimetypes
70 import optparse 70 import optparse
71 import os 71 import os
72 import sys 72 import sys
73 73
74 from webkitpy.common.host import Host 74 from webkitpy.common.host import Host
75 from webkitpy.common.webkit_finder import WebKitFinder 75 from webkitpy.common.webkit_finder import WebKitFinder
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 self.dir_above_repo = self.filesystem.dirname(self.top_of_repo) 167 self.dir_above_repo = self.filesystem.dirname(self.top_of_repo)
168 168
169 self.import_list = [] 169 self.import_list = []
170 170
171 def do_import(self): 171 def do_import(self):
172 _log.info("Importing %s into %s", self.dir_to_import, self.destination_d irectory) 172 _log.info("Importing %s into %s", self.dir_to_import, self.destination_d irectory)
173 self.find_importable_tests(self.dir_to_import) 173 self.find_importable_tests(self.dir_to_import)
174 self.import_tests() 174 self.import_tests()
175 175
176 def find_importable_tests(self, directory): 176 def find_importable_tests(self, directory):
177 """Walks through the source directory to find what tests should be impor ted.
178
179 This function sets self.import_list, which contains information about ho w many
180 tests are being imported, and their source and destination paths.
181 """
177 paths_to_skip = self.find_paths_to_skip() 182 paths_to_skip = self.find_paths_to_skip()
178 183
179 for root, dirs, files in self.filesystem.walk(directory): 184 for root, dirs, files in self.filesystem.walk(directory):
180 cur_dir = root.replace(self.dir_above_repo + '/', '') + '/' 185 cur_dir = root.replace(self.dir_above_repo + '/', '') + '/'
181 _log.info(' scanning ' + cur_dir + '...') 186 _log.info(' scanning ' + cur_dir + '...')
182 total_tests = 0 187 total_tests = 0
183 reftests = 0 188 reftests = 0
184 jstests = 0 189 jstests = 0
185 190
186 # Files in 'tools' are not for browser testing (e.g., a script for g enerating test files). 191 # Files in 'tools' are not for browser testing (e.g., a script for g enerating test files).
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 expectation_lines = parser.parse(w3c_import_expectations_path, w3c_impor t_expectations) 303 expectation_lines = parser.parse(w3c_import_expectations_path, w3c_impor t_expectations)
299 for line in expectation_lines: 304 for line in expectation_lines:
300 if 'SKIP' in line.expectations: 305 if 'SKIP' in line.expectations:
301 if line.specifiers: 306 if line.specifiers:
302 _log.warning("W3CImportExpectations:%s should not have any s pecifiers" % line.line_numbers) 307 _log.warning("W3CImportExpectations:%s should not have any s pecifiers" % line.line_numbers)
303 continue 308 continue
304 paths_to_skip.add(line.name) 309 paths_to_skip.add(line.name)
305 return paths_to_skip 310 return paths_to_skip
306 311
307 def import_tests(self): 312 def import_tests(self):
313 """Reads |self.import_list|, and converts and copies files to their dest ination."""
308 total_imported_tests = 0 314 total_imported_tests = 0
309 total_imported_reftests = 0 315 total_imported_reftests = 0
310 total_imported_jstests = 0 316 total_imported_jstests = 0
311 total_prefixed_properties = {} 317 total_prefixed_properties = {}
312 318
313 for dir_to_copy in self.import_list: 319 for dir_to_copy in self.import_list:
314 total_imported_tests += dir_to_copy['total_tests'] 320 total_imported_tests += dir_to_copy['total_tests']
315 total_imported_reftests += dir_to_copy['reftests'] 321 total_imported_reftests += dir_to_copy['reftests']
316 total_imported_jstests += dir_to_copy['jstests'] 322 total_imported_jstests += dir_to_copy['jstests']
317 323
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 361
356 relpath = self.filesystem.relpath(new_filepath, self.layout_test s_dir) 362 relpath = self.filesystem.relpath(new_filepath, self.layout_test s_dir)
357 if not self.options.overwrite and self.filesystem.exists(new_fil epath): 363 if not self.options.overwrite and self.filesystem.exists(new_fil epath):
358 _log.info(' skipping %s' % relpath) 364 _log.info(' skipping %s' % relpath)
359 else: 365 else:
360 # FIXME: Maybe doing a file diff is in order here for existi ng files? 366 # FIXME: Maybe doing a file diff is in order here for existi ng files?
361 # In other words, there's no sense in overwriting identical files, but 367 # In other words, there's no sense in overwriting identical files, but
362 # there's no harm in copying the identical thing. 368 # there's no harm in copying the identical thing.
363 _log.info(' %s' % relpath) 369 _log.info(' %s' % relpath)
364 370
365 # Only html, xml, or css should be converted 371 # Only HTML, XML, or CSS should be converted.
366 # FIXME: Eventually, so should js when support is added for this type of conversion 372 # FIXME: Eventually, so should JS when support is added for this type of conversion.
367 mimetype = mimetypes.guess_type(orig_filepath) 373 mimetype = mimetypes.guess_type(orig_filepath)
368 if 'html' in str(mimetype[0]) or 'xml' in str(mimetype[0]) or 'c ss' in str(mimetype[0]): 374 if 'html' in str(mimetype[0]) or 'xml' in str(mimetype[0]) or 'c ss' in str(mimetype[0]):
369 converted_file = convert_for_webkit(new_path, filename=orig_ filepath, 375 converted_file = convert_for_webkit(new_path, filename=orig_ filepath,
370 reference_support_info=r eference_support_info) 376 reference_support_info=r eference_support_info)
371 377
372 if not converted_file: 378 if not converted_file:
373 if not self.import_in_place and not self.options.dry_run : 379 if not self.import_in_place and not self.options.dry_run :
374 self.filesystem.copyfile(orig_filepath, new_filepath ) # The file was unmodified. 380 self.filesystem.copyfile(orig_filepath, new_filepath ) # The file was unmodified.
375 else: 381 else:
376 for prefixed_property in converted_file[0]: 382 for prefixed_property in converted_file[0]:
(...skipping 28 matching lines...) Expand all
405 def path_too_long(self, source_path): 411 def path_too_long(self, source_path):
406 """Checks whether a source path is too long to import. 412 """Checks whether a source path is too long to import.
407 413
408 Args: 414 Args:
409 Absolute path of file to be imported. 415 Absolute path of file to be imported.
410 """ 416 """
411 path_from_repo_base = os.path.relpath(source_path, self.top_of_repo) 417 path_from_repo_base = os.path.relpath(source_path, self.top_of_repo)
412 return len(path_from_repo_base) > MAX_PATH_LENGTH 418 return len(path_from_repo_base) > MAX_PATH_LENGTH
413 419
414 def setup_destination_directory(self): 420 def setup_destination_directory(self):
415 """ Creates a destination directory that mirrors that of the source dire ctory """ 421 """Creates a destination directory that mirrors that of the source direc tory."""
416 422
417 new_subpath = self.dir_to_import[len(self.top_of_repo):] 423 new_subpath = self.dir_to_import[len(self.top_of_repo):]
418 424
419 destination_directory = self.filesystem.join(self.destination_directory, new_subpath) 425 destination_directory = self.filesystem.join(self.destination_directory, new_subpath)
420 426
421 if not self.filesystem.exists(destination_directory): 427 if not self.filesystem.exists(destination_directory):
422 self.filesystem.maybe_make_directory(destination_directory) 428 self.filesystem.maybe_make_directory(destination_directory)
423 429
424 _log.info('Tests will be imported into: %s', destination_directory) 430 _log.info('Tests will be imported into: %s', destination_directory)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698