OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """A class for updating layout test expectations when updating w3c tests. | 5 """A class for updating layout test expectations when updating w3c tests. |
6 | 6 |
7 Specifically, this class fetches results from try bots for the current CL, and: | 7 Specifically, this class fetches results from try bots for the current CL, and: |
8 1. Downloads new baseline files for any tests that can be rebaselined. | 8 1. Downloads new baseline files for any tests that can be rebaselined. |
9 2. Updates the generic TestExpectations file for any other failing tests. | 9 2. Updates the generic TestExpectations file for any other failing tests. |
10 | 10 |
11 This is used as part of the w3c test auto-import process. | 11 This is used as part of the w3c test auto-import process. |
12 """ | 12 """ |
13 | 13 |
14 import argparse | 14 import argparse |
15 import logging | 15 import logging |
16 | 16 |
17 from webkitpy.common.net.git_cl import GitCL | 17 from webkitpy.common.net.git_cl import GitCL |
18 from webkitpy.common.net.rietveld import Rietveld | 18 from webkitpy.common.net.rietveld import Rietveld |
19 from webkitpy.common.webkit_finder import WebKitFinder | 19 from webkitpy.common.webkit_finder import WebKitFinder |
20 from webkitpy.w3c.test_parser import TestParser | 20 from webkitpy.w3c.test_parser import TestParser |
| 21 from webkitpy.layout_tests.models.test_expectations import TestExpectationLine |
21 | 22 |
22 _log = logging.getLogger(__name__) | 23 _log = logging.getLogger(__name__) |
23 | 24 |
24 | 25 |
25 class W3CExpectationsLineAdder(object): | 26 class W3CExpectationsLineAdder(object): |
26 | 27 |
27 def __init__(self, host): | 28 def __init__(self, host): |
28 self.host = host | 29 self.host = host |
29 self.host.initialize_scm() | 30 self.host.initialize_scm() |
30 self.finder = WebKitFinder(self.host.filesystem) | 31 self.finder = WebKitFinder(self.host.filesystem) |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 platform_list.append(platform) | 250 platform_list.append(platform) |
250 bug.append(platform_results[platform]['bug']) | 251 bug.append(platform_results[platform]['bug']) |
251 expectations = self.get_expectations(platform_results[platfo
rm]) | 252 expectations = self.get_expectations(platform_results[platfo
rm]) |
252 line = '%s [ %s ] %s [ %s ]' % (bug[0], ' '.join(platform_li
st), test_name, ' '.join(expectations)) | 253 line = '%s [ %s ] %s [ %s ]' % (bug[0], ' '.join(platform_li
st), test_name, ' '.join(expectations)) |
253 line_list.append(str(line)) | 254 line_list.append(str(line)) |
254 return line_list | 255 return line_list |
255 | 256 |
256 def write_to_test_expectations(self, line_list): | 257 def write_to_test_expectations(self, line_list): |
257 """Writes to TestExpectations. | 258 """Writes to TestExpectations. |
258 | 259 |
259 Writes the test expectations lines in |line_list| to the test | |
260 expectations file. | |
261 | |
262 The place in the file where the new lines are inserted is after a | 260 The place in the file where the new lines are inserted is after a |
263 marker comment line. If this marker comment line is not found, it will | 261 marker comment line. If this marker comment line is not found, it will |
264 be added to the end of the file. | 262 be added to the end of the file. |
265 | 263 |
266 Args: | 264 Args: |
267 line_list: A list of w3c test expectations lines. | 265 line_list: A list of lines to add to the TestExpectations file. |
268 """ | 266 """ |
269 _log.debug('Lines to write to TestExpectations: %r', line_list) | 267 _log.debug('Lines to write to TestExpectations: %r', line_list) |
270 port = self.host.port_factory.get() | 268 port = self.host.port_factory.get() |
271 expectations_file = port.path_to_generic_test_expectations_file() | 269 expectations_file_path = port.path_to_generic_test_expectations_file() |
272 comment_line = '# Tests added from W3C auto import bot' | 270 marker_comment = '# Tests added from W3C auto import bot' |
273 file_contents = self.host.filesystem.read_text_file(expectations_file) | 271 file_contents = self.host.filesystem.read_text_file(expectations_file_pa
th) |
274 w3c_comment_line_index = file_contents.find(comment_line) | 272 marker_comment_index = file_contents.find(marker_comment) |
275 all_lines = '' | 273 line_list = [line for line in line_list if self._test_name_from_expectat
ion_string(line) not in file_contents] |
276 for line in line_list: | 274 if marker_comment_index == -1: |
277 end_bracket_index = line.split().index(']') | 275 file_contents += '\n%s\n' % marker_comment |
278 test_name = line.split()[end_bracket_index + 1] | 276 file_contents += '\n'.join(line_list) |
279 if test_name in file_contents: | |
280 continue | |
281 all_lines += str(line) + '\n' | |
282 all_lines = all_lines[:-1] | |
283 if w3c_comment_line_index == -1: | |
284 file_contents += '\n%s\n' % comment_line | |
285 file_contents += all_lines | |
286 else: | 277 else: |
287 end_of_comment_line = (file_contents[w3c_comment_line_index:].find('
\n')) + w3c_comment_line_index | 278 end_of_marker_line = (file_contents[marker_comment_index:].find('\n'
)) + marker_comment_index |
288 new_data = file_contents[: end_of_comment_line + 1] + all_lines + fi
le_contents[end_of_comment_line:] | 279 file_contents = file_contents[:end_of_marker_line + 1] + '\n'.join(l
ine_list) + file_contents[end_of_marker_line:] |
289 file_contents = new_data | 280 self.host.filesystem.write_text_file(expectations_file_path, file_conten
ts) |
290 self.host.filesystem.write_text_file(expectations_file, file_contents) | 281 |
| 282 @staticmethod |
| 283 def _test_name_from_expectation_string(expectation_string): |
| 284 return TestExpectationLine.tokenize_line(filename='', expectation_string
=expectation_string, line_number=0).name |
291 | 285 |
292 def get_expected_txt_files(self, tests_results): | 286 def get_expected_txt_files(self, tests_results): |
293 """Fetches new baseline files for tests that should be rebaselined. | 287 """Fetches new baseline files for tests that should be rebaselined. |
294 | 288 |
295 Invokes webkit-patch rebaseline-from-try-jobs in order to download new | 289 Invokes webkit-patch rebaseline-from-try-jobs in order to download new |
296 -expected.txt files for testharness.js tests that did not crash or time | 290 -expected.txt files for testharness.js tests that did not crash or time |
297 out. Then, the platform-specific test is removed from the overall | 291 out. Then, the platform-specific test is removed from the overall |
298 failure test dictionary. | 292 failure test dictionary. |
299 | 293 |
300 Args: | 294 Args: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 350 |
357 Args: | 351 Args: |
358 test_path: A file path relative to the layout tests directory. | 352 test_path: A file path relative to the layout tests directory. |
359 This might correspond to a deleted file or a non-test. | 353 This might correspond to a deleted file or a non-test. |
360 """ | 354 """ |
361 absolute_path = self.host.filesystem.join(self.finder.layout_tests_dir()
, test_path) | 355 absolute_path = self.host.filesystem.join(self.finder.layout_tests_dir()
, test_path) |
362 test_parser = TestParser(absolute_path, self.host) | 356 test_parser = TestParser(absolute_path, self.host) |
363 if not test_parser.test_doc: | 357 if not test_parser.test_doc: |
364 return False | 358 return False |
365 return test_parser.is_jstest() | 359 return test_parser.is_jstest() |
OLD | NEW |