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

Side by Side Diff: Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder.py

Issue 546133003: Reformat webkitpy.layout_tests w/ format-webkitpy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (C) 2012 Google Inc. All rights reserved. 1 # Copyright (C) 2012 Google Inc. 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 are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 19 matching lines...) Expand all
30 import logging 30 import logging
31 import re 31 import re
32 32
33 from webkitpy.layout_tests.models import test_expectations 33 from webkitpy.layout_tests.models import test_expectations
34 34
35 35
36 _log = logging.getLogger(__name__) 36 _log = logging.getLogger(__name__)
37 37
38 38
39 class LayoutTestFinder(object): 39 class LayoutTestFinder(object):
40
40 def __init__(self, port, options): 41 def __init__(self, port, options):
41 self._port = port 42 self._port = port
42 self._options = options 43 self._options = options
43 self._filesystem = self._port.host.filesystem 44 self._filesystem = self._port.host.filesystem
44 self.LAYOUT_TESTS_DIRECTORY = 'LayoutTests' 45 self.LAYOUT_TESTS_DIRECTORY = 'LayoutTests'
45 46
46 def find_tests(self, options, args): 47 def find_tests(self, options, args):
47 paths = self._strip_test_dir_prefixes(args) 48 paths = self._strip_test_dir_prefixes(args)
48 if options.test_list: 49 if options.test_list:
49 paths += self._strip_test_dir_prefixes(self._read_test_names_from_fi le(options.test_list, self._port.TEST_PATH_SEPARATOR)) 50 paths += self._strip_test_dir_prefixes(
51 self._read_test_names_from_file(
52 options.test_list,
53 self._port.TEST_PATH_SEPARATOR))
50 test_files = self._port.tests(paths) 54 test_files = self._port.tests(paths)
51 return (paths, test_files) 55 return (paths, test_files)
52 56
53 def _strip_test_dir_prefixes(self, paths): 57 def _strip_test_dir_prefixes(self, paths):
54 return [self._strip_test_dir_prefix(path) for path in paths if path] 58 return [self._strip_test_dir_prefix(path) for path in paths if path]
55 59
56 def _strip_test_dir_prefix(self, path): 60 def _strip_test_dir_prefix(self, path):
57 # Handle both "LayoutTests/foo/bar.html" and "LayoutTests\foo\bar.html" if 61 # Handle both "LayoutTests/foo/bar.html" and "LayoutTests\foo\bar.html" if
58 # the filesystem uses '\\' as a directory separator. 62 # the filesystem uses '\\' as a directory separator.
59 if path.startswith(self.LAYOUT_TESTS_DIRECTORY + self._port.TEST_PATH_SE PARATOR): 63 if path.startswith(self.LAYOUT_TESTS_DIRECTORY + self._port.TEST_PATH_SE PARATOR):
60 return path[len(self.LAYOUT_TESTS_DIRECTORY + self._port.TEST_PATH_S EPARATOR):] 64 return path[len(self.LAYOUT_TESTS_DIRECTORY + self._port.TEST_PATH_S EPARATOR):]
61 if path.startswith(self.LAYOUT_TESTS_DIRECTORY + self._filesystem.sep): 65 if path.startswith(self.LAYOUT_TESTS_DIRECTORY + self._filesystem.sep):
62 return path[len(self.LAYOUT_TESTS_DIRECTORY + self._filesystem.sep): ] 66 return path[len(self.LAYOUT_TESTS_DIRECTORY + self._filesystem.sep): ]
63 return path 67 return path
64 68
65 def _read_test_names_from_file(self, filenames, test_path_separator): 69 def _read_test_names_from_file(self, filenames, test_path_separator):
66 fs = self._filesystem 70 fs = self._filesystem
67 tests = [] 71 tests = []
68 for filename in filenames: 72 for filename in filenames:
69 try: 73 try:
70 if test_path_separator != fs.sep: 74 if test_path_separator != fs.sep:
71 filename = filename.replace(test_path_separator, fs.sep) 75 filename = filename.replace(test_path_separator, fs.sep)
72 file_contents = fs.read_text_file(filename).split('\n') 76 file_contents = fs.read_text_file(filename).split('\n')
73 for line in file_contents: 77 for line in file_contents:
74 line = self._strip_comments(line) 78 line = self._strip_comments(line)
75 if line: 79 if line:
76 tests.append(line) 80 tests.append(line)
77 except IOError, e: 81 except IOError as e:
78 if e.errno == errno.ENOENT: 82 if e.errno == errno.ENOENT:
79 _log.critical('') 83 _log.critical('')
80 _log.critical('--test-list file "%s" not found' % file) 84 _log.critical('--test-list file "%s" not found' % file)
81 raise 85 raise
82 return tests 86 return tests
83 87
84 @staticmethod 88 @staticmethod
85 def _strip_comments(line): 89 def _strip_comments(line):
86 commentIndex = line.find('//') 90 commentIndex = line.find('//')
87 if commentIndex is -1: 91 if commentIndex is -1:
(...skipping 25 matching lines...) Expand all
113 117
114 def split_into_chunks(self, test_names): 118 def split_into_chunks(self, test_names):
115 """split into a list to run and a set to skip, based on --run-chunk and --run-part.""" 119 """split into a list to run and a set to skip, based on --run-chunk and --run-part."""
116 if not self._options.run_chunk and not self._options.run_part: 120 if not self._options.run_chunk and not self._options.run_part:
117 return test_names, set() 121 return test_names, set()
118 122
119 # If the user specifies they just want to run a subset of the tests, 123 # If the user specifies they just want to run a subset of the tests,
120 # just grab a subset of the non-skipped tests. 124 # just grab a subset of the non-skipped tests.
121 chunk_value = self._options.run_chunk or self._options.run_part 125 chunk_value = self._options.run_chunk or self._options.run_part
122 try: 126 try:
123 (chunk_num, chunk_len) = chunk_value.split(":") 127 (chunk_num, chunk_len) = chunk_value.split(':')
124 chunk_num = int(chunk_num) 128 chunk_num = int(chunk_num)
125 assert(chunk_num >= 0) 129 assert(chunk_num >= 0)
126 test_size = int(chunk_len) 130 test_size = int(chunk_len)
127 assert(test_size > 0) 131 assert(test_size > 0)
128 except AssertionError: 132 except AssertionError:
129 _log.critical("invalid chunk '%s'" % chunk_value) 133 _log.critical("invalid chunk '%s'" % chunk_value)
130 return (None, None) 134 return (None, None)
131 135
132 # Get the number of tests 136 # Get the number of tests
133 num_tests = len(test_names) 137 num_tests = len(test_names)
(...skipping 28 matching lines...) Expand all
162 _log.debug('chunk slice [%d:%d] of %d is %d tests' % (slice_start, slice _end, num_tests, (slice_end - slice_start))) 166 _log.debug('chunk slice [%d:%d] of %d is %d tests' % (slice_start, slice _end, num_tests, (slice_end - slice_start)))
163 167
164 # If we reached the end and we don't have enough tests, we run some 168 # If we reached the end and we don't have enough tests, we run some
165 # from the beginning. 169 # from the beginning.
166 if slice_end - slice_start < chunk_len: 170 if slice_end - slice_start < chunk_len:
167 extra = chunk_len - (slice_end - slice_start) 171 extra = chunk_len - (slice_end - slice_start)
168 _log.debug(' last chunk is partial, appending [0:%d]' % extra) 172 _log.debug(' last chunk is partial, appending [0:%d]' % extra)
169 tests_to_run.extend(test_names[0:extra]) 173 tests_to_run.extend(test_names[0:extra])
170 174
171 return (tests_to_run, set(test_names) - set(tests_to_run)) 175 return (tests_to_run, set(test_names) - set(tests_to_run))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698