Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 """ | |
| 4 Copyright 2014 Google Inc. | |
| 5 | |
| 6 Use of this source code is governed by a BSD-style license that can be | |
| 7 found in the LICENSE file. | |
| 8 | |
| 9 ImagePair class (see class docstring for details) | |
| 10 """ | |
| 11 | |
| 12 import posixpath | |
| 13 | |
| 14 # Keys used within ImagePair dictionary representations. | |
| 15 KEY_DIFFERENCE_DATA = 'differenceData' | |
| 16 KEY_EXPECTATIONS_DATA = 'expectationsData' | |
| 17 KEY_EXTRA_COLUMN_VALUES = 'extraColumnValues' | |
| 18 KEY_IMAGE_A_URL = 'imageAUrl' | |
| 19 KEY_IMAGE_B_URL = 'imageBUrl' | |
| 20 KEY_IS_DIFFERENT = 'isDifferent' | |
|
rmistry
2014/02/10 18:09:29
From the style guide in http://google-styleguide.g
epoger
2014/02/10 18:18:41
Wow. Thanks for finding that... even though I don
| |
| 21 | |
| 22 | |
| 23 class ImagePair(object): | |
| 24 """ | |
| 25 Describes a pair of images, along with optional metadata (pixel difference | |
| 26 metrics, whether to ignore mismatches, etc.) | |
| 27 """ | |
| 28 | |
| 29 def __init__(self, image_diff_db, | |
| 30 base_url, imageA_relative_url, imageB_relative_url, | |
| 31 expectations=None, extra_columns=None): | |
| 32 """ | |
| 33 Args: | |
| 34 image_diff_db: ImageDiffDB instance we use to generate/store image diffs | |
| 35 base_url: base of all image URLs | |
| 36 imageA_relative_url: URL pointing at an image, relative to base_url | |
| 37 imageB_relative_url: URL pointing at an image, relative to base_url | |
| 38 expectations: optional dictionary containing expectations-specific | |
| 39 metadata (ignore-failure, bug numbers, etc.) | |
| 40 extra_columns: optional dictionary containing more metadata (test name, | |
| 41 builder name, etc.) | |
| 42 """ | |
| 43 self.base_url = base_url | |
| 44 self.imageA_relative_url = imageA_relative_url | |
| 45 self.imageB_relative_url = imageB_relative_url | |
| 46 self.expectations_dict = expectations | |
| 47 self.extra_columns_dict = extra_columns | |
| 48 if imageA_relative_url == imageB_relative_url: | |
| 49 self.diff_record = None | |
| 50 else: | |
| 51 # TODO(epoger): Rather than blocking until image_diff_db can read in | |
| 52 # the image pair and generate diffs, it would be better to do it | |
| 53 # asynchronously: tell image_diff_db to download a bunch of file pairs, | |
| 54 # and only block later if we're still waiting for diff_records to come | |
| 55 # back. | |
| 56 image_diff_db.add_image_pair( | |
| 57 expected_image_locator=imageA_relative_url, | |
| 58 expected_image_url=posixpath.join(base_url, imageA_relative_url), | |
| 59 actual_image_locator=imageB_relative_url, | |
| 60 actual_image_url=posixpath.join(base_url, imageB_relative_url)) | |
| 61 self.diff_record = image_diff_db.get_diff_record( | |
| 62 expected_image_locator=imageA_relative_url, | |
| 63 actual_image_locator=imageB_relative_url) | |
| 64 | |
| 65 def as_dict(self): | |
| 66 """ | |
| 67 Return a dictionary describing this ImagePair, as needed when constructing | |
| 68 the JSON representation. Uses the KEY_* constants as keys. | |
| 69 """ | |
| 70 asdict = { | |
| 71 KEY_IMAGE_A_URL: self.imageA_relative_url, | |
| 72 KEY_IMAGE_B_URL: self.imageB_relative_url, | |
| 73 } | |
| 74 if self.expectations_dict: | |
| 75 asdict[KEY_EXPECTATIONS_DATA] = self.expectations_dict | |
| 76 if self.extra_columns_dict: | |
| 77 asdict[KEY_EXTRA_COLUMN_VALUES] = self.extra_columns_dict | |
| 78 if self.diff_record and (self.diff_record.get_num_pixels_differing() > 0): | |
| 79 asdict[KEY_IS_DIFFERENT] = True | |
| 80 asdict[KEY_DIFFERENCE_DATA] = self.diff_record.as_dict() | |
| 81 else: | |
| 82 asdict[KEY_IS_DIFFERENT] = False | |
| 83 return asdict | |
| OLD | NEW |