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 script to modify TestExpectations lines based layout test failures in try j
obs. | 5 """A script to modify TestExpectations lines based layout test failures in try j
obs. |
6 | 6 |
7 This script outputs a list of test expectation lines to add to a 'TestExpectatio
ns' file | 7 This script outputs a list of test expectation lines to add to a 'TestExpectatio
ns' file |
8 by retrieving the try job results for the current CL. | 8 by retrieving the try job results for the current CL. |
9 """ | 9 """ |
10 | 10 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 line_list.append(str(line)) | 223 line_list.append(str(line)) |
224 return line_list | 224 return line_list |
225 | 225 |
226 def write_to_test_expectations(self, host, path, line_list): | 226 def write_to_test_expectations(self, host, path, line_list): |
227 """Writes to TestExpectations. | 227 """Writes to TestExpectations. |
228 | 228 |
229 Writes to the test expectations lines in line_list | 229 Writes to the test expectations lines in line_list |
230 to LayoutTest/TestExpectations. Checks the file for the string | 230 to LayoutTest/TestExpectations. Checks the file for the string |
231 '# Tests added from W3C auto import bot' and writes expectation | 231 '# Tests added from W3C auto import bot' and writes expectation |
232 lines directly under it. If not found, it writes to the end of | 232 lines directly under it. If not found, it writes to the end of |
233 the file. | 233 the file. If the test name is already in LayoutTests/TestExpectations, |
| 234 the line will be skipped. |
234 | 235 |
235 Args: | 236 Args: |
236 host: A Host object. | 237 host: A Host object. |
237 path: The path to the file LayoutTest/TestExpectations. | 238 path: The path to the file LayoutTests/TestExpectations. |
238 line_list: A list of w3c test expectations lines. | 239 line_list: A list of w3c test expectations lines. |
239 | 240 |
240 Returns: | 241 Returns: |
241 Writes to a file on the filesystem called LayoutTests/TestExpectatio
ns. | 242 Writes to a file on the filesystem called LayoutTests/TestExpectatio
ns. |
242 """ | 243 """ |
243 comment_line = '# Tests added from W3C auto import bot' | 244 comment_line = '# Tests added from W3C auto import bot' |
244 file_contents = host.filesystem.read_text_file(path) | 245 file_contents = host.filesystem.read_text_file(path) |
245 w3c_comment_line_index = file_contents.find(comment_line) | 246 w3c_comment_line_index = file_contents.find(comment_line) |
246 all_lines = '' | 247 all_lines = '' |
247 for line in line_list: | 248 for line in line_list: |
| 249 end_bracket_index = line.split().index(']') |
| 250 test_name = line.split()[end_bracket_index + 1] |
| 251 if test_name in file_contents: |
| 252 continue |
248 all_lines += str(line) + '\n' | 253 all_lines += str(line) + '\n' |
249 all_lines = all_lines[:-1] | 254 all_lines = all_lines[:-1] |
250 if w3c_comment_line_index == -1: | 255 if w3c_comment_line_index == -1: |
251 file_contents += '\n%s\n' % comment_line | 256 file_contents += '\n%s\n' % comment_line |
252 file_contents += all_lines | 257 file_contents += all_lines |
253 else: | 258 else: |
254 end_of_comment_line = (file_contents[w3c_comment_line_index:].find('
\n')) + w3c_comment_line_index | 259 end_of_comment_line = (file_contents[w3c_comment_line_index:].find('
\n')) + w3c_comment_line_index |
255 new_data = file_contents[: end_of_comment_line + 1] + all_lines + fi
le_contents[end_of_comment_line:] | 260 new_data = file_contents[: end_of_comment_line + 1] + all_lines + fi
le_contents[end_of_comment_line:] |
256 file_contents = new_data | 261 file_contents = new_data |
257 host.filesystem.write_text_file(path, file_contents) | 262 host.filesystem.write_text_file(path, file_contents) |
OLD | NEW |