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 |
14 # Keys used within ImagePair dictionary representations. | 15 # Keys used within ImagePair dictionary representations. |
15 # NOTE: Keep these in sync with static/constants.js | 16 # NOTE: Keep these in sync with static/constants.js |
16 KEY__DIFFERENCE_DATA = 'differenceData' | 17 KEY__IMAGEPAIRS__DIFFERENCES = 'differenceData' |
17 KEY__EXPECTATIONS_DATA = 'expectations' | 18 KEY__IMAGEPAIRS__EXPECTATIONS = 'expectations' |
18 KEY__EXTRA_COLUMN_VALUES = 'extraColumns' | 19 KEY__IMAGEPAIRS__EXTRACOLUMNS = 'extraColumns' |
19 KEY__IMAGE_A_URL = 'imageAUrl' | 20 KEY__IMAGEPAIRS__IMAGE_A_URL = 'imageAUrl' |
20 KEY__IMAGE_B_URL = 'imageBUrl' | 21 KEY__IMAGEPAIRS__IMAGE_B_URL = 'imageBUrl' |
21 KEY__IS_DIFFERENT = 'isDifferent' | 22 KEY__IMAGEPAIRS__IS_DIFFERENT = 'isDifferent' |
22 | 23 |
23 | 24 |
24 class ImagePair(object): | 25 class ImagePair(object): |
25 """Describes a pair of images, pixel difference info, and optional metadata. | 26 """Describes a pair of images, pixel difference info, and optional metadata. |
26 """ | 27 """ |
27 | 28 |
28 def __init__(self, image_diff_db, | 29 def __init__(self, image_diff_db, |
29 base_url, imageA_relative_url, imageB_relative_url, | 30 base_url, imageA_relative_url, imageB_relative_url, |
30 expectations=None, extra_columns=None): | 31 expectations=None, extra_columns=None): |
31 """ | 32 """ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 actual_image_url=posixpath.join(base_url, imageB_relative_url)) | 67 actual_image_url=posixpath.join(base_url, imageB_relative_url)) |
67 self.diff_record = image_diff_db.get_diff_record( | 68 self.diff_record = image_diff_db.get_diff_record( |
68 expected_image_locator=imageA_relative_url, | 69 expected_image_locator=imageA_relative_url, |
69 actual_image_locator=imageB_relative_url) | 70 actual_image_locator=imageB_relative_url) |
70 if self.diff_record and self.diff_record.get_num_pixels_differing() == 0: | 71 if self.diff_record and self.diff_record.get_num_pixels_differing() == 0: |
71 self._is_different = False | 72 self._is_different = False |
72 | 73 |
73 def as_dict(self): | 74 def as_dict(self): |
74 """Returns a dictionary describing this ImagePair. | 75 """Returns a dictionary describing this ImagePair. |
75 | 76 |
76 Uses the KEY__* constants as keys. | 77 Uses the KEY__IMAGEPAIRS__* constants as keys. |
77 """ | 78 """ |
78 asdict = { | 79 asdict = { |
79 KEY__IMAGE_A_URL: self.imageA_relative_url, | 80 KEY__IMAGEPAIRS__IMAGE_A_URL: self.imageA_relative_url, |
80 KEY__IMAGE_B_URL: self.imageB_relative_url, | 81 KEY__IMAGEPAIRS__IMAGE_B_URL: self.imageB_relative_url, |
81 } | 82 } |
82 asdict[KEY__IS_DIFFERENT] = self._is_different | 83 asdict[KEY__IMAGEPAIRS__IS_DIFFERENT] = self._is_different |
83 if self.expectations_dict: | 84 if self.expectations_dict: |
84 asdict[KEY__EXPECTATIONS_DATA] = self.expectations_dict | 85 asdict[KEY__IMAGEPAIRS__EXPECTATIONS] = self.expectations_dict |
85 if self.extra_columns_dict: | 86 if self.extra_columns_dict: |
86 asdict[KEY__EXTRA_COLUMN_VALUES] = self.extra_columns_dict | 87 asdict[KEY__IMAGEPAIRS__EXTRACOLUMNS] = self.extra_columns_dict |
87 if self.diff_record and (self.diff_record.get_num_pixels_differing() > 0): | 88 if self.diff_record and (self.diff_record.get_num_pixels_differing() > 0): |
88 asdict[KEY__DIFFERENCE_DATA] = self.diff_record.as_dict() | 89 asdict[KEY__IMAGEPAIRS__DIFFERENCES] = self.diff_record.as_dict() |
89 return asdict | 90 return asdict |
OLD | NEW |