commit-bot@chromium.org | 9985ef5 | 2014-02-10 18:19:30 +0000 | [diff] [blame] | 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/bitmap-64bitMD5/' |
| 23 | |
| 24 | |
| 25 | class ImagePairTest(unittest.TestCase): |
| 26 | |
| 27 | def setUp(self): |
| 28 | self._temp_dir = tempfile.mkdtemp() |
| 29 | self.maxDiff = None |
| 30 | |
| 31 | def tearDown(self): |
| 32 | shutil.rmtree(self._temp_dir) |
| 33 | |
| 34 | def shortDescription(self): |
commit-bot@chromium.org | 536b15f | 2014-02-13 17:17:05 +0000 | [diff] [blame] | 35 | """Tells unittest framework to not print docstrings for test cases.""" |
commit-bot@chromium.org | 9985ef5 | 2014-02-10 18:19:30 +0000 | [diff] [blame] | 36 | return None |
| 37 | |
| 38 | def test_endToEnd(self): |
commit-bot@chromium.org | 536b15f | 2014-02-13 17:17:05 +0000 | [diff] [blame] | 39 | """Tests ImagePair, using a real ImageDiffDB to download real images. |
commit-bot@chromium.org | 9985ef5 | 2014-02-10 18:19:30 +0000 | [diff] [blame] | 40 | |
| 41 | TODO(epoger): Either in addition to or instead of this end-to-end test, |
| 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 | { |
commit-bot@chromium.org | 536b15f | 2014-02-13 17:17:05 +0000 | [diff] [blame] | 68 | 'extraColumns': { |
commit-bot@chromium.org | 9985ef5 | 2014-02-10 18:19:30 +0000 | [diff] [blame] | 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, |
commit-bot@chromium.org | 16f4180 | 2014-02-26 19:05:20 +0000 | [diff] [blame] | 90 | 'perceptualDifference': 0.06620000000000914, |
commit-bot@chromium.org | 9985ef5 | 2014-02-10 18:19:30 +0000 | [diff] [blame] | 91 | 'weightedDiffMeasure': 0.01127756555171088, |
| 92 | }, |
| 93 | 'imageAUrl': 'arcofzorro/16206093933823793653.png', |
| 94 | 'imageBUrl': 'arcofzorro/13786535001616823825.png', |
| 95 | 'isDifferent': True, |
| 96 | }, |
| 97 | ], |
| 98 | |
| 99 | [ |
| 100 | # inputs: |
| 101 | 'gradients_degenerate_2pt/10552995703607727960.png', |
| 102 | 'gradients_degenerate_2pt/11198253335583713230.png', |
| 103 | { |
| 104 | 'ignoreFailure': True, |
| 105 | 'bugs': [1001, 1002], |
| 106 | }, |
| 107 | { |
| 108 | 'builder': 'MyBuilder', |
| 109 | 'test': 'MyTest', |
| 110 | }, |
| 111 | # expected output: |
| 112 | { |
| 113 | 'differenceData': { |
| 114 | 'maxDiffPerChannel': [255, 0, 255], |
| 115 | 'numDifferingPixels': 102400, |
| 116 | 'percentDifferingPixels': 100.00, |
commit-bot@chromium.org | 16f4180 | 2014-02-26 19:05:20 +0000 | [diff] [blame] | 117 | 'perceptualDifference': 100.00, |
commit-bot@chromium.org | 9985ef5 | 2014-02-10 18:19:30 +0000 | [diff] [blame] | 118 | 'weightedDiffMeasure': 66.66666666666667, |
| 119 | }, |
commit-bot@chromium.org | 536b15f | 2014-02-13 17:17:05 +0000 | [diff] [blame] | 120 | 'expectations': { |
commit-bot@chromium.org | 9985ef5 | 2014-02-10 18:19:30 +0000 | [diff] [blame] | 121 | 'bugs': [1001, 1002], |
| 122 | 'ignoreFailure': True, |
| 123 | }, |
commit-bot@chromium.org | 536b15f | 2014-02-13 17:17:05 +0000 | [diff] [blame] | 124 | 'extraColumns': { |
commit-bot@chromium.org | 9985ef5 | 2014-02-10 18:19:30 +0000 | [diff] [blame] | 125 | 'builder': 'MyBuilder', |
| 126 | 'test': 'MyTest', |
| 127 | }, |
| 128 | 'imageAUrl': |
| 129 | 'gradients_degenerate_2pt/10552995703607727960.png', |
| 130 | 'imageBUrl': |
| 131 | 'gradients_degenerate_2pt/11198253335583713230.png', |
| 132 | 'isDifferent': True, |
| 133 | }, |
| 134 | ], |
commit-bot@chromium.org | 6844958 | 2014-04-01 22:16:33 +0000 | [diff] [blame] | 135 | |
| 136 | # Test fix for http://skbug.com/2368 -- how do we handle an ImagePair |
| 137 | # missing one of its images? |
| 138 | [ |
| 139 | # inputs: |
| 140 | 'arcofzorro/16206093933823793653.png', |
| 141 | 'nonexistentDir/111111.png', |
| 142 | { |
| 143 | 'ignoreFailure': True, |
| 144 | 'bugs': [1001, 1002], |
| 145 | }, |
| 146 | { |
| 147 | 'builder': 'MyBuilder', |
| 148 | 'test': 'MyTest', |
| 149 | }, |
| 150 | # expected output: |
| 151 | { |
| 152 | 'expectations': { |
| 153 | 'bugs': [1001, 1002], |
| 154 | 'ignoreFailure': True, |
| 155 | }, |
| 156 | 'extraColumns': { |
| 157 | 'builder': 'MyBuilder', |
| 158 | 'test': 'MyTest', |
| 159 | }, |
| 160 | 'imageAUrl': 'arcofzorro/16206093933823793653.png', |
| 161 | 'imageBUrl': 'nonexistentDir/111111.png', |
| 162 | 'isDifferent': True, |
| 163 | }, |
| 164 | ], |
commit-bot@chromium.org | 9985ef5 | 2014-02-10 18:19:30 +0000 | [diff] [blame] | 165 | ] |
| 166 | |
| 167 | db = imagediffdb.ImageDiffDB(self._temp_dir) |
| 168 | for selftest in selftests: |
| 169 | image_pair = imagepair.ImagePair( |
| 170 | image_diff_db=db, |
| 171 | base_url=IMG_URL_BASE, |
| 172 | imageA_relative_url=selftest[0], |
| 173 | imageB_relative_url=selftest[1], |
| 174 | expectations=selftest[2], |
| 175 | extra_columns=selftest[3]) |
| 176 | self.assertEqual(image_pair.as_dict(), selftest[4]) |
| 177 | |
| 178 | |
| 179 | def main(): |
| 180 | suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairTest) |
| 181 | unittest.TextTestRunner(verbosity=2).run(suite) |
| 182 | |
| 183 | |
| 184 | if __name__ == '__main__': |
| 185 | main() |