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

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

Issue 1839193004: Run auto-formatter (autopep8) on webkitpy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 8 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
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 logger.setLevel(logging.INFO) 126 logger.setLevel(logging.INFO)
127 handler = LogHandler() 127 handler = LogHandler()
128 handler.setLevel(logging.INFO) 128 handler.setLevel(logging.INFO)
129 logger.addHandler(handler) 129 logger.addHandler(handler)
130 return handler 130 return handler
131 131
132 132
133 def parse_args(): 133 def parse_args():
134 parser = optparse.OptionParser(usage='usage: %prog [options] [dir_to_import] [top_of_repo]') 134 parser = optparse.OptionParser(usage='usage: %prog [options] [dir_to_import] [top_of_repo]')
135 parser.add_option('-n', '--no-overwrite', dest='overwrite', action='store_fa lse', default=True, 135 parser.add_option('-n', '--no-overwrite', dest='overwrite', action='store_fa lse', default=True,
136 help='Flag to prevent duplicate test files from overwriting existing tes ts. By default, they will be overwritten.') 136 help='Flag to prevent duplicate test files from overwritin g existing tests. By default, they will be overwritten.')
137 parser.add_option('-a', '--all', action='store_true', default=False, 137 parser.add_option('-a', '--all', action='store_true', default=False,
138 help='Import all tests including reftests, JS tests, and manual/pixel te sts. By default, only reftests and JS tests are imported.') 138 help='Import all tests including reftests, JS tests, and m anual/pixel tests. By default, only reftests and JS tests are imported.')
139 parser.add_option('-d', '--dest-dir', dest='destination', default='w3c', 139 parser.add_option('-d', '--dest-dir', dest='destination', default='w3c',
140 help='Import into a specified directory relative to the LayoutTests root . By default, files are imported under LayoutTests/w3c.') 140 help='Import into a specified directory relative to the La youtTests root. By default, files are imported under LayoutTests/w3c.')
141 parser.add_option('--ignore-expectations', action='store_true', default=Fals e, 141 parser.add_option('--ignore-expectations', action='store_true', default=Fals e,
142 help='Ignore the W3CImportExpectations file and import everything.') 142 help='Ignore the W3CImportExpectations file and import eve rything.')
143 parser.add_option('--dry-run', action='store_true', default=False, 143 parser.add_option('--dry-run', action='store_true', default=False,
144 help='Dryrun only (don\'t actually write any results).') 144 help='Dryrun only (don\'t actually write any results).')
145 145
146 options, args = parser.parse_args() 146 options, args = parser.parse_args()
147 if len(args) > 2: 147 if len(args) > 2:
148 parser.error('Incorrect number of arguments') 148 parser.error('Incorrect number of arguments')
149 elif len(args) == 0: 149 elif len(args) == 0:
150 args = (os.getcwd(),) 150 args = (os.getcwd(),)
151 return options, args 151 return options, args
152 152
153 153
154 class TestImporter(object): 154 class TestImporter(object):
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 path_base = path_base.replace(cur_dir, '') 214 path_base = path_base.replace(cur_dir, '')
215 path_full = self.filesystem.join(root, path_base) 215 path_full = self.filesystem.join(root, path_base)
216 if path_base in dirs: 216 if path_base in dirs:
217 dirs.remove(path_base) 217 dirs.remove(path_base)
218 if not self.options.dry_run and self.import_in_place: 218 if not self.options.dry_run and self.import_in_place:
219 _log.info(" pruning %s" % path_base) 219 _log.info(" pruning %s" % path_base)
220 self.filesystem.rmtree(path_full) 220 self.filesystem.rmtree(path_full)
221 else: 221 else:
222 _log.info(" skipping %s" % path_base) 222 _log.info(" skipping %s" % path_base)
223 223
224
225 copy_list = [] 224 copy_list = []
226 225
227 for filename in files: 226 for filename in files:
228 path_full = self.filesystem.join(root, filename) 227 path_full = self.filesystem.join(root, filename)
229 path_base = path_full.replace(directory + '/', '') 228 path_base = path_full.replace(directory + '/', '')
230 path_base = self.destination_directory.replace(self.layout_tests _dir + '/', '') + '/' + path_base 229 path_base = self.destination_directory.replace(self.layout_tests _dir + '/', '') + '/' + path_base
231 if path_base in paths_to_skip: 230 if path_base in paths_to_skip:
232 if not self.options.dry_run and self.import_in_place: 231 if not self.options.dry_run and self.import_in_place:
233 _log.info(" pruning %s" % path_base) 232 _log.info(" pruning %s" % path_base)
234 self.filesystem.remove(path_full) 233 self.filesystem.remove(path_full)
(...skipping 30 matching lines...) Expand all
265 # FIXME: Ideally we'd support reading the metadata 264 # FIXME: Ideally we'd support reading the metadata
266 # directly rather than relying on a naming convention. 265 # directly rather than relying on a naming convention.
267 # Using a naming convention creates duplicate copies of the 266 # Using a naming convention creates duplicate copies of the
268 # reference files. 267 # reference files.
269 ref_file = os.path.splitext(test_basename)[0] + '-expected' 268 ref_file = os.path.splitext(test_basename)[0] + '-expected'
270 # Make sure to use the extension from the *reference*, not 269 # Make sure to use the extension from the *reference*, not
271 # from the test, because at least flexbox tests use XHTML 270 # from the test, because at least flexbox tests use XHTML
272 # references but HTML tests. 271 # references but HTML tests.
273 ref_file += os.path.splitext(test_info['reference'])[1] 272 ref_file += os.path.splitext(test_info['reference'])[1]
274 273
275 copy_list.append({'src': test_info['reference'], 'dest': ref _file, 'reference_support_info': test_info['reference_support_info']}) 274 copy_list.append({'src': test_info['reference'], 'dest': ref _file,
275 'reference_support_info': test_info['refer ence_support_info']})
276 copy_list.append({'src': test_info['test'], 'dest': filename }) 276 copy_list.append({'src': test_info['test'], 'dest': filename })
277 277
278 elif 'jstest' in test_info.keys(): 278 elif 'jstest' in test_info.keys():
279 jstests += 1 279 jstests += 1
280 total_tests += 1 280 total_tests += 1
281 copy_list.append({'src': fullpath, 'dest': filename}) 281 copy_list.append({'src': fullpath, 'dest': filename})
282 else: 282 else:
283 total_tests += 1 283 total_tests += 1
284 copy_list.append({'src': fullpath, 'dest': filename}) 284 copy_list.append({'src': fullpath, 'dest': filename})
285 285
286 if copy_list: 286 if copy_list:
287 # Only add this directory to the list if there's something to im port 287 # Only add this directory to the list if there's something to im port
288 self.import_list.append({'dirname': root, 'copy_list': copy_list , 288 self.import_list.append({'dirname': root, 'copy_list': copy_list ,
289 'reftests': reftests, 'jstests': jstests, 'total_tests': tot al_tests}) 289 'reftests': reftests, 'jstests': jstest s, 'total_tests': total_tests})
290 290
291 def find_paths_to_skip(self): 291 def find_paths_to_skip(self):
292 if self.options.ignore_expectations: 292 if self.options.ignore_expectations:
293 return set() 293 return set()
294 294
295 paths_to_skip = set() 295 paths_to_skip = set()
296 port = self.host.port_factory.get() 296 port = self.host.port_factory.get()
297 w3c_import_expectations_path = self.webkit_finder.path_from_webkit_base( 'LayoutTests', 'W3CImportExpectations') 297 w3c_import_expectations_path = self.webkit_finder.path_from_webkit_base( 'LayoutTests', 'W3CImportExpectations')
298 w3c_import_expectations = self.filesystem.read_text_file(w3c_import_expe ctations_path) 298 w3c_import_expectations = self.filesystem.read_text_file(w3c_import_expe ctations_path)
299 parser = TestExpectationParser(port, all_tests=(), is_lint_mode=False) 299 parser = TestExpectationParser(port, all_tests=(), is_lint_mode=False)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 _log.info(' skipping %s' % relpath) 360 _log.info(' skipping %s' % relpath)
361 else: 361 else:
362 # FIXME: Maybe doing a file diff is in order here for existi ng files? 362 # FIXME: Maybe doing a file diff is in order here for existi ng files?
363 # In other words, there's no sense in overwriting identical files, but 363 # In other words, there's no sense in overwriting identical files, but
364 # there's no harm in copying the identical thing. 364 # there's no harm in copying the identical thing.
365 _log.info(' %s' % relpath) 365 _log.info(' %s' % relpath)
366 366
367 # Only html, xml, or css should be converted 367 # Only html, xml, or css should be converted
368 # FIXME: Eventually, so should js when support is added for this type of conversion 368 # FIXME: Eventually, so should js when support is added for this type of conversion
369 mimetype = mimetypes.guess_type(orig_filepath) 369 mimetype = mimetypes.guess_type(orig_filepath)
370 if 'html' in str(mimetype[0]) or 'xml' in str(mimetype[0]) or ' css' in str(mimetype[0]): 370 if 'html' in str(mimetype[0]) or 'xml' in str(mimetype[0]) or 'c ss' in str(mimetype[0]):
371 converted_file = convert_for_webkit(new_path, filename=orig_ filepath, reference_support_info=reference_support_info) 371 converted_file = convert_for_webkit(new_path, filename=orig_ filepath,
372 reference_support_info=r eference_support_info)
372 373
373 if not converted_file: 374 if not converted_file:
374 if not self.import_in_place and not self.options.dry_run : 375 if not self.import_in_place and not self.options.dry_run :
375 shutil.copyfile(orig_filepath, new_filepath) # The file was unmodified. 376 shutil.copyfile(orig_filepath, new_filepath) # The file was unmodified.
376 else: 377 else:
377 for prefixed_property in converted_file[0]: 378 for prefixed_property in converted_file[0]:
378 total_prefixed_properties.setdefault(prefixed_proper ty, 0) 379 total_prefixed_properties.setdefault(prefixed_proper ty, 0)
379 total_prefixed_properties[prefixed_property] += 1 380 total_prefixed_properties[prefixed_property] += 1
380 381
381 prefixed_properties.extend(set(converted_file[0]) - set( prefixed_properties)) 382 prefixed_properties.extend(set(converted_file[0]) - set( prefixed_properties))
(...skipping 25 matching lines...) Expand all
407 """ Creates a destination directory that mirrors that of the source dire ctory """ 408 """ Creates a destination directory that mirrors that of the source dire ctory """
408 409
409 new_subpath = self.dir_to_import[len(self.top_of_repo):] 410 new_subpath = self.dir_to_import[len(self.top_of_repo):]
410 411
411 destination_directory = os.path.join(self.destination_directory, new_sub path) 412 destination_directory = os.path.join(self.destination_directory, new_sub path)
412 413
413 if not os.path.exists(destination_directory): 414 if not os.path.exists(destination_directory):
414 os.makedirs(destination_directory) 415 os.makedirs(destination_directory)
415 416
416 _log.info('Tests will be imported into: %s', destination_directory) 417 _log.info('Tests will be imported into: %s', destination_directory)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698