OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 """ | 3 """ |
4 Copyright 2013 Google Inc. | 4 Copyright 2013 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 Test imagediffdb.py | 9 Test imagediffdb.py |
10 """ | 10 """ |
11 | 11 |
12 # System-level imports | 12 # System-level imports |
13 import logging | 13 import logging |
14 import shutil | 14 import shutil |
15 import tempfile | 15 import tempfile |
16 import unittest | 16 import unittest |
17 | 17 |
18 # Local imports | 18 # Local imports |
19 import imagediffdb | 19 import imagediffdb |
20 | 20 |
21 | 21 |
22 IMG_URL_BASE = 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm/bitm
ap-64bitMD5/' | 22 IMG_URL_BASE = ('http://chromium-skia-gm.commondatastorage.googleapis.com/gm/' |
| 23 'bitmap-64bitMD5/') |
23 | 24 |
24 | 25 |
25 class ImageDiffDbTest(unittest.TestCase): | 26 class ImageDiffDbTest(unittest.TestCase): |
26 | 27 |
27 def setUp(self): | 28 def setUp(self): |
28 self._temp_dir = tempfile.mkdtemp() | 29 self._temp_dir = tempfile.mkdtemp() |
29 self.maxDiff = None | 30 self.maxDiff = None |
30 | 31 |
31 def tearDown(self): | 32 def tearDown(self): |
32 shutil.rmtree(self._temp_dir) | 33 shutil.rmtree(self._temp_dir) |
(...skipping 16 matching lines...) Expand all Loading... |
49 TODO(epoger): Instead of hitting Google Storage, we should read image | 50 TODO(epoger): Instead of hitting Google Storage, we should read image |
50 files from local disk using a file:// IMG_URL_BASE. | 51 files from local disk using a file:// IMG_URL_BASE. |
51 """ | 52 """ |
52 # params for each self-test: | 53 # params for each self-test: |
53 # 0. expected image locator | 54 # 0. expected image locator |
54 # 1. expected image URL | 55 # 1. expected image URL |
55 # 2. actual image locator | 56 # 2. actual image locator |
56 # 3. actual image URL | 57 # 3. actual image URL |
57 # 4. expected percent_pixels_differing (as a string, to 4 decimal places) | 58 # 4. expected percent_pixels_differing (as a string, to 4 decimal places) |
58 # 5. expected weighted_diff_measure (as a string, to 4 decimal places) | 59 # 5. expected weighted_diff_measure (as a string, to 4 decimal places) |
59 # 6. expected max_diff_per_channel | 60 # 6. expected perceptual difference (as a string, to 4 decimal places) |
| 61 # 7. expected max_diff_per_channel |
60 selftests = [ | 62 selftests = [ |
61 [ | 63 [ |
62 'arcofzorro/16206093933823793653', | 64 'arcofzorro/16206093933823793653', |
63 IMG_URL_BASE + 'arcofzorro/16206093933823793653.png', | 65 IMG_URL_BASE + 'arcofzorro/16206093933823793653.png', |
64 'arcofzorro/13786535001616823825', | 66 'arcofzorro/13786535001616823825', |
65 IMG_URL_BASE + 'arcofzorro/13786535001616823825.png', | 67 IMG_URL_BASE + 'arcofzorro/13786535001616823825.png', |
66 '0.0662', '0.0113', [255, 255, 247], | 68 '0.0662', '0.0113', '0.0662', [255, 255, 247], |
67 ], | 69 ], |
68 [ | 70 [ |
69 'gradients_degenerate_2pt/10552995703607727960', | 71 'gradients_degenerate_2pt/10552995703607727960', |
70 IMG_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png', | 72 IMG_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png', |
71 'gradients_degenerate_2pt/11198253335583713230', | 73 'gradients_degenerate_2pt/11198253335583713230', |
72 IMG_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png', | 74 IMG_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png', |
73 '100.0000', '66.6667', [255, 0, 255], | 75 '100.0000', '66.6667', '100.0000', [255, 0, 255], |
74 ], | 76 ], |
75 ] | 77 ] |
76 | 78 |
77 # Add all image pairs to the database | 79 # Add all image pairs to the database |
78 db = imagediffdb.ImageDiffDB(self._temp_dir) | 80 db = imagediffdb.ImageDiffDB(self._temp_dir) |
79 for selftest in selftests: | 81 for selftest in selftests: |
80 retval = db.add_image_pair( | 82 retval = db.add_image_pair( |
81 expected_image_locator=selftest[0], expected_image_url=selftest[1], | 83 expected_image_locator=selftest[0], expected_image_url=selftest[1], |
82 actual_image_locator=selftest[2], actual_image_url=selftest[3]) | 84 actual_image_locator=selftest[2], actual_image_url=selftest[3]) |
83 | 85 |
84 # Fetch each image pair from the database | 86 # Fetch each image pair from the database |
85 for selftest in selftests: | 87 for selftest in selftests: |
86 record = db.get_diff_record(expected_image_locator=selftest[0], | 88 record = db.get_diff_record(expected_image_locator=selftest[0], |
87 actual_image_locator=selftest[2]) | 89 actual_image_locator=selftest[2]) |
88 self.assertEqual('%.4f' % record.get_percent_pixels_differing(), | 90 self.assertEqual('%.4f' % record.get_percent_pixels_differing(), |
89 selftest[4]) | 91 selftest[4]) |
90 self.assertEqual('%.4f' % record.get_weighted_diff_measure(), selftest[5]) | 92 self.assertEqual('%.4f' % record.get_weighted_diff_measure(), selftest[5]) |
91 self.assertEqual(record.get_max_diff_per_channel(), selftest[6]) | 93 self.assertEqual('%.4f' % record.get_perceptual_difference(), selftest[6]) |
| 94 self.assertEqual(record.get_max_diff_per_channel(), selftest[7]) |
92 | 95 |
93 | 96 |
94 def main(): | 97 def main(): |
95 suite = unittest.TestLoader().loadTestsFromTestCase(ImageDiffDbTest) | 98 suite = unittest.TestLoader().loadTestsFromTestCase(ImageDiffDbTest) |
96 unittest.TextTestRunner(verbosity=2).run(suite) | 99 unittest.TextTestRunner(verbosity=2).run(suite) |
97 | 100 |
98 | 101 |
99 if __name__ == '__main__': | 102 if __name__ == '__main__': |
100 main() | 103 main() |
OLD | NEW |