| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 """ | 3 """ |
| 4 Copyright 2013 Google Inc. | 4 Copyright 2013 Google Inc. |
| 5 | 5 |
| 6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
| 7 found in the LICENSE file. | 7 found in the LICENSE file. |
| 8 | 8 |
| 9 Repackage expected/actual GM results as needed by our HTML rebaseline viewer. | 9 Repackage expected/actual GM results as needed by our HTML rebaseline viewer. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 # System-level imports | 12 # System-level imports |
| 13 import argparse | 13 import argparse |
| 14 import fnmatch | 14 import fnmatch |
| 15 import json | |
| 16 import logging | 15 import logging |
| 17 import os | 16 import os |
| 18 import re | |
| 19 import sys | |
| 20 import time | 17 import time |
| 21 | 18 |
| 19 # Must fix up PYTHONPATH before importing from within Skia |
| 20 # pylint: disable=W0611 |
| 21 import fix_pythonpath |
| 22 # pylint: enable=W0611 |
| 23 |
| 22 # Imports from within Skia | 24 # Imports from within Skia |
| 23 import fix_pythonpath # must do this first | |
| 24 from pyutils import url_utils | 25 from pyutils import url_utils |
| 26 import column |
| 25 import gm_json | 27 import gm_json |
| 26 import imagediffdb | 28 import imagediffdb |
| 27 import imagepair | 29 import imagepair |
| 28 import imagepairset | 30 import imagepairset |
| 29 import results | 31 import results |
| 30 | 32 |
| 31 EXPECTATION_FIELDS_PASSED_THRU_VERBATIM = [ | 33 EXPECTATION_FIELDS_PASSED_THRU_VERBATIM = [ |
| 32 results.KEY__EXPECTATIONS__BUGS, | 34 results.KEY__EXPECTATIONS__BUGS, |
| 33 results.KEY__EXPECTATIONS__IGNOREFAILURE, | 35 results.KEY__EXPECTATIONS__IGNOREFAILURE, |
| 34 results.KEY__EXPECTATIONS__REVIEWED, | 36 results.KEY__EXPECTATIONS__REVIEWED, |
| 35 ] | 37 ] |
| 38 FREEFORM_COLUMN_IDS = [ |
| 39 results.KEY__EXTRACOLUMNS__BUILDER, |
| 40 results.KEY__EXTRACOLUMNS__TEST, |
| 41 ] |
| 42 ORDERED_COLUMN_IDS = [ |
| 43 results.KEY__EXTRACOLUMNS__RESULT_TYPE, |
| 44 results.KEY__EXTRACOLUMNS__BUILDER, |
| 45 results.KEY__EXTRACOLUMNS__TEST, |
| 46 results.KEY__EXTRACOLUMNS__CONFIG, |
| 47 ] |
| 48 |
| 36 TRUNK_DIRECTORY = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) | 49 TRUNK_DIRECTORY = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
| 37 DEFAULT_EXPECTATIONS_DIR = os.path.join(TRUNK_DIRECTORY, 'expectations', 'gm') | 50 DEFAULT_EXPECTATIONS_DIR = os.path.join(TRUNK_DIRECTORY, 'expectations', 'gm') |
| 38 DEFAULT_IGNORE_FAILURES_FILE = 'ignored-tests.txt' | 51 DEFAULT_IGNORE_FAILURES_FILE = 'ignored-tests.txt' |
| 39 | 52 |
| 40 IMAGEPAIR_SET_DESCRIPTIONS = ('expected image', 'actual image') | 53 IMAGEPAIR_SET_DESCRIPTIONS = ('expected image', 'actual image') |
| 41 | 54 |
| 42 | 55 |
| 43 class ExpectationComparisons(results.BaseComparisons): | 56 class ExpectationComparisons(results.BaseComparisons): |
| 44 """Loads actual and expected GM results into an ImagePairSet. | 57 """Loads actual and expected GM results into an ImagePairSet. |
| 45 | 58 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 pattern: which files to write within root (fnmatch-style pattern) | 177 pattern: which files to write within root (fnmatch-style pattern) |
| 165 | 178 |
| 166 Raises: | 179 Raises: |
| 167 IOError if root does not refer to an existing directory | 180 IOError if root does not refer to an existing directory |
| 168 KeyError if the set of per-builder dictionaries written out was | 181 KeyError if the set of per-builder dictionaries written out was |
| 169 different than expected | 182 different than expected |
| 170 """ | 183 """ |
| 171 if not os.path.isdir(root): | 184 if not os.path.isdir(root): |
| 172 raise IOError('no directory found at path %s' % root) | 185 raise IOError('no directory found at path %s' % root) |
| 173 actual_builders_written = [] | 186 actual_builders_written = [] |
| 174 for dirpath, dirnames, filenames in os.walk(root): | 187 for dirpath, _, filenames in os.walk(root): |
| 175 for matching_filename in fnmatch.filter(filenames, pattern): | 188 for matching_filename in fnmatch.filter(filenames, pattern): |
| 176 builder = os.path.basename(dirpath) | 189 builder = os.path.basename(dirpath) |
| 177 per_builder_dict = meta_dict.get(builder) | 190 per_builder_dict = meta_dict.get(builder) |
| 178 if per_builder_dict is not None: | 191 if per_builder_dict is not None: |
| 179 fullpath = os.path.join(dirpath, matching_filename) | 192 fullpath = os.path.join(dirpath, matching_filename) |
| 180 gm_json.WriteToFile(per_builder_dict, fullpath) | 193 gm_json.WriteToFile(per_builder_dict, fullpath) |
| 181 actual_builders_written.append(builder) | 194 actual_builders_written.append(builder) |
| 182 | 195 |
| 183 # Check: did we write out the set of per-builder dictionaries we | 196 # Check: did we write out the set of per-builder dictionaries we |
| 184 # expected to? | 197 # expected to? |
| (...skipping 19 matching lines...) Expand all Loading... |
| 204 expected_builder_dicts = self._read_builder_dicts_from_root( | 217 expected_builder_dicts = self._read_builder_dicts_from_root( |
| 205 self._expected_root) | 218 self._expected_root) |
| 206 | 219 |
| 207 all_image_pairs = imagepairset.ImagePairSet( | 220 all_image_pairs = imagepairset.ImagePairSet( |
| 208 descriptions=IMAGEPAIR_SET_DESCRIPTIONS, | 221 descriptions=IMAGEPAIR_SET_DESCRIPTIONS, |
| 209 diff_base_url=self._diff_base_url) | 222 diff_base_url=self._diff_base_url) |
| 210 failing_image_pairs = imagepairset.ImagePairSet( | 223 failing_image_pairs = imagepairset.ImagePairSet( |
| 211 descriptions=IMAGEPAIR_SET_DESCRIPTIONS, | 224 descriptions=IMAGEPAIR_SET_DESCRIPTIONS, |
| 212 diff_base_url=self._diff_base_url) | 225 diff_base_url=self._diff_base_url) |
| 213 | 226 |
| 227 # Override settings for columns that should be filtered using freeform text. |
| 228 for column_id in FREEFORM_COLUMN_IDS: |
| 229 factory = column.ColumnHeaderFactory( |
| 230 header_text=column_id, use_freeform_filter=True) |
| 231 all_image_pairs.set_column_header_factory( |
| 232 column_id=column_id, column_header_factory=factory) |
| 233 failing_image_pairs.set_column_header_factory( |
| 234 column_id=column_id, column_header_factory=factory) |
| 235 |
| 214 all_image_pairs.ensure_extra_column_values_in_summary( | 236 all_image_pairs.ensure_extra_column_values_in_summary( |
| 215 column_id=results.KEY__EXTRACOLUMNS__RESULT_TYPE, values=[ | 237 column_id=results.KEY__EXTRACOLUMNS__RESULT_TYPE, values=[ |
| 216 results.KEY__RESULT_TYPE__FAILED, | 238 results.KEY__RESULT_TYPE__FAILED, |
| 217 results.KEY__RESULT_TYPE__FAILUREIGNORED, | 239 results.KEY__RESULT_TYPE__FAILUREIGNORED, |
| 218 results.KEY__RESULT_TYPE__NOCOMPARISON, | 240 results.KEY__RESULT_TYPE__NOCOMPARISON, |
| 219 results.KEY__RESULT_TYPE__SUCCEEDED, | 241 results.KEY__RESULT_TYPE__SUCCEEDED, |
| 220 ]) | 242 ]) |
| 221 failing_image_pairs.ensure_extra_column_values_in_summary( | 243 failing_image_pairs.ensure_extra_column_values_in_summary( |
| 222 column_id=results.KEY__EXTRACOLUMNS__RESULT_TYPE, values=[ | 244 column_id=results.KEY__EXTRACOLUMNS__RESULT_TYPE, values=[ |
| 223 results.KEY__RESULT_TYPE__FAILED, | 245 results.KEY__RESULT_TYPE__FAILED, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 imageA_relative_url=expected_image_relative_url, | 354 imageA_relative_url=expected_image_relative_url, |
| 333 imageB_relative_url=actual_image_relative_url, | 355 imageB_relative_url=actual_image_relative_url, |
| 334 expectations=expectations_dict, | 356 expectations=expectations_dict, |
| 335 extra_columns=extra_columns_dict) | 357 extra_columns=extra_columns_dict) |
| 336 all_image_pairs.add_image_pair(image_pair) | 358 all_image_pairs.add_image_pair(image_pair) |
| 337 if updated_result_type != results.KEY__RESULT_TYPE__SUCCEEDED: | 359 if updated_result_type != results.KEY__RESULT_TYPE__SUCCEEDED: |
| 338 failing_image_pairs.add_image_pair(image_pair) | 360 failing_image_pairs.add_image_pair(image_pair) |
| 339 except Exception: | 361 except Exception: |
| 340 logging.exception('got exception while creating new ImagePair') | 362 logging.exception('got exception while creating new ImagePair') |
| 341 | 363 |
| 364 # pylint: disable=W0201 |
| 342 self._results = { | 365 self._results = { |
| 343 results.KEY__HEADER__RESULTS_ALL: all_image_pairs.as_dict(), | 366 results.KEY__HEADER__RESULTS_ALL: all_image_pairs.as_dict( |
| 344 results.KEY__HEADER__RESULTS_FAILURES: failing_image_pairs.as_dict(), | 367 column_ids_in_order=ORDERED_COLUMN_IDS), |
| 368 results.KEY__HEADER__RESULTS_FAILURES: failing_image_pairs.as_dict( |
| 369 column_ids_in_order=ORDERED_COLUMN_IDS), |
| 345 } | 370 } |
| 346 | 371 |
| 347 | 372 |
| 348 def main(): | 373 def main(): |
| 349 logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', | 374 logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', |
| 350 datefmt='%m/%d/%Y %H:%M:%S', | 375 datefmt='%m/%d/%Y %H:%M:%S', |
| 351 level=logging.INFO) | 376 level=logging.INFO) |
| 352 parser = argparse.ArgumentParser() | 377 parser = argparse.ArgumentParser() |
| 353 parser.add_argument( | 378 parser.add_argument( |
| 354 '--actuals', default=results.DEFAULT_ACTUALS_DIR, | 379 '--actuals', default=results.DEFAULT_ACTUALS_DIR, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 382 expected_root=args.expectations, | 407 expected_root=args.expectations, |
| 383 ignore_failures_file=args.ignore_failures_file, | 408 ignore_failures_file=args.ignore_failures_file, |
| 384 generated_images_root=args.workdir) | 409 generated_images_root=args.workdir) |
| 385 gm_json.WriteToFile( | 410 gm_json.WriteToFile( |
| 386 results_obj.get_packaged_results_of_type(results_type=args.results), | 411 results_obj.get_packaged_results_of_type(results_type=args.results), |
| 387 args.outfile) | 412 args.outfile) |
| 388 | 413 |
| 389 | 414 |
| 390 if __name__ == '__main__': | 415 if __name__ == '__main__': |
| 391 main() | 416 main() |
| OLD | NEW |