OLD | NEW |
1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 if driver_output.image and expected_driver_output.image: | 75 if driver_output.image and expected_driver_output.image: |
76 diff_image, err_str = port.diff_image(expected_driver_output.ima
ge, driver_output.image) | 76 diff_image, err_str = port.diff_image(expected_driver_output.ima
ge, driver_output.image) |
77 if diff_image: | 77 if diff_image: |
78 writer.write_image_diff_files(diff_image) | 78 writer.write_image_diff_files(diff_image) |
79 else: | 79 else: |
80 _log.warn('ref test mismatch did not produce an image diff.'
) | 80 _log.warn('ref test mismatch did not produce an image diff.'
) |
81 writer.write_image_files(driver_output.image, expected_image=None) | 81 writer.write_image_files(driver_output.image, expected_image=None) |
82 if filesystem.exists(failure.reference_filename): | 82 if filesystem.exists(failure.reference_filename): |
83 writer.write_reftest(failure.reference_filename) | 83 writer.write_reftest(failure.reference_filename) |
84 else: | 84 else: |
85 _log.warn("reference %s was not found" % failure.reference_filen
ame) | 85 _log.warn('reference %s was not found' % failure.reference_filen
ame) |
86 elif isinstance(failure, test_failures.FailureReftestMismatchDidNotOccur
): | 86 elif isinstance(failure, test_failures.FailureReftestMismatchDidNotOccur
): |
87 writer.write_image_files(driver_output.image, expected_image=None) | 87 writer.write_image_files(driver_output.image, expected_image=None) |
88 if filesystem.exists(failure.reference_filename): | 88 if filesystem.exists(failure.reference_filename): |
89 writer.write_reftest(failure.reference_filename) | 89 writer.write_reftest(failure.reference_filename) |
90 else: | 90 else: |
91 _log.warn("reference %s was not found" % failure.reference_filen
ame) | 91 _log.warn('reference %s was not found' % failure.reference_filen
ame) |
92 else: | 92 else: |
93 assert isinstance(failure, (test_failures.FailureTimeout, test_failu
res.FailureReftestNoImagesGenerated)) | 93 assert isinstance(failure, (test_failures.FailureTimeout, test_failu
res.FailureReftestNoImagesGenerated)) |
94 | 94 |
95 writer.create_repaint_overlay_result(driver_output.text, expected_driver
_output.text) | 95 writer.create_repaint_overlay_result(driver_output.text, expected_driver
_output.text) |
96 | 96 |
97 | 97 |
98 class TestResultWriter(object): | 98 class TestResultWriter(object): |
| 99 |
99 """A class which handles all writing operations to the result directory.""" | 100 """A class which handles all writing operations to the result directory.""" |
100 | 101 |
101 # Filename pieces when writing failures to the test results directory. | 102 # Filename pieces when writing failures to the test results directory. |
102 FILENAME_SUFFIX_ACTUAL = "-actual" | 103 FILENAME_SUFFIX_ACTUAL = '-actual' |
103 FILENAME_SUFFIX_EXPECTED = "-expected" | 104 FILENAME_SUFFIX_EXPECTED = '-expected' |
104 FILENAME_SUFFIX_DIFF = "-diff" | 105 FILENAME_SUFFIX_DIFF = '-diff' |
105 FILENAME_SUFFIX_STDERR = "-stderr" | 106 FILENAME_SUFFIX_STDERR = '-stderr' |
106 FILENAME_SUFFIX_CRASH_LOG = "-crash-log" | 107 FILENAME_SUFFIX_CRASH_LOG = '-crash-log' |
107 FILENAME_SUFFIX_SAMPLE = "-sample" | 108 FILENAME_SUFFIX_SAMPLE = '-sample' |
108 FILENAME_SUFFIX_LEAK_LOG = "-leak-log" | 109 FILENAME_SUFFIX_LEAK_LOG = '-leak-log' |
109 FILENAME_SUFFIX_WDIFF = "-wdiff.html" | 110 FILENAME_SUFFIX_WDIFF = '-wdiff.html' |
110 FILENAME_SUFFIX_PRETTY_PATCH = "-pretty-diff.html" | 111 FILENAME_SUFFIX_PRETTY_PATCH = '-pretty-diff.html' |
111 FILENAME_SUFFIX_IMAGE_DIFF = "-diff.png" | 112 FILENAME_SUFFIX_IMAGE_DIFF = '-diff.png' |
112 FILENAME_SUFFIX_IMAGE_DIFFS_HTML = "-diffs.html" | 113 FILENAME_SUFFIX_IMAGE_DIFFS_HTML = '-diffs.html' |
113 FILENAME_SUFFIX_OVERLAY = "-overlay.html" | 114 FILENAME_SUFFIX_OVERLAY = '-overlay.html' |
114 | 115 |
115 def __init__(self, filesystem, port, root_output_dir, test_name): | 116 def __init__(self, filesystem, port, root_output_dir, test_name): |
116 self._filesystem = filesystem | 117 self._filesystem = filesystem |
117 self._port = port | 118 self._port = port |
118 self._root_output_dir = root_output_dir | 119 self._root_output_dir = root_output_dir |
119 self._test_name = test_name | 120 self._test_name = test_name |
120 | 121 |
121 def _make_output_directory(self): | 122 def _make_output_directory(self): |
122 """Creates the output directory (if needed) for a given test filename.""
" | 123 """Creates the output directory (if needed) for a given test filename.""
" |
123 fs = self._filesystem | 124 fs = self._filesystem |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 output: A string containing the test output | 163 output: A string containing the test output |
163 expected: A string containing the expected test output | 164 expected: A string containing the expected test output |
164 """ | 165 """ |
165 actual_filename = self.output_filename(self.FILENAME_SUFFIX_ACTUAL + fil
e_type) | 166 actual_filename = self.output_filename(self.FILENAME_SUFFIX_ACTUAL + fil
e_type) |
166 expected_filename = self.output_filename(self.FILENAME_SUFFIX_EXPECTED +
file_type) | 167 expected_filename = self.output_filename(self.FILENAME_SUFFIX_EXPECTED +
file_type) |
167 | 168 |
168 self._write_file(actual_filename, output) | 169 self._write_file(actual_filename, output) |
169 self._write_file(expected_filename, expected) | 170 self._write_file(expected_filename, expected) |
170 | 171 |
171 def write_stderr(self, error): | 172 def write_stderr(self, error): |
172 filename = self.output_filename(self.FILENAME_SUFFIX_STDERR + ".txt") | 173 filename = self.output_filename(self.FILENAME_SUFFIX_STDERR + '.txt') |
173 self._write_file(filename, error) | 174 self._write_file(filename, error) |
174 | 175 |
175 def write_crash_log(self, crash_log): | 176 def write_crash_log(self, crash_log): |
176 filename = self.output_filename(self.FILENAME_SUFFIX_CRASH_LOG + ".txt") | 177 filename = self.output_filename(self.FILENAME_SUFFIX_CRASH_LOG + '.txt') |
177 self._write_file(filename, crash_log.encode('utf8', 'replace')) | 178 self._write_file(filename, crash_log.encode('utf8', 'replace')) |
178 | 179 |
179 def write_leak_log(self, leak_log): | 180 def write_leak_log(self, leak_log): |
180 filename = self.output_filename(self.FILENAME_SUFFIX_LEAK_LOG + ".txt") | 181 filename = self.output_filename(self.FILENAME_SUFFIX_LEAK_LOG + '.txt') |
181 self._write_file(filename, leak_log) | 182 self._write_file(filename, leak_log) |
182 | 183 |
183 def copy_sample_file(self, sample_file): | 184 def copy_sample_file(self, sample_file): |
184 filename = self.output_filename(self.FILENAME_SUFFIX_SAMPLE + ".txt") | 185 filename = self.output_filename(self.FILENAME_SUFFIX_SAMPLE + '.txt') |
185 self._filesystem.copyfile(sample_file, filename) | 186 self._filesystem.copyfile(sample_file, filename) |
186 | 187 |
187 def write_text_files(self, actual_text, expected_text): | 188 def write_text_files(self, actual_text, expected_text): |
188 self.write_output_files(".txt", actual_text, expected_text) | 189 self.write_output_files('.txt', actual_text, expected_text) |
189 | 190 |
190 def create_text_diff_and_write_result(self, actual_text, expected_text): | 191 def create_text_diff_and_write_result(self, actual_text, expected_text): |
191 # FIXME: This function is actually doing the diffs as well as writing re
sults. | 192 # FIXME: This function is actually doing the diffs as well as writing re
sults. |
192 # It might be better to extract code which does 'diff' and make it a sep
arate function. | 193 # It might be better to extract code which does 'diff' and make it a sep
arate function. |
193 if not actual_text or not expected_text: | 194 if not actual_text or not expected_text: |
194 return | 195 return |
195 | 196 |
196 file_type = '.txt' | 197 file_type = '.txt' |
197 actual_filename = self.output_filename(self.FILENAME_SUFFIX_ACTUAL + fil
e_type) | 198 actual_filename = self.output_filename(self.FILENAME_SUFFIX_ACTUAL + fil
e_type) |
198 expected_filename = self.output_filename(self.FILENAME_SUFFIX_EXPECTED +
file_type) | 199 expected_filename = self.output_filename(self.FILENAME_SUFFIX_EXPECTED +
file_type) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 'diff_filename': self._output_testname(self.FILENAME_SUFFIX_IMAGE_DI
FF), | 285 'diff_filename': self._output_testname(self.FILENAME_SUFFIX_IMAGE_DI
FF), |
285 'prefix': self._output_testname(''), | 286 'prefix': self._output_testname(''), |
286 } | 287 } |
287 self._write_file(diffs_html_filename, html) | 288 self._write_file(diffs_html_filename, html) |
288 | 289 |
289 def write_reftest(self, src_filepath): | 290 def write_reftest(self, src_filepath): |
290 fs = self._filesystem | 291 fs = self._filesystem |
291 dst_dir = fs.dirname(fs.join(self._root_output_dir, self._test_name)) | 292 dst_dir = fs.dirname(fs.join(self._root_output_dir, self._test_name)) |
292 dst_filepath = fs.join(dst_dir, fs.basename(src_filepath)) | 293 dst_filepath = fs.join(dst_dir, fs.basename(src_filepath)) |
293 self._write_file(dst_filepath, fs.read_binary_file(src_filepath)) | 294 self._write_file(dst_filepath, fs.read_binary_file(src_filepath)) |
OLD | NEW |