| 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 """ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 # If self._diff_record is set to this, we haven't asked ImageDiffDB for the | 25 # If self._diff_record is set to this, we haven't asked ImageDiffDB for the |
| 26 # image diff details yet. | 26 # image diff details yet. |
| 27 _DIFF_RECORD_STILL_LOADING = 'still_loading' | 27 _DIFF_RECORD_STILL_LOADING = 'still_loading' |
| 28 | 28 |
| 29 | 29 |
| 30 class ImagePair(object): | 30 class ImagePair(object): |
| 31 """Describes a pair of images, pixel difference info, and optional metadata. | 31 """Describes a pair of images, pixel difference info, and optional metadata. |
| 32 """ | 32 """ |
| 33 | 33 |
| 34 def __init__(self, image_diff_db, | 34 def __init__(self, image_diff_db, |
| 35 base_url, imageA_relative_url, imageB_relative_url, | 35 imageA_base_url, imageB_base_url, |
| 36 imageA_relative_url, imageB_relative_url, |
| 36 expectations=None, extra_columns=None, source_json_file=None, | 37 expectations=None, extra_columns=None, source_json_file=None, |
| 37 download_all_images=False): | 38 download_all_images=False): |
| 38 """ | 39 """ |
| 39 Args: | 40 Args: |
| 40 image_diff_db: ImageDiffDB instance we use to generate/store image diffs | 41 image_diff_db: ImageDiffDB instance we use to generate/store image diffs |
| 41 base_url: base of all image URLs | 42 imageA_base_url: string; base URL for image A |
| 43 imageB_base_url: string; base URL for image B |
| 42 imageA_relative_url: string; URL pointing at an image, relative to | 44 imageA_relative_url: string; URL pointing at an image, relative to |
| 43 base_url; or None, if this image is missing | 45 imageA_base_url; or None, if this image is missing |
| 44 imageB_relative_url: string; URL pointing at an image, relative to | 46 imageB_relative_url: string; URL pointing at an image, relative to |
| 45 base_url; or None, if this image is missing | 47 imageB_base_url; or None, if this image is missing |
| 46 expectations: optional dictionary containing expectations-specific | 48 expectations: optional dictionary containing expectations-specific |
| 47 metadata (ignore-failure, bug numbers, etc.) | 49 metadata (ignore-failure, bug numbers, etc.) |
| 48 extra_columns: optional dictionary containing more metadata (test name, | 50 extra_columns: optional dictionary containing more metadata (test name, |
| 49 builder name, etc.) | 51 builder name, etc.) |
| 50 source_json_file: relative path of the JSON file where each image came | 52 source_json_file: relative path of the JSON file where each image came |
| 51 from; this will be the same for both imageA and imageB, within their | 53 from; this will be the same for both imageA and imageB, within their |
| 52 respective directories | 54 respective directories |
| 53 download_all_images: if True, download any images associated with this | 55 download_all_images: if True, download any images associated with this |
| 54 image pair, even if we don't need them to generate diffs | 56 image pair, even if we don't need them to generate diffs |
| 55 (imageA == imageB, or one of them is missing) | 57 (imageA == imageB, or one of them is missing) |
| 56 """ | 58 """ |
| 57 self._image_diff_db = image_diff_db | 59 self._image_diff_db = image_diff_db |
| 58 self.base_url = base_url | 60 self.imageA_base_url = imageA_base_url |
| 61 self.imageB_base_url = imageB_base_url |
| 59 self.imageA_relative_url = imageA_relative_url | 62 self.imageA_relative_url = imageA_relative_url |
| 60 self.imageB_relative_url = imageB_relative_url | 63 self.imageB_relative_url = imageB_relative_url |
| 61 self.expectations_dict = expectations | 64 self.expectations_dict = expectations |
| 62 self.extra_columns_dict = extra_columns | 65 self.extra_columns_dict = extra_columns |
| 63 self.source_json_file = source_json_file | 66 self.source_json_file = source_json_file |
| 64 if not imageA_relative_url or not imageB_relative_url: | 67 if not imageA_relative_url or not imageB_relative_url: |
| 65 self._is_different = True | 68 self._is_different = True |
| 66 self._diff_record = None | 69 self._diff_record = None |
| 67 elif imageA_relative_url == imageB_relative_url: | 70 elif imageA_relative_url == imageB_relative_url: |
| 68 self._is_different = False | 71 self._is_different = False |
| 69 self._diff_record = None | 72 self._diff_record = None |
| 70 else: | 73 else: |
| 71 # Tell image_diff_db to add an entry for this diff asynchronously. | 74 # Tell image_diff_db to add an entry for this diff asynchronously. |
| 72 # Later on, we will call image_diff_db.get_diff_record() to find it. | 75 # Later on, we will call image_diff_db.get_diff_record() to find it. |
| 73 self._is_different = True | 76 self._is_different = True |
| 74 self._diff_record = _DIFF_RECORD_STILL_LOADING | 77 self._diff_record = _DIFF_RECORD_STILL_LOADING |
| 75 | 78 |
| 76 if self._diff_record != None or download_all_images: | 79 if self._diff_record != None or download_all_images: |
| 77 image_diff_db.add_image_pair( | 80 image_diff_db.add_image_pair( |
| 78 expected_image_locator=imageA_relative_url, | 81 expected_image_locator=imageA_relative_url, |
| 79 expected_image_url=self.posixpath_join(base_url, imageA_relative_url), | 82 expected_image_url=self.posixpath_join(imageA_base_url, |
| 83 imageA_relative_url), |
| 80 actual_image_locator=imageB_relative_url, | 84 actual_image_locator=imageB_relative_url, |
| 81 actual_image_url=self.posixpath_join(base_url, imageB_relative_url)) | 85 actual_image_url=self.posixpath_join(imageB_base_url, |
| 86 imageB_relative_url)) |
| 82 | 87 |
| 83 def as_dict(self): | 88 def as_dict(self): |
| 84 """Returns a dictionary describing this ImagePair. | 89 """Returns a dictionary describing this ImagePair. |
| 85 | 90 |
| 86 Uses the KEY__IMAGEPAIRS__* constants as keys. | 91 Uses the KEY__IMAGEPAIRS__* constants as keys. |
| 87 """ | 92 """ |
| 88 asdict = { | 93 asdict = { |
| 89 KEY__IMAGEPAIRS__IMAGE_A_URL: self.imageA_relative_url, | 94 KEY__IMAGEPAIRS__IMAGE_A_URL: self.imageA_relative_url, |
| 90 KEY__IMAGEPAIRS__IMAGE_B_URL: self.imageB_relative_url, | 95 KEY__IMAGEPAIRS__IMAGE_B_URL: self.imageB_relative_url, |
| 91 } | 96 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 114 @staticmethod | 119 @staticmethod |
| 115 def posixpath_join(*args): | 120 def posixpath_join(*args): |
| 116 """Wrapper around posixpath.join(). | 121 """Wrapper around posixpath.join(). |
| 117 | 122 |
| 118 Returns posixpath.join(*args), or None if any arg is None. | 123 Returns posixpath.join(*args), or None if any arg is None. |
| 119 """ | 124 """ |
| 120 for arg in args: | 125 for arg in args: |
| 121 if arg == None: | 126 if arg == None: |
| 122 return None | 127 return None |
| 123 return posixpath.join(*args) | 128 return posixpath.join(*args) |
| OLD | NEW |