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,
93 'imageAUrl': 'arcofzorro/16206093933823793653.png',
94 'imageBUrl': 'arcofzorro/13786535001616823825.png',
101 'gradients_degenerate_2pt/10552995703607727960.png',
102 'gradients_degenerate_2pt/11198253335583713230.png',
104 'ignoreFailure': True,
105 'bugs': [1001, 1002],
108 'builder': 'MyBuilder',
114 'maxDiffPerChannel': [255, 0, 255],
115 'numDifferingPixels': 102400,
116 'percentDifferingPixels': 100.00,
117 'perceptualDifference': 100.00,
120 'bugs': [1001, 1002],
121 'ignoreFailure': True,
124 'builder': 'MyBuilder',
128 'gradients_degenerate_2pt/10552995703607727960.png',
130 'gradients_degenerate_2pt/11198253335583713230.png',
135 # Test fix for http://skbug.com/2368 -- how do we handle an ImagePair
136 # missing one of its images?
139 'arcofzorro/16206093933823793653.png',
140 'nonexistentDir/111111.png',
142 'ignoreFailure': True,
143 'bugs': [1001, 1002],
146 'builder': 'MyBuilder',
152 'bugs': [1001, 1002],
153 'ignoreFailure': True,
156 'builder': 'MyBuilder',
159 'imageAUrl': 'arcofzorro/16206093933823793653.png',
160 'imageBUrl': 'nonexistentDir/111111.png',
165 # One of the two images is missing, but download_all_images=True so we
166 # should download it anyway.
170 'arcofzorro/13786535001616823825.png',
176 'imageBUrl': 'arcofzorro/13786535001616823825.png',
183 db = imagediffdb.ImageDiffDB(self.temp_dir)
184 for selftest in selftests:
185 image_pair = imagepair.ImagePair(
187 base_url=IMG_URL_BASE,
188 imageA_relative_url=selftest[0],
189 imageB_relative_url=selftest[1],
190 expectations=selftest[2],
191 extra_columns=selftest[3],
192 download_all_images=True)
193 self.assertEqual(image_pair.as_dict(), selftest[4])
197 suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairTest)
198 unittest.TextTestRunner(verbosity=2).run(suite)
201 if __name__ == '__main__':