Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 """ | |
| 4 Copyright 2014 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 imagepair.py | |
| 10 """ | |
| 11 | |
| 12 # System-level imports | |
| 13 import shutil | |
| 14 import tempfile | |
| 15 import unittest | |
| 16 | |
| 17 # Local imports | |
| 18 import imagediffdb | |
| 19 import imagepair | |
| 20 | |
| 21 | |
| 22 IMG_URL_BASE = 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm/bitm ap-64bitMD5/' | |
| 23 | |
| 24 | |
| 25 class ImagePairTest(unittest.TestCase): | |
| 26 | |
| 27 def setUp(self): | |
| 28 self._temp_dir = tempfile.mkdtemp() | |
| 29 self.maxDiff = None | |
|
epoger
2014/02/07 21:36:17
don't truncate the diffs displayed by unittest in
| |
| 30 | |
| 31 def tearDown(self): | |
| 32 shutil.rmtree(self._temp_dir) | |
| 33 | |
| 34 def shortDescription(self): | |
| 35 """Tell unittest framework to not print docstrings for test cases.""" | |
| 36 return None | |
| 37 | |
| 38 def test_endToEnd(self): | |
| 39 """Test ImagePair, using a real ImageDiffDB to download real images. | |
| 40 | |
| 41 TODO(epoger): Either in addition to or instead of this end-to-end test, | |
|
epoger
2014/02/07 21:36:17
If you think it's important, I can tackle this bef
rmistry
2014/02/10 17:34:54
TODO is fine with me
| |
| 42 we should perform some tests using either: | |
| 43 1. a mock ImageDiffDB, or | |
| 44 2. a real ImageDiffDB that doesn't hit Google Storage looking for input | |
| 45 image files (maybe a file:// IMG_URL_BASE) | |
| 46 """ | |
| 47 # params for each self-test: | |
| 48 # | |
| 49 # inputs: | |
| 50 # 0. imageA_relative_URL | |
| 51 # 1. imageB_relative_URL | |
| 52 # 2. expectations dict | |
| 53 # 3. extra_columns dict | |
| 54 # expected output: | |
| 55 # 4. expected result of ImagePair.as_dict() | |
| 56 selftests = [ | |
| 57 [ | |
| 58 # inputs: | |
| 59 'arcofzorro/16206093933823793653.png', | |
| 60 'arcofzorro/16206093933823793653.png', | |
| 61 None, | |
| 62 { | |
| 63 'builder': 'MyBuilder', | |
| 64 'test': 'MyTest', | |
| 65 }, | |
| 66 # expected output: | |
| 67 { | |
| 68 'extraColumnValues': { | |
| 69 'builder': 'MyBuilder', | |
| 70 'test': 'MyTest', | |
| 71 }, | |
| 72 'imageAUrl': 'arcofzorro/16206093933823793653.png', | |
| 73 'imageBUrl': 'arcofzorro/16206093933823793653.png', | |
| 74 'isDifferent': False, | |
| 75 }, | |
| 76 ], | |
| 77 | |
| 78 [ | |
| 79 # inputs: | |
| 80 'arcofzorro/16206093933823793653.png', | |
| 81 'arcofzorro/13786535001616823825.png', | |
| 82 None, | |
| 83 None, | |
| 84 # expected output: | |
| 85 { | |
| 86 'differenceData': { | |
| 87 'maxDiffPerChannel': [255, 255, 247], | |
| 88 'numDifferingPixels': 662, | |
| 89 'percentDifferingPixels': 0.0662, | |
| 90 'weightedDiffMeasure': 0.01127756555171088, | |
| 91 }, | |
| 92 'imageAUrl': 'arcofzorro/16206093933823793653.png', | |
| 93 'imageBUrl': 'arcofzorro/13786535001616823825.png', | |
| 94 'isDifferent': True, | |
| 95 }, | |
| 96 ], | |
| 97 | |
| 98 [ | |
| 99 # inputs: | |
| 100 'gradients_degenerate_2pt/10552995703607727960.png', | |
| 101 'gradients_degenerate_2pt/11198253335583713230.png', | |
| 102 { | |
| 103 'ignoreFailure': True, | |
| 104 'bugs': [1001, 1002], | |
| 105 }, | |
| 106 { | |
| 107 'builder': 'MyBuilder', | |
| 108 'test': 'MyTest', | |
| 109 }, | |
| 110 # expected output: | |
| 111 { | |
| 112 'differenceData': { | |
| 113 'maxDiffPerChannel': [255, 0, 255], | |
| 114 'numDifferingPixels': 102400, | |
| 115 'percentDifferingPixels': 100.00, | |
| 116 'weightedDiffMeasure': 66.66666666666667, | |
| 117 }, | |
| 118 'expectationsData': { | |
| 119 'bugs': [1001, 1002], | |
| 120 'ignoreFailure': True, | |
| 121 }, | |
| 122 'extraColumnValues': { | |
| 123 'builder': 'MyBuilder', | |
| 124 'test': 'MyTest', | |
| 125 }, | |
| 126 'imageAUrl': 'gradients_degenerate_2pt/10552995703607727960.png' , | |
|
epoger
2014/02/07 21:36:17
yes, it's just over 80 chars, but I think wrapping
rmistry
2014/02/10 17:34:54
I dont think it would be terrible to move the valu
epoger
2014/02/10 18:01:16
Oh, all right. :-)
| |
| 127 'imageBUrl': 'gradients_degenerate_2pt/11198253335583713230.png' , | |
| 128 'isDifferent': True, | |
| 129 }, | |
| 130 ], | |
| 131 ] | |
| 132 | |
| 133 db = imagediffdb.ImageDiffDB(self._temp_dir) | |
| 134 for selftest in selftests: | |
| 135 image_pair = imagepair.ImagePair( | |
| 136 image_diff_db=db, | |
| 137 base_url=IMG_URL_BASE, | |
| 138 imageA_relative_url=selftest[0], | |
| 139 imageB_relative_url=selftest[1], | |
| 140 expectations=selftest[2], | |
| 141 extra_columns=selftest[3]) | |
| 142 self.assertEqual(image_pair.as_dict(), selftest[4]) | |
| 143 | |
| 144 | |
| 145 def main(): | |
| 146 suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairTest) | |
| 147 unittest.TextTestRunner(verbosity=2).run(suite) | |
| 148 | |
| 149 | |
| 150 if __name__ == '__main__': | |
| 151 main() | |
| OLD | NEW |