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