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