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

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: nite nite, nits! 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 """Tells unittest framework to not print docstrings for test cases.
77 """
78 return None
79
80 def test_success(self):
81 """Assembles some ImagePairs into an ImagePairSet, and validates results.
82 """
83 image_pairs = [
84 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT),
85 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT),
86 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_3_AS_DICT),
87 ]
88 expected_imageset_dict = {
89 'columnHeaders': {
90 'builder': {
91 'headerText': 'builder',
92 'isFilterable': True,
93 'isSortable': True,
94 'valuesAndCounts': {
95 'MyBuilder': 3
96 },
97 },
98 'test': {
99 'headerText': 'which GM test',
100 'headerUrl': 'http://learn/about/gm/tests',
101 'isFilterable': True,
102 'isSortable': False,
103 },
104 },
105 'imagePairs': [
106 IMAGEPAIR_1_AS_DICT,
107 IMAGEPAIR_2_AS_DICT,
108 IMAGEPAIR_3_AS_DICT,
109 ],
110 'imageSets': [
111 {
112 'baseUrl': BASE_URL_1,
113 'description': SET_A_DESCRIPTION,
114 },
115 {
116 'baseUrl': BASE_URL_1,
117 'description': SET_B_DESCRIPTION,
118 },
119 ],
120 }
121
122 image_pair_set = imagepairset.ImagePairSet(
123 descriptions=(SET_A_DESCRIPTION, SET_B_DESCRIPTION))
124 for image_pair in image_pairs:
125 image_pair_set.add_image_pair(image_pair)
126 # The 'builder' column header uses the default settings,
127 # but the 'test' column header has manual adjustments.
128 image_pair_set.set_column_header_factory(
129 'test',
130 column.ColumnHeaderFactory(
131 header_text='which GM test',
132 header_url='http://learn/about/gm/tests',
133 is_filterable=True,
134 is_sortable=False,
135 include_values_and_counts=False))
136 self.assertEqual(image_pair_set.as_dict(), expected_imageset_dict)
137
138 def test_mismatched_base_url(self):
139 """Confirms that mismatched base_urls will cause an exception.
140 """
141 image_pair_set = imagepairset.ImagePairSet()
142 image_pair_set.add_image_pair(
143 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT))
144 image_pair_set.add_image_pair(
145 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT))
146 with self.assertRaises(Exception):
147 image_pair_set.add_image_pair(
148 MockImagePair(base_url=BASE_URL_2,
149 dict_to_return=IMAGEPAIR_3_AS_DICT))
150
151
152 class MockImagePair(object):
153 """Mock ImagePair object, which will return canned results.
154 """
155 def __init__(self, base_url, dict_to_return):
156 """
157 Args:
158 base_url: base_url attribute for this object
159 dict_to_return: dictionary to return from as_dict()
160 """
161 self.base_url = base_url
162 self.extra_columns_dict = dict_to_return.get(
163 imagepair.KEY__EXTRA_COLUMN_VALUES, None)
164 self._dict_to_return = dict_to_return
165
166 def as_dict(self):
167 return self._dict_to_return
168
169
170 def main():
171 suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairSetTest)
172 unittest.TextTestRunner(verbosity=2).run(suite)
173
174
175 if __name__ == '__main__':
176 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