commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +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 the render_pictures binary. |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 10 | """ |
| 11 | |
| 12 | # System-level imports |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 13 | import copy |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 14 | import json |
| 15 | import os |
| 16 | import shutil |
| 17 | import tempfile |
| 18 | |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 19 | # Must fix up PYTHONPATH before importing from within Skia |
| 20 | import fix_pythonpath # pylint: disable=W0611 |
| 21 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 22 | # Imports from within Skia |
| 23 | import base_unittest |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 24 | import find_run_binary |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 25 | |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 26 | # Maximum length of text diffs to show when tests fail |
| 27 | MAX_DIFF_LENGTH = 30000 |
| 28 | |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 29 | EXPECTED_HEADER_CONTENTS = { |
| 30 | "type" : "ChecksummedImages", |
| 31 | "revision" : 1, |
| 32 | } |
| 33 | |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 34 | # Manually verified: 640x400 red rectangle with black border |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 35 | # Standard expectations will be set up in such a way that this image fails |
| 36 | # the comparison. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 37 | RED_WHOLEIMAGE = { |
| 38 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 39 | "checksumValue" : 11092453015575919668, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 40 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 41 | "filepath" : "red_skp.png", |
| 42 | } |
| 43 | |
| 44 | # Manually verified: 640x400 green rectangle with black border |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 45 | # Standard expectations will be set up in such a way that this image passes |
| 46 | # the comparison. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 47 | GREEN_WHOLEIMAGE = { |
| 48 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 49 | "checksumValue" : 8891695120562235492, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 50 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 51 | "filepath" : "green_skp.png", |
| 52 | } |
| 53 | |
| 54 | # Manually verified these 6 images, all 256x256 tiles, |
| 55 | # consistent with a tiled version of the 640x400 red rect |
| 56 | # with black borders. |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 57 | # Standard expectations will be set up in such a way that these images fail |
| 58 | # the comparison. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 59 | RED_TILES = [{ |
| 60 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 61 | "checksumValue" : 5815827069051002745, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 62 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 63 | "filepath" : "red_skp-tile0.png", |
| 64 | },{ |
| 65 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 66 | "checksumValue" : 9323613075234140270, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 67 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 68 | "filepath" : "red_skp-tile1.png", |
| 69 | }, { |
| 70 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 71 | "checksumValue" : 16670399404877552232, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 72 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 73 | "filepath" : "red_skp-tile2.png", |
| 74 | }, { |
| 75 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 76 | "checksumValue" : 2507897274083364964, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 77 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 78 | "filepath" : "red_skp-tile3.png", |
| 79 | }, { |
| 80 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 81 | "checksumValue" : 7325267995523877959, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 82 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 83 | "filepath" : "red_skp-tile4.png", |
| 84 | }, { |
| 85 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 86 | "checksumValue" : 2181381724594493116, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 87 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 88 | "filepath" : "red_skp-tile5.png", |
| 89 | }] |
| 90 | |
| 91 | # Manually verified these 6 images, all 256x256 tiles, |
| 92 | # consistent with a tiled version of the 640x400 green rect |
| 93 | # with black borders. |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 94 | # Standard expectations will be set up in such a way that these images pass |
| 95 | # the comparison. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 96 | GREEN_TILES = [{ |
| 97 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 98 | "checksumValue" : 12587324416545178013, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 99 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 100 | "filepath" : "green_skp-tile0.png", |
| 101 | }, { |
| 102 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 103 | "checksumValue" : 7624374914829746293, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 104 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 105 | "filepath" : "green_skp-tile1.png", |
| 106 | }, { |
| 107 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 108 | "checksumValue" : 5686489729535631913, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 109 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 110 | "filepath" : "green_skp-tile2.png", |
| 111 | }, { |
| 112 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 113 | "checksumValue" : 7980646035555096146, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 114 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 115 | "filepath" : "green_skp-tile3.png", |
| 116 | }, { |
| 117 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 118 | "checksumValue" : 17817086664365875131, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 119 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 120 | "filepath" : "green_skp-tile4.png", |
| 121 | }, { |
| 122 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 123 | "checksumValue" : 10673669813016809363, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 124 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 125 | "filepath" : "green_skp-tile5.png", |
| 126 | }] |
| 127 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 128 | |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 129 | def modified_dict(input_dict, modification_dict): |
| 130 | """Returns a dict, with some modifications applied to it. |
| 131 | |
| 132 | Args: |
| 133 | input_dict: a dictionary (which will be copied, not modified in place) |
| 134 | modification_dict: a set of key/value pairs to overwrite in the dict |
| 135 | """ |
| 136 | output_dict = input_dict.copy() |
| 137 | output_dict.update(modification_dict) |
| 138 | return output_dict |
| 139 | |
| 140 | |
| 141 | def modified_list_of_dicts(input_list, modification_dict): |
| 142 | """Returns a list of dicts, with some modifications applied to each dict. |
| 143 | |
| 144 | Args: |
| 145 | input_list: a list of dictionaries; these dicts will be copied, not |
| 146 | modified in place |
| 147 | modification_dict: a set of key/value pairs to overwrite in each dict |
| 148 | within input_list |
| 149 | """ |
| 150 | output_list = [] |
| 151 | for input_dict in input_list: |
| 152 | output_dict = modified_dict(input_dict, modification_dict) |
| 153 | output_list.append(output_dict) |
| 154 | return output_list |
| 155 | |
| 156 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 157 | class RenderPicturesTest(base_unittest.TestCase): |
| 158 | |
| 159 | def setUp(self): |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 160 | self.maxDiff = MAX_DIFF_LENGTH |
| 161 | self._expectations_dir = tempfile.mkdtemp() |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 162 | self._input_skp_dir = tempfile.mkdtemp() |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 163 | # All output of render_pictures binary will go into this directory. |
| 164 | self._output_dir = tempfile.mkdtemp() |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 165 | |
| 166 | def tearDown(self): |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 167 | shutil.rmtree(self._expectations_dir) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 168 | shutil.rmtree(self._input_skp_dir) |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 169 | shutil.rmtree(self._output_dir) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 170 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 171 | def test_tiled_whole_image(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 172 | """Run render_pictures with tiles and --writeWholeImage flag. |
| 173 | |
| 174 | TODO(epoger): This test generates undesired results! The JSON summary |
| 175 | includes both whole-image and tiled-images (as it should), but only |
| 176 | whole-images are written out to disk. See http://skbug.com/2463 |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 177 | Once I fix that, I should add a similar test that exercises mismatchPath. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 178 | |
| 179 | TODO(epoger): I noticed that when this is run without --writePath being |
| 180 | specified, this test writes red_skp.png and green_skp.png to the current |
| 181 | directory. We should fix that... if --writePath is not specified, this |
| 182 | probably shouldn't write out red_skp.png and green_skp.png at all! |
| 183 | See http://skbug.com/2464 |
| 184 | """ |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 185 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 186 | write_path_dir = self.create_empty_dir( |
| 187 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 188 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 189 | expectations_path = self._create_expectations() |
| 190 | self._run_render_pictures([ |
| 191 | '-r', self._input_skp_dir, |
| 192 | '--bbh', 'grid', '256', '256', |
| 193 | '--mode', 'tile', '256', '256', |
| 194 | '--readJsonSummaryPath', expectations_path, |
| 195 | '--writeJsonSummaryPath', output_json_path, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 196 | '--writePath', write_path_dir, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 197 | '--writeWholeImage']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 198 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 199 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 200 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 201 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 202 | "tiled-images": RED_TILES, |
| 203 | "whole-image": RED_WHOLEIMAGE, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 204 | }, |
| 205 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 206 | "tiled-images": GREEN_TILES, |
| 207 | "whole-image": GREEN_WHOLEIMAGE, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
commit-bot@chromium.org | 238771c | 2014-01-15 16:33:31 +0000 | [diff] [blame] | 210 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 211 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 212 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 213 | write_path_dir, ['red_skp.png', 'green_skp.png']) |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 214 | |
| 215 | def test_missing_tile_and_whole_image(self): |
| 216 | """test_tiled_whole_image, but missing expectations for some images. |
| 217 | """ |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 218 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 219 | write_path_dir = self.create_empty_dir( |
| 220 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 221 | self._generate_skps() |
| 222 | expectations_path = self._create_expectations(missing_some_images=True) |
| 223 | self._run_render_pictures([ |
| 224 | '-r', self._input_skp_dir, |
| 225 | '--bbh', 'grid', '256', '256', |
| 226 | '--mode', 'tile', '256', '256', |
| 227 | '--readJsonSummaryPath', expectations_path, |
| 228 | '--writeJsonSummaryPath', output_json_path, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 229 | '--writePath', write_path_dir, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 230 | '--writeWholeImage']) |
| 231 | modified_red_tiles = copy.deepcopy(RED_TILES) |
| 232 | modified_red_tiles[5]['comparisonResult'] = 'no-comparison' |
| 233 | expected_summary_dict = { |
| 234 | "header" : EXPECTED_HEADER_CONTENTS, |
| 235 | "actual-results" : { |
| 236 | "red.skp": { |
| 237 | "tiled-images": modified_red_tiles, |
| 238 | "whole-image": modified_dict( |
| 239 | RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
| 240 | }, |
| 241 | "green.skp": { |
| 242 | "tiled-images": GREEN_TILES, |
| 243 | "whole-image": GREEN_WHOLEIMAGE, |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 248 | |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 249 | def _test_untiled(self, expectations_path=None, expected_summary_dict=None, |
| 250 | additional_args=None): |
| 251 | """Base for multiple tests without tiles. |
| 252 | |
| 253 | Args: |
| 254 | expectations_path: path we should pass using --readJsonSummaryPath, or |
| 255 | None if we should create the default expectations file |
| 256 | expected_summary_dict: dict we should compare against the output actual |
| 257 | results summary, or None if we should use a default comparison dict |
| 258 | additional_args: array of command-line args to add when we run |
| 259 | render_pictures |
| 260 | """ |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 261 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 262 | write_path_dir = self.create_empty_dir( |
| 263 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 264 | self._generate_skps() |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 265 | if expectations_path == None: |
| 266 | expectations_path = self._create_expectations() |
| 267 | args = [ |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 268 | '-r', self._input_skp_dir, |
| 269 | '--readJsonSummaryPath', expectations_path, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 270 | '--writePath', write_path_dir, |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 271 | '--writeJsonSummaryPath', output_json_path, |
| 272 | ] |
| 273 | if additional_args: |
| 274 | args.extend(additional_args) |
| 275 | self._run_render_pictures(args) |
| 276 | if expected_summary_dict == None: |
| 277 | expected_summary_dict = { |
| 278 | "header" : EXPECTED_HEADER_CONTENTS, |
| 279 | "actual-results" : { |
| 280 | "red.skp": { |
| 281 | "whole-image": RED_WHOLEIMAGE, |
| 282 | }, |
| 283 | "green.skp": { |
| 284 | "whole-image": GREEN_WHOLEIMAGE, |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 289 | self._assert_directory_contents( |
| 290 | write_path_dir, ['red_skp.png', 'green_skp.png']) |
| 291 | |
| 292 | def test_untiled(self): |
| 293 | """Basic test without tiles.""" |
| 294 | self._test_untiled() |
| 295 | |
| 296 | def test_untiled_empty_expectations_file(self): |
| 297 | """Same as test_untiled, but with an empty expectations file.""" |
| 298 | expectations_path = os.path.join(self._expectations_dir, 'empty') |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 299 | with open(expectations_path, 'w'): |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 300 | pass |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 301 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 302 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 303 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 304 | "red.skp": { |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 305 | "whole-image": modified_dict( |
| 306 | RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 307 | }, |
| 308 | "green.skp": { |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 309 | "whole-image": modified_dict( |
| 310 | GREEN_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | } |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 314 | self._test_untiled(expectations_path=expectations_path, |
| 315 | expected_summary_dict=expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 316 | |
| 317 | def test_untiled_writeChecksumBasedFilenames(self): |
| 318 | """Same as test_untiled, but with --writeChecksumBasedFilenames.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 319 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 320 | write_path_dir = self.create_empty_dir( |
| 321 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 322 | self._generate_skps() |
| 323 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 324 | '--writeChecksumBasedFilenames', |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 325 | '--writePath', write_path_dir, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 326 | '--writeJsonSummaryPath', output_json_path]) |
| 327 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 328 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 329 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 330 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 331 | # Manually verified: 640x400 red rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 332 | "whole-image": { |
| 333 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 334 | "checksumValue" : 11092453015575919668, |
| 335 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 336 | "filepath" : |
| 337 | "red_skp/bitmap-64bitMD5_11092453015575919668.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 338 | }, |
| 339 | }, |
| 340 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 341 | # Manually verified: 640x400 green rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 342 | "whole-image": { |
| 343 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 344 | "checksumValue" : 8891695120562235492, |
| 345 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 346 | "filepath" : |
| 347 | "green_skp/bitmap-64bitMD5_8891695120562235492.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 348 | }, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | } |
| 352 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 353 | self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 354 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 355 | os.path.join(write_path_dir, 'red_skp'), |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 356 | ['bitmap-64bitMD5_11092453015575919668.png']) |
| 357 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 358 | os.path.join(write_path_dir, 'green_skp'), |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 359 | ['bitmap-64bitMD5_8891695120562235492.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 360 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 361 | def test_untiled_validate(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 362 | """Same as test_untiled, but with --validate.""" |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 363 | self._test_untiled(additional_args=['--validate']) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 364 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 365 | def test_untiled_without_writePath(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 366 | """Same as test_untiled, but without --writePath.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 367 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 368 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 369 | expectations_path = self._create_expectations() |
| 370 | self._run_render_pictures([ |
| 371 | '-r', self._input_skp_dir, |
| 372 | '--readJsonSummaryPath', expectations_path, |
| 373 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 374 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 375 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 376 | "actual-results" : { |
| 377 | "red.skp": { |
| 378 | "whole-image": RED_WHOLEIMAGE, |
| 379 | }, |
| 380 | "green.skp": { |
| 381 | "whole-image": GREEN_WHOLEIMAGE, |
| 382 | } |
| 383 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 384 | } |
| 385 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 386 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 387 | def test_tiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 388 | """Generate individual tiles.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 389 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 390 | write_path_dir = self.create_empty_dir( |
| 391 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 392 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 393 | expectations_path = self._create_expectations() |
| 394 | self._run_render_pictures([ |
| 395 | '-r', self._input_skp_dir, |
| 396 | '--bbh', 'grid', '256', '256', |
| 397 | '--mode', 'tile', '256', '256', |
| 398 | '--readJsonSummaryPath', expectations_path, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 399 | '--writePath', write_path_dir, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 400 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 401 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 402 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 403 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 404 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 405 | "tiled-images": RED_TILES, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 406 | }, |
| 407 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 408 | "tiled-images": GREEN_TILES, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 411 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 412 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 413 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 414 | write_path_dir, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 415 | ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', |
| 416 | 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', |
| 417 | 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png', |
| 418 | 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png', |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 419 | ]) |
| 420 | |
| 421 | def test_tiled_mismatches(self): |
| 422 | """Same as test_tiled, but only write out mismatching images.""" |
| 423 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 424 | mismatch_path_dir = self.create_empty_dir( |
| 425 | path=os.path.join(self._output_dir, 'mismatchPath')) |
| 426 | self._generate_skps() |
| 427 | expectations_path = self._create_expectations() |
| 428 | self._run_render_pictures([ |
| 429 | '-r', self._input_skp_dir, |
| 430 | '--bbh', 'grid', '256', '256', |
| 431 | '--mode', 'tile', '256', '256', |
| 432 | '--readJsonSummaryPath', expectations_path, |
| 433 | '--mismatchPath', mismatch_path_dir, |
| 434 | '--writeJsonSummaryPath', output_json_path]) |
| 435 | expected_summary_dict = { |
| 436 | "header" : EXPECTED_HEADER_CONTENTS, |
| 437 | "actual-results" : { |
| 438 | "red.skp": { |
| 439 | "tiled-images": RED_TILES, |
| 440 | }, |
| 441 | "green.skp": { |
| 442 | "tiled-images": GREEN_TILES, |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 447 | self._assert_directory_contents( |
| 448 | mismatch_path_dir, |
| 449 | ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', |
| 450 | 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', |
| 451 | ]) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 452 | |
| 453 | def test_tiled_writeChecksumBasedFilenames(self): |
| 454 | """Same as test_tiled, but with --writeChecksumBasedFilenames.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 455 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 456 | write_path_dir = self.create_empty_dir( |
| 457 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 458 | self._generate_skps() |
| 459 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 460 | '--bbh', 'grid', '256', '256', |
| 461 | '--mode', 'tile', '256', '256', |
| 462 | '--writeChecksumBasedFilenames', |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 463 | '--writePath', write_path_dir, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 464 | '--writeJsonSummaryPath', output_json_path]) |
| 465 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 466 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 467 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 468 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 469 | # Manually verified these 6 images, all 256x256 tiles, |
| 470 | # consistent with a tiled version of the 640x400 red rect |
| 471 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 472 | "tiled-images": [{ |
| 473 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 474 | "checksumValue" : 5815827069051002745, |
| 475 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 476 | "filepath" : |
| 477 | "red_skp/bitmap-64bitMD5_5815827069051002745.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 478 | }, { |
| 479 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 480 | "checksumValue" : 9323613075234140270, |
| 481 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 482 | "filepath" : |
| 483 | "red_skp/bitmap-64bitMD5_9323613075234140270.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 484 | }, { |
| 485 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 486 | "checksumValue" : 16670399404877552232, |
| 487 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 488 | "filepath" : |
| 489 | "red_skp/bitmap-64bitMD5_16670399404877552232.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 490 | }, { |
| 491 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 492 | "checksumValue" : 2507897274083364964, |
| 493 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 494 | "filepath" : |
| 495 | "red_skp/bitmap-64bitMD5_2507897274083364964.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 496 | }, { |
| 497 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 498 | "checksumValue" : 7325267995523877959, |
| 499 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 500 | "filepath" : |
| 501 | "red_skp/bitmap-64bitMD5_7325267995523877959.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 502 | }, { |
| 503 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 504 | "checksumValue" : 2181381724594493116, |
| 505 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 506 | "filepath" : |
| 507 | "red_skp/bitmap-64bitMD5_2181381724594493116.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 508 | }], |
| 509 | }, |
| 510 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 511 | # Manually verified these 6 images, all 256x256 tiles, |
| 512 | # consistent with a tiled version of the 640x400 green rect |
| 513 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 514 | "tiled-images": [{ |
| 515 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 516 | "checksumValue" : 12587324416545178013, |
| 517 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 518 | "filepath" : |
| 519 | "green_skp/bitmap-64bitMD5_12587324416545178013.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 520 | }, { |
| 521 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 522 | "checksumValue" : 7624374914829746293, |
| 523 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 524 | "filepath" : |
| 525 | "green_skp/bitmap-64bitMD5_7624374914829746293.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 526 | }, { |
| 527 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 528 | "checksumValue" : 5686489729535631913, |
| 529 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 530 | "filepath" : |
| 531 | "green_skp/bitmap-64bitMD5_5686489729535631913.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 532 | }, { |
| 533 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 534 | "checksumValue" : 7980646035555096146, |
| 535 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 536 | "filepath" : |
| 537 | "green_skp/bitmap-64bitMD5_7980646035555096146.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 538 | }, { |
| 539 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 540 | "checksumValue" : 17817086664365875131, |
| 541 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 542 | "filepath" : |
| 543 | "green_skp/bitmap-64bitMD5_17817086664365875131.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 544 | }, { |
| 545 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 546 | "checksumValue" : 10673669813016809363, |
| 547 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 548 | "filepath" : |
| 549 | "green_skp/bitmap-64bitMD5_10673669813016809363.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 550 | }], |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | } |
| 554 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 555 | self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 556 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 557 | os.path.join(write_path_dir, 'red_skp'), |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 558 | ['bitmap-64bitMD5_5815827069051002745.png', |
| 559 | 'bitmap-64bitMD5_9323613075234140270.png', |
| 560 | 'bitmap-64bitMD5_16670399404877552232.png', |
| 561 | 'bitmap-64bitMD5_2507897274083364964.png', |
| 562 | 'bitmap-64bitMD5_7325267995523877959.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 563 | 'bitmap-64bitMD5_2181381724594493116.png']) |
| 564 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 565 | os.path.join(write_path_dir, 'green_skp'), |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 566 | ['bitmap-64bitMD5_12587324416545178013.png', |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 567 | 'bitmap-64bitMD5_7624374914829746293.png', |
| 568 | 'bitmap-64bitMD5_5686489729535631913.png', |
| 569 | 'bitmap-64bitMD5_7980646035555096146.png', |
| 570 | 'bitmap-64bitMD5_17817086664365875131.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 571 | 'bitmap-64bitMD5_10673669813016809363.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 572 | |
| 573 | def _run_render_pictures(self, args): |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 574 | binary = find_run_binary.find_path_to_program('render_pictures') |
| 575 | return find_run_binary.run_command( |
| 576 | [binary, '--config', '8888'] + args) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 577 | |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 578 | def _create_expectations(self, missing_some_images=False, |
| 579 | rel_path='expectations.json'): |
| 580 | """Creates expectations JSON file within self._expectations_dir . |
| 581 | |
| 582 | Args: |
| 583 | missing_some_images: (bool) whether to remove expectations for a subset |
| 584 | of the images |
| 585 | rel_path: (string) relative path within self._expectations_dir to write |
| 586 | the expectations into |
| 587 | |
| 588 | Returns: full path to the expectations file created. |
| 589 | """ |
| 590 | expectations_dict = { |
| 591 | "header" : EXPECTED_HEADER_CONTENTS, |
| 592 | "expected-results" : { |
| 593 | # red.skp: these should fail the comparison |
| 594 | "red.skp": { |
| 595 | "tiled-images": modified_list_of_dicts( |
| 596 | RED_TILES, {'checksumValue': 11111}), |
| 597 | "whole-image": modified_dict( |
| 598 | RED_WHOLEIMAGE, {'checksumValue': 22222}), |
| 599 | }, |
| 600 | # green.skp: these should pass the comparison |
| 601 | "green.skp": { |
| 602 | "tiled-images": GREEN_TILES, |
| 603 | "whole-image": GREEN_WHOLEIMAGE, |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | if missing_some_images: |
| 608 | del expectations_dict['expected-results']['red.skp']['whole-image'] |
| 609 | del expectations_dict['expected-results']['red.skp']['tiled-images'][-1] |
| 610 | path = os.path.join(self._expectations_dir, rel_path) |
| 611 | with open(path, 'w') as fh: |
| 612 | json.dump(expectations_dict, fh) |
| 613 | return path |
| 614 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 615 | def _generate_skps(self): |
| 616 | """Runs the skpmaker binary to generate files in self._input_skp_dir.""" |
| 617 | self._run_skpmaker( |
| 618 | output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255) |
| 619 | self._run_skpmaker( |
| 620 | output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255) |
| 621 | |
| 622 | def _run_skpmaker(self, output_path, red=0, green=0, blue=0, |
| 623 | width=640, height=400): |
| 624 | """Runs the skpmaker binary to generate SKP with known characteristics. |
| 625 | |
| 626 | Args: |
| 627 | output_path: Filepath to write the SKP into. |
| 628 | red: Value of red color channel in image, 0-255. |
| 629 | green: Value of green color channel in image, 0-255. |
| 630 | blue: Value of blue color channel in image, 0-255. |
| 631 | width: Width of canvas to create. |
| 632 | height: Height of canvas to create. |
| 633 | """ |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 634 | binary = find_run_binary.find_path_to_program('skpmaker') |
| 635 | return find_run_binary.run_command([ |
| 636 | binary, |
| 637 | '--red', str(red), |
| 638 | '--green', str(green), |
| 639 | '--blue', str(blue), |
| 640 | '--width', str(width), |
| 641 | '--height', str(height), |
| 642 | '--writePath', str(output_path), |
| 643 | ]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 644 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 645 | def _assert_directory_contents(self, dir_path, expected_filenames): |
| 646 | """Asserts that files found in a dir are identical to expected_filenames. |
| 647 | |
| 648 | Args: |
| 649 | dir_path: Path to a directory on local disk. |
| 650 | expected_filenames: Set containing the expected filenames within the dir. |
| 651 | |
| 652 | Raises: |
| 653 | AssertionError: contents of the directory are not identical to |
| 654 | expected_filenames. |
| 655 | """ |
| 656 | self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames)) |
| 657 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 658 | def _assert_json_contents(self, json_path, expected_dict): |
| 659 | """Asserts that contents of a JSON file are identical to expected_dict. |
| 660 | |
| 661 | Args: |
| 662 | json_path: Path to a JSON file. |
| 663 | expected_dict: Dictionary indicating the expected contents of the JSON |
| 664 | file. |
| 665 | |
| 666 | Raises: |
| 667 | AssertionError: contents of the JSON file are not identical to |
| 668 | expected_dict. |
| 669 | """ |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 670 | prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True, |
| 671 | indent=2) |
| 672 | with open(json_path, 'r') as fh: |
| 673 | prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True, |
| 674 | indent=2) |
| 675 | self.assertMultiLineEqual(prettyprinted_expected_dict, |
| 676 | prettyprinted_json_dict) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 677 | |
| 678 | |
| 679 | def main(): |
| 680 | base_unittest.main(RenderPicturesTest) |
| 681 | |
| 682 | |
| 683 | if __name__ == '__main__': |
| 684 | main() |