Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 """ | |
| 4 Copyright 2013 Google Inc. | |
| 5 | |
| 6 Use of this source code is governed by a BSD-style license that can be | |
| 7 found in the LICENSE file. | |
| 8 | |
| 9 Test imagediffdb.py | |
|
epoger
2013/11/07 21:11:54
Moved the self-test code into this new file.
jcgregorio
2013/11/08 02:02:29
Please rename to imagediffdb_test.py. A file image
epoger
2013/11/08 16:11:28
Done.
| |
| 10 """ | |
| 11 | |
| 12 # System-level imports | |
| 13 import logging | |
| 14 | |
| 15 # Local imports | |
| 16 import imagediffdb | |
| 17 | |
| 18 | |
| 19 IMAGE_URL_BASE = 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm/bi tmap-64bitMD5/' | |
| 20 | |
| 21 def main(): | |
| 22 logging.basicConfig(level=logging.INFO) | |
| 23 | |
| 24 # params for each self-test: | |
| 25 # 0. expected image locator | |
| 26 # 1. expected image URL | |
| 27 # 2. actual image locator | |
| 28 # 3. actual image URL | |
| 29 # 4. expected percent_pixels_differing (as a string, to 4 decimal places) | |
| 30 # 5. expected weighted_diff_measure (as a string, to 4 decimal places) | |
| 31 selftests = [ | |
| 32 ['16206093933823793653', | |
| 33 IMAGE_URL_BASE + 'arcofzorro/16206093933823793653.png', | |
| 34 '13786535001616823825', | |
| 35 IMAGE_URL_BASE + 'arcofzorro/13786535001616823825.png', | |
| 36 '0.0653', '0.0113'], | |
| 37 ] | |
| 38 | |
| 39 # Add all image pairs to the database | |
| 40 db = imagediffdb.ImageDiffDB('/tmp/ImageDiffDB') | |
| 41 for selftest in selftests: | |
| 42 retval = db.add_image_pair( | |
| 43 expected_image_locator=selftest[0], expected_image_url=selftest[1], | |
| 44 actual_image_locator=selftest[2], actual_image_url=selftest[3]) | |
| 45 | |
| 46 # Fetch each image pair from the database | |
| 47 for selftest in selftests: | |
|
jcgregorio
2013/11/08 02:02:29
Either convert tests to use Python's unittest fram
epoger
2013/11/08 16:11:28
Added a TODO at the top of the renamed file.
| |
| 48 record = db.get_diff_record(expected_image_locator=selftest[0], | |
| 49 actual_image_locator=selftest[2]) | |
| 50 assert (('%.4f' % record.get_percent_pixels_differing()) == selftest[4]) | |
| 51 assert (('%.4f' % record.get_weighted_diff_measure()) == selftest[5]) | |
| 52 | |
| 53 logging.info("Self-test completed successfully!") | |
| 54 | |
| 55 | |
| 56 if __name__ == '__main__': | |
| 57 main() | |
| OLD | NEW |