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

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

Issue 139343018: rebaseline_server: create ImagePairSet-- holds a number of ImagePairs to examine (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
(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 Test imagepairset.py
10 """
11
12 # System-level imports
13 import unittest
14
15 # Local imports
16 import column
17 import imagepair
18 import imagepairset
19
20
21 BASE_URL_1 = 'http://base/url/1'
22 BASE_URL_2 = 'http://base/url/2'
23 IMAGEPAIR_1_AS_DICT = {
24 imagepair.KEY__EXTRA_COLUMN_VALUES: {
25 'builder': 'MyBuilder',
26 'test': 'test1',
27 },
28 imagepair.KEY__IMAGE_A_URL: 'test1/1111.png',
29 imagepair.KEY__IMAGE_B_URL: 'test1/1111.png',
30 imagepair.KEY__IS_DIFFERENT: False,
31 }
32 IMAGEPAIR_2_AS_DICT = {
33 imagepair.KEY__DIFFERENCE_DATA: {
34 'maxDiffPerChannel': [1, 2, 3],
35 'numDifferingPixels': 111,
36 'percentDifferingPixels': 22.222,
37 'weightedDiffMeasure': 33.333,
38 },
39 imagepair.KEY__EXTRA_COLUMN_VALUES: {
40 'builder': 'MyBuilder',
41 'test': 'test2',
42 },
43 imagepair.KEY__IMAGE_A_URL: 'test2/2222.png',
44 imagepair.KEY__IMAGE_B_URL: 'test2/22223.png',
45 imagepair.KEY__IS_DIFFERENT: True,
46 }
47 IMAGEPAIR_3_AS_DICT = {
48 imagepair.KEY__DIFFERENCE_DATA: {
49 'maxDiffPerChannel': [4, 5, 6],
50 'numDifferingPixels': 111,
51 'percentDifferingPixels': 44.444,
52 'weightedDiffMeasure': 33.333,
53 },
54 imagepair.KEY__EXPECTATIONS_DATA: {
55 'bugs': [1001, 1002],
56 'ignoreFailure': True,
57 },
58 imagepair.KEY__EXTRA_COLUMN_VALUES: {
59 'builder': 'MyBuilder',
60 'test': 'test3',
61 },
62 imagepair.KEY__IMAGE_A_URL: 'test3/3333.png',
63 imagepair.KEY__IMAGE_B_URL: 'test3/33334.png',
64 imagepair.KEY__IS_DIFFERENT: True,
65 }
66 SET_A_DESCRIPTION = 'expectations'
67 SET_B_DESCRIPTION = 'actuals'
68
69
70 class ImagePairSetTest(unittest.TestCase):
71
72 def setUp(self):
73 self.maxDiff = None # do not truncate diffs when tests fail
74
75 def shortDescription(self):
76 """Tell unittest framework to not print docstrings for test cases."""
77 return None
78
79 def test_success(self):
80 """Assemble some ImagePairs into an ImagePairSet, and validate results."""
81 image_pairs = [
82 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT),
83 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT),
84 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_3_AS_DICT),
85 ]
86 expected_imageset_dict = {
87 'columnHeaders': {
88 'builder': {
89 'headerText': 'builder',
90 'isFilterable': True,
91 'isSortable': True,
92 'valuesAndCounts': {
93 'MyBuilder': 3
94 },
95 },
96 'test': {
97 'headerText': 'which GM test',
98 'headerUrl': 'http://learn/about/gm/tests',
99 'isFilterable': True,
100 'isSortable': False,
101 },
102 },
103 'imagePairs': [
104 IMAGEPAIR_1_AS_DICT,
105 IMAGEPAIR_2_AS_DICT,
106 IMAGEPAIR_3_AS_DICT,
107 ],
108 'imageSets': [
109 {
110 'baseUrl': BASE_URL_1,
111 'description': SET_A_DESCRIPTION,
112 },
113 {
114 'baseUrl': BASE_URL_1,
115 'description': SET_B_DESCRIPTION,
116 },
117 ],
118 }
119
120 image_pair_set = imagepairset.ImagePairSet(
121 descriptions=(SET_A_DESCRIPTION, SET_B_DESCRIPTION))
122 for image_pair in image_pairs:
123 image_pair_set.add_image_pair(image_pair)
124 # The 'builder' column header uses the default settings,
125 # but the 'test' column header has manual adjustments.
126 image_pair_set.set_column_header_factory(
127 'test',
128 column.ColumnHeaderFactory(
129 header_text='which GM test',
130 header_url='http://learn/about/gm/tests',
131 is_filterable=True,
132 is_sortable=False,
133 include_values_and_counts=False))
134 self.assertEqual(image_pair_set.as_dict(), expected_imageset_dict)
135
136 def test_mismatched_base_url(self):
137 """Confirm that mismatched base_urls will cause an exception."""
138 image_pair_set = imagepairset.ImagePairSet()
139 image_pair_set.add_image_pair(
140 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT))
141 image_pair_set.add_image_pair(
142 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT))
143 with self.assertRaises(Exception):
144 image_pair_set.add_image_pair(
145 MockImagePair(base_url=BASE_URL_2,
146 dict_to_return=IMAGEPAIR_3_AS_DICT))
147
148
149 class MockImagePair(object):
150 """
151 Mock ImagePair object, which will return canned results.
152 """
153 def __init__(self, base_url, dict_to_return):
154 """
155 Args:
156 base_url: base_url attribute for this object
157 dict_to_return: dictionary to return from as_dict()
158 """
159 self.base_url = base_url
160 self.extra_columns_dict = dict_to_return.get(
161 imagepair.KEY__EXTRA_COLUMN_VALUES, None)
162 self._dict_to_return = dict_to_return
163
164 def as_dict(self):
165 return self._dict_to_return
166
167
168 def main():
169 suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairSetTest)
170 unittest.TextTestRunner(verbosity=2).run(suite)
171
172
173 if __name__ == '__main__':
174 main()
OLDNEW
« gm/rebaseline_server/imagepairset.py ('K') | « gm/rebaseline_server/imagepairset.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698