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 | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 245 | def test_untiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 246 | """Run without tiles.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 247 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 248 | write_path_dir = self.create_empty_dir( |
| 249 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 250 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 251 | expectations_path = self._create_expectations() |
| 252 | self._run_render_pictures([ |
| 253 | '-r', self._input_skp_dir, |
| 254 | '--readJsonSummaryPath', expectations_path, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 255 | '--writePath', write_path_dir, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 256 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 257 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 258 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 259 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 260 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 261 | "whole-image": RED_WHOLEIMAGE, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 262 | }, |
| 263 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 264 | "whole-image": GREEN_WHOLEIMAGE, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | } |
| 268 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 269 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 270 | write_path_dir, ['red_skp.png', 'green_skp.png']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 271 | |
| 272 | def test_untiled_writeChecksumBasedFilenames(self): |
| 273 | """Same as test_untiled, but with --writeChecksumBasedFilenames.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 274 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 275 | write_path_dir = self.create_empty_dir( |
| 276 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 277 | self._generate_skps() |
| 278 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 279 | '--writeChecksumBasedFilenames', |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 280 | '--writePath', write_path_dir, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 281 | '--writeJsonSummaryPath', output_json_path]) |
| 282 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 283 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 284 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 285 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 286 | # Manually verified: 640x400 red rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 287 | "whole-image": { |
| 288 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 289 | "checksumValue" : 11092453015575919668, |
| 290 | "comparisonResult" : "no-comparison", |
| 291 | "filepath" : "red_skp/bitmap-64bitMD5_11092453015575919668.png", |
| 292 | }, |
| 293 | }, |
| 294 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 295 | # Manually verified: 640x400 green rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 296 | "whole-image": { |
| 297 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 298 | "checksumValue" : 8891695120562235492, |
| 299 | "comparisonResult" : "no-comparison", |
| 300 | "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.png", |
| 301 | }, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | } |
| 305 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 306 | 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] | 307 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 308 | os.path.join(write_path_dir, 'red_skp'), |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 309 | ['bitmap-64bitMD5_11092453015575919668.png']) |
| 310 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 311 | os.path.join(write_path_dir, 'green_skp'), |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 312 | ['bitmap-64bitMD5_8891695120562235492.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 313 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 314 | def test_untiled_validate(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 315 | """Same as test_untiled, but with --validate.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 316 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 317 | write_path_dir = self.create_empty_dir( |
| 318 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 319 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 320 | expectations_path = self._create_expectations() |
| 321 | self._run_render_pictures([ |
| 322 | '-r', self._input_skp_dir, |
| 323 | '--readJsonSummaryPath', expectations_path, |
| 324 | '--validate', |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 325 | '--writePath', write_path_dir, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 326 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 327 | expected_summary_dict = { |
| 328 | "header" : EXPECTED_HEADER_CONTENTS, |
| 329 | "actual-results" : { |
| 330 | "red.skp": { |
| 331 | "whole-image": RED_WHOLEIMAGE, |
| 332 | }, |
| 333 | "green.skp": { |
| 334 | "whole-image": GREEN_WHOLEIMAGE, |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 339 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 340 | write_path_dir, ['red_skp.png', 'green_skp.png']) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 341 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 342 | def test_untiled_without_writePath(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 343 | """Same as test_untiled, but without --writePath.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 344 | 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] | 345 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 346 | expectations_path = self._create_expectations() |
| 347 | self._run_render_pictures([ |
| 348 | '-r', self._input_skp_dir, |
| 349 | '--readJsonSummaryPath', expectations_path, |
| 350 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 351 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 352 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 353 | "actual-results" : { |
| 354 | "red.skp": { |
| 355 | "whole-image": RED_WHOLEIMAGE, |
| 356 | }, |
| 357 | "green.skp": { |
| 358 | "whole-image": GREEN_WHOLEIMAGE, |
| 359 | } |
| 360 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 361 | } |
| 362 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 363 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 364 | def test_tiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 365 | """Generate individual tiles.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 366 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 367 | write_path_dir = self.create_empty_dir( |
| 368 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 369 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 370 | expectations_path = self._create_expectations() |
| 371 | self._run_render_pictures([ |
| 372 | '-r', self._input_skp_dir, |
| 373 | '--bbh', 'grid', '256', '256', |
| 374 | '--mode', 'tile', '256', '256', |
| 375 | '--readJsonSummaryPath', expectations_path, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 376 | '--writePath', write_path_dir, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 377 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 378 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 379 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 380 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 381 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 382 | "tiled-images": RED_TILES, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 383 | }, |
| 384 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 385 | "tiled-images": GREEN_TILES, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 386 | } |
| 387 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 388 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 389 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 390 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 391 | write_path_dir, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 392 | ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', |
| 393 | 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', |
| 394 | 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png', |
| 395 | '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^] | 396 | ]) |
| 397 | |
| 398 | def test_tiled_mismatches(self): |
| 399 | """Same as test_tiled, but only write out mismatching images.""" |
| 400 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 401 | mismatch_path_dir = self.create_empty_dir( |
| 402 | path=os.path.join(self._output_dir, 'mismatchPath')) |
| 403 | self._generate_skps() |
| 404 | expectations_path = self._create_expectations() |
| 405 | self._run_render_pictures([ |
| 406 | '-r', self._input_skp_dir, |
| 407 | '--bbh', 'grid', '256', '256', |
| 408 | '--mode', 'tile', '256', '256', |
| 409 | '--readJsonSummaryPath', expectations_path, |
| 410 | '--mismatchPath', mismatch_path_dir, |
| 411 | '--writeJsonSummaryPath', output_json_path]) |
| 412 | expected_summary_dict = { |
| 413 | "header" : EXPECTED_HEADER_CONTENTS, |
| 414 | "actual-results" : { |
| 415 | "red.skp": { |
| 416 | "tiled-images": RED_TILES, |
| 417 | }, |
| 418 | "green.skp": { |
| 419 | "tiled-images": GREEN_TILES, |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 424 | self._assert_directory_contents( |
| 425 | mismatch_path_dir, |
| 426 | ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', |
| 427 | 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', |
| 428 | ]) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 429 | |
| 430 | def test_tiled_writeChecksumBasedFilenames(self): |
| 431 | """Same as test_tiled, but with --writeChecksumBasedFilenames.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 432 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 433 | write_path_dir = self.create_empty_dir( |
| 434 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 435 | self._generate_skps() |
| 436 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 437 | '--bbh', 'grid', '256', '256', |
| 438 | '--mode', 'tile', '256', '256', |
| 439 | '--writeChecksumBasedFilenames', |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 440 | '--writePath', write_path_dir, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 441 | '--writeJsonSummaryPath', output_json_path]) |
| 442 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 443 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 444 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 445 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 446 | # Manually verified these 6 images, all 256x256 tiles, |
| 447 | # consistent with a tiled version of the 640x400 red rect |
| 448 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 449 | "tiled-images": [{ |
| 450 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 451 | "checksumValue" : 5815827069051002745, |
| 452 | "comparisonResult" : "no-comparison", |
| 453 | "filepath" : "red_skp/bitmap-64bitMD5_5815827069051002745.png", |
| 454 | }, { |
| 455 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 456 | "checksumValue" : 9323613075234140270, |
| 457 | "comparisonResult" : "no-comparison", |
| 458 | "filepath" : "red_skp/bitmap-64bitMD5_9323613075234140270.png", |
| 459 | }, { |
| 460 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 461 | "checksumValue" : 16670399404877552232, |
| 462 | "comparisonResult" : "no-comparison", |
| 463 | "filepath" : "red_skp/bitmap-64bitMD5_16670399404877552232.png", |
| 464 | }, { |
| 465 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 466 | "checksumValue" : 2507897274083364964, |
| 467 | "comparisonResult" : "no-comparison", |
| 468 | "filepath" : "red_skp/bitmap-64bitMD5_2507897274083364964.png", |
| 469 | }, { |
| 470 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 471 | "checksumValue" : 7325267995523877959, |
| 472 | "comparisonResult" : "no-comparison", |
| 473 | "filepath" : "red_skp/bitmap-64bitMD5_7325267995523877959.png", |
| 474 | }, { |
| 475 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 476 | "checksumValue" : 2181381724594493116, |
| 477 | "comparisonResult" : "no-comparison", |
| 478 | "filepath" : "red_skp/bitmap-64bitMD5_2181381724594493116.png", |
| 479 | }], |
| 480 | }, |
| 481 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 482 | # Manually verified these 6 images, all 256x256 tiles, |
| 483 | # consistent with a tiled version of the 640x400 green rect |
| 484 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 485 | "tiled-images": [{ |
| 486 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 487 | "checksumValue" : 12587324416545178013, |
| 488 | "comparisonResult" : "no-comparison", |
| 489 | "filepath" : "green_skp/bitmap-64bitMD5_12587324416545178013.png", |
| 490 | }, { |
| 491 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 492 | "checksumValue" : 7624374914829746293, |
| 493 | "comparisonResult" : "no-comparison", |
| 494 | "filepath" : "green_skp/bitmap-64bitMD5_7624374914829746293.png", |
| 495 | }, { |
| 496 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 497 | "checksumValue" : 5686489729535631913, |
| 498 | "comparisonResult" : "no-comparison", |
| 499 | "filepath" : "green_skp/bitmap-64bitMD5_5686489729535631913.png", |
| 500 | }, { |
| 501 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 502 | "checksumValue" : 7980646035555096146, |
| 503 | "comparisonResult" : "no-comparison", |
| 504 | "filepath" : "green_skp/bitmap-64bitMD5_7980646035555096146.png", |
| 505 | }, { |
| 506 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 507 | "checksumValue" : 17817086664365875131, |
| 508 | "comparisonResult" : "no-comparison", |
| 509 | "filepath" : "green_skp/bitmap-64bitMD5_17817086664365875131.png", |
| 510 | }, { |
| 511 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 512 | "checksumValue" : 10673669813016809363, |
| 513 | "comparisonResult" : "no-comparison", |
| 514 | "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363.png", |
| 515 | }], |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | } |
| 519 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 520 | 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] | 521 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 522 | os.path.join(write_path_dir, 'red_skp'), |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 523 | ['bitmap-64bitMD5_5815827069051002745.png', |
| 524 | 'bitmap-64bitMD5_9323613075234140270.png', |
| 525 | 'bitmap-64bitMD5_16670399404877552232.png', |
| 526 | 'bitmap-64bitMD5_2507897274083364964.png', |
| 527 | 'bitmap-64bitMD5_7325267995523877959.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 528 | 'bitmap-64bitMD5_2181381724594493116.png']) |
| 529 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame^] | 530 | os.path.join(write_path_dir, 'green_skp'), |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 531 | ['bitmap-64bitMD5_12587324416545178013.png', |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 532 | 'bitmap-64bitMD5_7624374914829746293.png', |
| 533 | 'bitmap-64bitMD5_5686489729535631913.png', |
| 534 | 'bitmap-64bitMD5_7980646035555096146.png', |
| 535 | 'bitmap-64bitMD5_17817086664365875131.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 536 | 'bitmap-64bitMD5_10673669813016809363.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 537 | |
| 538 | def _run_render_pictures(self, args): |
| 539 | binary = self.find_path_to_program('render_pictures') |
| 540 | return self.run_command([binary, |
| 541 | '--clone', '1', |
| 542 | '--config', '8888', |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 543 | ] + args) |
| 544 | |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 545 | def _create_expectations(self, missing_some_images=False, |
| 546 | rel_path='expectations.json'): |
| 547 | """Creates expectations JSON file within self._expectations_dir . |
| 548 | |
| 549 | Args: |
| 550 | missing_some_images: (bool) whether to remove expectations for a subset |
| 551 | of the images |
| 552 | rel_path: (string) relative path within self._expectations_dir to write |
| 553 | the expectations into |
| 554 | |
| 555 | Returns: full path to the expectations file created. |
| 556 | """ |
| 557 | expectations_dict = { |
| 558 | "header" : EXPECTED_HEADER_CONTENTS, |
| 559 | "expected-results" : { |
| 560 | # red.skp: these should fail the comparison |
| 561 | "red.skp": { |
| 562 | "tiled-images": modified_list_of_dicts( |
| 563 | RED_TILES, {'checksumValue': 11111}), |
| 564 | "whole-image": modified_dict( |
| 565 | RED_WHOLEIMAGE, {'checksumValue': 22222}), |
| 566 | }, |
| 567 | # green.skp: these should pass the comparison |
| 568 | "green.skp": { |
| 569 | "tiled-images": GREEN_TILES, |
| 570 | "whole-image": GREEN_WHOLEIMAGE, |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | if missing_some_images: |
| 575 | del expectations_dict['expected-results']['red.skp']['whole-image'] |
| 576 | del expectations_dict['expected-results']['red.skp']['tiled-images'][-1] |
| 577 | path = os.path.join(self._expectations_dir, rel_path) |
| 578 | with open(path, 'w') as fh: |
| 579 | json.dump(expectations_dict, fh) |
| 580 | return path |
| 581 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 582 | def _generate_skps(self): |
| 583 | """Runs the skpmaker binary to generate files in self._input_skp_dir.""" |
| 584 | self._run_skpmaker( |
| 585 | output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255) |
| 586 | self._run_skpmaker( |
| 587 | output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255) |
| 588 | |
| 589 | def _run_skpmaker(self, output_path, red=0, green=0, blue=0, |
| 590 | width=640, height=400): |
| 591 | """Runs the skpmaker binary to generate SKP with known characteristics. |
| 592 | |
| 593 | Args: |
| 594 | output_path: Filepath to write the SKP into. |
| 595 | red: Value of red color channel in image, 0-255. |
| 596 | green: Value of green color channel in image, 0-255. |
| 597 | blue: Value of blue color channel in image, 0-255. |
| 598 | width: Width of canvas to create. |
| 599 | height: Height of canvas to create. |
| 600 | """ |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 601 | binary = self.find_path_to_program('skpmaker') |
| 602 | return self.run_command([binary, |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 603 | '--red', str(red), |
| 604 | '--green', str(green), |
| 605 | '--blue', str(blue), |
| 606 | '--width', str(width), |
| 607 | '--height', str(height), |
| 608 | '--writePath', str(output_path), |
| 609 | ]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 610 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 611 | def _assert_directory_contents(self, dir_path, expected_filenames): |
| 612 | """Asserts that files found in a dir are identical to expected_filenames. |
| 613 | |
| 614 | Args: |
| 615 | dir_path: Path to a directory on local disk. |
| 616 | expected_filenames: Set containing the expected filenames within the dir. |
| 617 | |
| 618 | Raises: |
| 619 | AssertionError: contents of the directory are not identical to |
| 620 | expected_filenames. |
| 621 | """ |
| 622 | self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames)) |
| 623 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 624 | def _assert_json_contents(self, json_path, expected_dict): |
| 625 | """Asserts that contents of a JSON file are identical to expected_dict. |
| 626 | |
| 627 | Args: |
| 628 | json_path: Path to a JSON file. |
| 629 | expected_dict: Dictionary indicating the expected contents of the JSON |
| 630 | file. |
| 631 | |
| 632 | Raises: |
| 633 | AssertionError: contents of the JSON file are not identical to |
| 634 | expected_dict. |
| 635 | """ |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 636 | prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True, |
| 637 | indent=2) |
| 638 | with open(json_path, 'r') as fh: |
| 639 | prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True, |
| 640 | indent=2) |
| 641 | self.assertMultiLineEqual(prettyprinted_expected_dict, |
| 642 | prettyprinted_json_dict) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 643 | |
| 644 | |
| 645 | def main(): |
| 646 | base_unittest.main(RenderPicturesTest) |
| 647 | |
| 648 | |
| 649 | if __name__ == '__main__': |
| 650 | main() |