| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 """ | 3 """ |
| 4 Copyright 2014 Google Inc. | 4 Copyright 2014 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 ImagePair class (see class docstring for details) | 9 ImagePair class (see class docstring for details) |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 import posixpath | 12 import posixpath |
| 13 | 13 |
| 14 # Keys used within ImagePair dictionary representations. | 14 # Keys used within ImagePair dictionary representations. |
| 15 KEY_DIFFERENCE_DATA = 'differenceData' | 15 KEY__DIFFERENCE_DATA = 'differenceData' |
| 16 KEY_EXPECTATIONS_DATA = 'expectationsData' | 16 KEY__EXPECTATIONS_DATA = 'expectations' |
| 17 KEY_EXTRA_COLUMN_VALUES = 'extraColumnValues' | 17 KEY__EXTRA_COLUMN_VALUES = 'extraColumns' |
| 18 KEY_IMAGE_A_URL = 'imageAUrl' | 18 KEY__IMAGE_A_URL = 'imageAUrl' |
| 19 KEY_IMAGE_B_URL = 'imageBUrl' | 19 KEY__IMAGE_B_URL = 'imageBUrl' |
| 20 KEY_IS_DIFFERENT = 'isDifferent' | 20 KEY__IS_DIFFERENT = 'isDifferent' |
| 21 | 21 |
| 22 | 22 |
| 23 class ImagePair(object): | 23 class ImagePair(object): |
| 24 """ | 24 """Describes a pair of images, pixel difference info, and optional metadata. |
| 25 Describes a pair of images, along with optional metadata (pixel difference | |
| 26 metrics, whether to ignore mismatches, etc.) | |
| 27 """ | 25 """ |
| 28 | 26 |
| 29 def __init__(self, image_diff_db, | 27 def __init__(self, image_diff_db, |
| 30 base_url, imageA_relative_url, imageB_relative_url, | 28 base_url, imageA_relative_url, imageB_relative_url, |
| 31 expectations=None, extra_columns=None): | 29 expectations=None, extra_columns=None): |
| 32 """ | 30 """ |
| 33 Args: | 31 Args: |
| 34 image_diff_db: ImageDiffDB instance we use to generate/store image diffs | 32 image_diff_db: ImageDiffDB instance we use to generate/store image diffs |
| 35 base_url: base of all image URLs | 33 base_url: base of all image URLs |
| 36 imageA_relative_url: URL pointing at an image, relative to base_url | 34 imageA_relative_url: URL pointing at an image, relative to base_url |
| (...skipping 19 matching lines...) Expand all Loading... |
| 56 image_diff_db.add_image_pair( | 54 image_diff_db.add_image_pair( |
| 57 expected_image_locator=imageA_relative_url, | 55 expected_image_locator=imageA_relative_url, |
| 58 expected_image_url=posixpath.join(base_url, imageA_relative_url), | 56 expected_image_url=posixpath.join(base_url, imageA_relative_url), |
| 59 actual_image_locator=imageB_relative_url, | 57 actual_image_locator=imageB_relative_url, |
| 60 actual_image_url=posixpath.join(base_url, imageB_relative_url)) | 58 actual_image_url=posixpath.join(base_url, imageB_relative_url)) |
| 61 self.diff_record = image_diff_db.get_diff_record( | 59 self.diff_record = image_diff_db.get_diff_record( |
| 62 expected_image_locator=imageA_relative_url, | 60 expected_image_locator=imageA_relative_url, |
| 63 actual_image_locator=imageB_relative_url) | 61 actual_image_locator=imageB_relative_url) |
| 64 | 62 |
| 65 def as_dict(self): | 63 def as_dict(self): |
| 66 """ | 64 """Returns a dictionary describing this ImagePair. |
| 67 Return a dictionary describing this ImagePair, as needed when constructing | 65 |
| 68 the JSON representation. Uses the KEY_* constants as keys. | 66 Uses the KEY__* constants as keys. |
| 69 """ | 67 """ |
| 70 asdict = { | 68 asdict = { |
| 71 KEY_IMAGE_A_URL: self.imageA_relative_url, | 69 KEY__IMAGE_A_URL: self.imageA_relative_url, |
| 72 KEY_IMAGE_B_URL: self.imageB_relative_url, | 70 KEY__IMAGE_B_URL: self.imageB_relative_url, |
| 73 } | 71 } |
| 74 if self.expectations_dict: | 72 if self.expectations_dict: |
| 75 asdict[KEY_EXPECTATIONS_DATA] = self.expectations_dict | 73 asdict[KEY__EXPECTATIONS_DATA] = self.expectations_dict |
| 76 if self.extra_columns_dict: | 74 if self.extra_columns_dict: |
| 77 asdict[KEY_EXTRA_COLUMN_VALUES] = self.extra_columns_dict | 75 asdict[KEY__EXTRA_COLUMN_VALUES] = self.extra_columns_dict |
| 78 if self.diff_record and (self.diff_record.get_num_pixels_differing() > 0): | 76 if self.diff_record and (self.diff_record.get_num_pixels_differing() > 0): |
| 79 asdict[KEY_IS_DIFFERENT] = True | 77 asdict[KEY__IS_DIFFERENT] = True |
| 80 asdict[KEY_DIFFERENCE_DATA] = self.diff_record.as_dict() | 78 asdict[KEY__DIFFERENCE_DATA] = self.diff_record.as_dict() |
| 81 else: | 79 else: |
| 82 asdict[KEY_IS_DIFFERENT] = False | 80 asdict[KEY__IS_DIFFERENT] = False |
| 83 return asdict | 81 return asdict |
| OLD | NEW |