4 Copyright 2014 Google Inc.
6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file.
12 # System-level imports
22 IMG_URL_BASE = ('http://chromium-skia-gm.commondatastorage.googleapis.com/'
23 'gm/bitmap-64bitMD5/')
26 class ImagePairTest(unittest.TestCase):
29 self.temp_dir = tempfile.mkdtemp()
33 shutil.rmtree(self.temp_dir)
35 def shortDescription(self):
36 """Tells unittest framework to not print docstrings for test cases."""
39 def test_endToEnd(self):
40 """Tests ImagePair, using a real ImageDiffDB to download real images.
42 TODO(epoger): Either in addition to or instead of this end-to-end test,
43 we should perform some tests using either:
44 1. a mock ImageDiffDB, or
45 2. a real ImageDiffDB that doesn't hit Google Storage looking for input
46 image files (maybe a file:// IMG_URL_BASE)
48 # params for each self-test:
51 # 0. imageA_relative_URL
52 # 1. imageB_relative_URL
53 # 2. expectations dict
54 # 3. extra_columns dict
56 # 4. expected result of ImagePair.as_dict()
60 'arcofzorro/16206093933823793653.png',
61 'arcofzorro/16206093933823793653.png',
64 'builder': 'MyBuilder',
70 'builder': 'MyBuilder',
73 'imageAUrl': 'arcofzorro/16206093933823793653.png',
74 'imageBUrl': 'arcofzorro/16206093933823793653.png',
81 'arcofzorro/16206093933823793653.png',
82 'arcofzorro/13786535001616823825.png',
88 'maxDiffPerChannel': [255, 255, 247],
89 'numDifferingPixels': 662,
90 'percentDifferingPixels': 0.0662,
91 'perceptualDifference': 0.06620300000000157,
92 'diffUrl': 'arcofzorro_16206093933823793653_png_png-vs-' +
93 'arcofzorro_13786535001616823825_png_png.png',
94 'whiteDiffUrl': 'arcofzorro_16206093933823793653_png_png' +
95 '-vs-arcofzorro_13786535001616823825_png_png.png',
97 'imageAUrl': 'arcofzorro/16206093933823793653.png',
98 'imageBUrl': 'arcofzorro/13786535001616823825.png',
105 'gradients_degenerate_2pt/10552995703607727960.png',
106 'gradients_degenerate_2pt/11198253335583713230.png',
108 'ignoreFailure': True,
109 'bugs': [1001, 1002],
112 'builder': 'MyBuilder',
118 'maxDiffPerChannel': [255, 0, 255],
119 'numDifferingPixels': 102400,
120 'percentDifferingPixels': 100.00,
121 'perceptualDifference': 100.00,
122 'diffUrl': 'gradients_degenerate_2pt_10552995703607727960' +
123 '_png_png-vs-gradients_degenerate_2pt_' +
124 '11198253335583713230_png_png.png',
125 'whiteDiffUrl': 'gradients_degenerate_2pt_' +
126 '10552995703607727960_png_png-vs-' +
127 'gradients_degenerate_2pt_11198253335583713230' +
131 'bugs': [1001, 1002],
132 'ignoreFailure': True,
135 'builder': 'MyBuilder',
139 'gradients_degenerate_2pt/10552995703607727960.png',
141 'gradients_degenerate_2pt/11198253335583713230.png',
146 # Test fix for http://skbug.com/2368 -- how do we handle an ImagePair
147 # missing one of its images?
150 'arcofzorro/16206093933823793653.png',
151 'nonexistentDir/111111.png',
153 'ignoreFailure': True,
154 'bugs': [1001, 1002],
157 'builder': 'MyBuilder',
163 'bugs': [1001, 1002],
164 'ignoreFailure': True,
167 'builder': 'MyBuilder',
170 'imageAUrl': 'arcofzorro/16206093933823793653.png',
171 'imageBUrl': 'nonexistentDir/111111.png',
176 # One of the two images is missing, but download_all_images=True so we
177 # should download it anyway.
181 'arcofzorro/13786535001616823825.png',
187 'imageBUrl': 'arcofzorro/13786535001616823825.png',
194 db = imagediffdb.ImageDiffDB(self.temp_dir)
195 for selftest in selftests:
196 image_pair = imagepair.ImagePair(
198 imageA_base_url=IMG_URL_BASE,
199 imageB_base_url=IMG_URL_BASE,
200 imageA_relative_url=selftest[0],
201 imageB_relative_url=selftest[1],
202 expectations=selftest[2],
203 extra_columns=selftest[3],
204 download_all_images=True)
205 self.assertEqual(image_pair.as_dict(), selftest[4])
209 suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairTest)
210 unittest.TextTestRunner(verbosity=2).run(suite)
213 if __name__ == '__main__':