Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1494)

Side by Side Diff: gm/rebaseline_server/imagepair.py

Issue 178253010: rebaseline_server: use new intermediate JSON format (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: delete accidentally-added actual result of unittest Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 # Keep these in sync with static/constants.js
15 KEY__DIFFERENCE_DATA = 'differenceData' 16 KEY__DIFFERENCE_DATA = 'differenceData'
16 KEY__EXPECTATIONS_DATA = 'expectations' 17 KEY__EXPECTATIONS_DATA = 'expectations'
17 KEY__EXTRA_COLUMN_VALUES = 'extraColumns' 18 KEY__EXTRA_COLUMN_VALUES = 'extraColumns'
18 KEY__IMAGE_A_URL = 'imageAUrl' 19 KEY__IMAGE_A_URL = 'imageAUrl'
19 KEY__IMAGE_B_URL = 'imageBUrl' 20 KEY__IMAGE_B_URL = 'imageBUrl'
20 KEY__IS_DIFFERENT = 'isDifferent' 21 KEY__IS_DIFFERENT = 'isDifferent'
21 22
22 23
23 class ImagePair(object): 24 class ImagePair(object):
24 """Describes a pair of images, pixel difference info, and optional metadata. 25 """Describes a pair of images, pixel difference info, and optional metadata.
25 """ 26 """
26 27
27 def __init__(self, image_diff_db, 28 def __init__(self, image_diff_db,
28 base_url, imageA_relative_url, imageB_relative_url, 29 base_url, imageA_relative_url, imageB_relative_url,
29 expectations=None, extra_columns=None): 30 expectations=None, extra_columns=None):
30 """ 31 """
31 Args: 32 Args:
32 image_diff_db: ImageDiffDB instance we use to generate/store image diffs 33 image_diff_db: ImageDiffDB instance we use to generate/store image diffs
33 base_url: base of all image URLs 34 base_url: base of all image URLs
34 imageA_relative_url: URL pointing at an image, relative to base_url 35 imageA_relative_url: string; URL pointing at an image, relative to
35 imageB_relative_url: URL pointing at an image, relative to base_url 36 base_url; or None, if this image is missing
37 imageB_relative_url: string; URL pointing at an image, relative to
38 base_url; or None, if this image is missing
36 expectations: optional dictionary containing expectations-specific 39 expectations: optional dictionary containing expectations-specific
37 metadata (ignore-failure, bug numbers, etc.) 40 metadata (ignore-failure, bug numbers, etc.)
38 extra_columns: optional dictionary containing more metadata (test name, 41 extra_columns: optional dictionary containing more metadata (test name,
39 builder name, etc.) 42 builder name, etc.)
40 """ 43 """
41 self.base_url = base_url 44 self.base_url = base_url
42 self.imageA_relative_url = imageA_relative_url 45 self.imageA_relative_url = imageA_relative_url
43 self.imageB_relative_url = imageB_relative_url 46 self.imageB_relative_url = imageB_relative_url
44 self.expectations_dict = expectations 47 self.expectations_dict = expectations
45 self.extra_columns_dict = extra_columns 48 self.extra_columns_dict = extra_columns
46 if imageA_relative_url == imageB_relative_url: 49 if imageA_relative_url == imageB_relative_url:
rmistry 2014/02/26 17:35:39 The following is more readable to me, WDYT? if no
epoger 2014/02/26 17:56:20 Agreed! Done. P.S. There was a typo in your sugg
47 self.diff_record = None 50 self.diff_record = None
51 elif not imageA_relative_url:
52 self.diff_record = None
53 elif not imageB_relative_url:
54 self.diff_record = None
48 else: 55 else:
49 # TODO(epoger): Rather than blocking until image_diff_db can read in 56 # TODO(epoger): Rather than blocking until image_diff_db can read in
50 # the image pair and generate diffs, it would be better to do it 57 # the image pair and generate diffs, it would be better to do it
51 # asynchronously: tell image_diff_db to download a bunch of file pairs, 58 # asynchronously: tell image_diff_db to download a bunch of file pairs,
52 # and only block later if we're still waiting for diff_records to come 59 # and only block later if we're still waiting for diff_records to come
53 # back. 60 # back.
54 image_diff_db.add_image_pair( 61 image_diff_db.add_image_pair(
55 expected_image_locator=imageA_relative_url, 62 expected_image_locator=imageA_relative_url,
56 expected_image_url=posixpath.join(base_url, imageA_relative_url), 63 expected_image_url=posixpath.join(base_url, imageA_relative_url),
57 actual_image_locator=imageB_relative_url, 64 actual_image_locator=imageB_relative_url,
(...skipping 14 matching lines...) Expand all
72 if self.expectations_dict: 79 if self.expectations_dict:
73 asdict[KEY__EXPECTATIONS_DATA] = self.expectations_dict 80 asdict[KEY__EXPECTATIONS_DATA] = self.expectations_dict
74 if self.extra_columns_dict: 81 if self.extra_columns_dict:
75 asdict[KEY__EXTRA_COLUMN_VALUES] = self.extra_columns_dict 82 asdict[KEY__EXTRA_COLUMN_VALUES] = self.extra_columns_dict
76 if self.diff_record and (self.diff_record.get_num_pixels_differing() > 0): 83 if self.diff_record and (self.diff_record.get_num_pixels_differing() > 0):
77 asdict[KEY__IS_DIFFERENT] = True 84 asdict[KEY__IS_DIFFERENT] = True
78 asdict[KEY__DIFFERENCE_DATA] = self.diff_record.as_dict() 85 asdict[KEY__DIFFERENCE_DATA] = self.diff_record.as_dict()
79 else: 86 else:
80 asdict[KEY__IS_DIFFERENT] = False 87 asdict[KEY__IS_DIFFERENT] = False
81 return asdict 88 return asdict
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698