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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 def main(): | 23 def main(): |
24 logging.basicConfig(level=logging.INFO) | 24 logging.basicConfig(level=logging.INFO) |
25 | 25 |
26 # params for each self-test: | 26 # params for each self-test: |
27 # 0. expected image locator | 27 # 0. expected image locator |
28 # 1. expected image URL | 28 # 1. expected image URL |
29 # 2. actual image locator | 29 # 2. actual image locator |
30 # 3. actual image URL | 30 # 3. actual image URL |
31 # 4. expected percent_pixels_differing (as a string, to 4 decimal places) | 31 # 4. expected percent_pixels_differing (as a string, to 4 decimal places) |
32 # 5. expected weighted_diff_measure (as a string, to 4 decimal places) | 32 # 5. expected weighted_diff_measure (as a string, to 4 decimal places) |
| 33 # 6. expected max_diff_per_channel |
33 selftests = [ | 34 selftests = [ |
34 ['16206093933823793653', | 35 [ |
35 IMAGE_URL_BASE + 'arcofzorro/16206093933823793653.png', | 36 '16206093933823793653', |
36 '13786535001616823825', | 37 IMAGE_URL_BASE + 'arcofzorro/16206093933823793653.png', |
37 IMAGE_URL_BASE + 'arcofzorro/13786535001616823825.png', | 38 '13786535001616823825', |
38 '0.0653', '0.0113'], | 39 IMAGE_URL_BASE + 'arcofzorro/13786535001616823825.png', |
| 40 '0.0662', '0.0113', [255, 255, 247], |
| 41 ], |
| 42 [ |
| 43 '10552995703607727960', |
| 44 IMAGE_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png', |
| 45 '11198253335583713230', |
| 46 IMAGE_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png', |
| 47 '100.0000', '66.6667', [255, 0, 255], |
| 48 ], |
39 ] | 49 ] |
40 | 50 |
41 # Add all image pairs to the database | 51 # Add all image pairs to the database |
42 db = imagediffdb.ImageDiffDB('/tmp/ImageDiffDB') | 52 db = imagediffdb.ImageDiffDB('/tmp/ImageDiffDB') |
43 for selftest in selftests: | 53 for selftest in selftests: |
44 retval = db.add_image_pair( | 54 retval = db.add_image_pair( |
45 expected_image_locator=selftest[0], expected_image_url=selftest[1], | 55 expected_image_locator=selftest[0], expected_image_url=selftest[1], |
46 actual_image_locator=selftest[2], actual_image_url=selftest[3]) | 56 actual_image_locator=selftest[2], actual_image_url=selftest[3]) |
47 | 57 |
48 # Fetch each image pair from the database | 58 # Fetch each image pair from the database |
49 for selftest in selftests: | 59 for selftest in selftests: |
50 record = db.get_diff_record(expected_image_locator=selftest[0], | 60 record = db.get_diff_record(expected_image_locator=selftest[0], |
51 actual_image_locator=selftest[2]) | 61 actual_image_locator=selftest[2]) |
52 assert (('%.4f' % record.get_percent_pixels_differing()) == selftest[4]) | 62 assert (('%.4f' % record.get_percent_pixels_differing()) == selftest[4]) |
53 assert (('%.4f' % record.get_weighted_diff_measure()) == selftest[5]) | 63 assert (('%.4f' % record.get_weighted_diff_measure()) == selftest[5]) |
54 | 64 assert (record.get_max_diff_per_channel() == selftest[6]) |
55 logging.info("Self-test completed successfully!") | 65 logging.info("Self-test completed successfully!") |
56 | 66 |
57 | 67 |
58 if __name__ == '__main__': | 68 if __name__ == '__main__': |
59 main() | 69 main() |
OLD | NEW |