| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 """ | 3 """ |
| 4 Copyright 2014 Google Inc. | 4 Copyright 2014 Google Inc. |
| 5 | 5 |
| 6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
| 7 found in the LICENSE file. | 7 found in the LICENSE file. |
| 8 | 8 |
| 9 Test the render_pictures binary. | 9 Test the render_pictures binary. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 # System-level imports | 12 # System-level imports |
| 13 import json | 13 import json |
| 14 import os | 14 import os |
| 15 import shutil | 15 import shutil |
| 16 import tempfile | 16 import tempfile |
| 17 | 17 |
| 18 # Imports from within Skia | 18 # Imports from within Skia |
| 19 import base_unittest | 19 import base_unittest |
| 20 | 20 |
| 21 # Maximum length of text diffs to show when tests fail | 21 # Maximum length of text diffs to show when tests fail |
| 22 MAX_DIFF_LENGTH = 30000 | 22 MAX_DIFF_LENGTH = 30000 |
| 23 | 23 |
| 24 EXPECTED_HEADER_CONTENTS = { | 24 EXPECTED_HEADER_CONTENTS = { |
| 25 "type" : "ChecksummedImages", | 25 "type" : "ChecksummedImages", |
| 26 "revision" : 1, | 26 "revision" : 1, |
| 27 } | 27 } |
| 28 | 28 |
| 29 # Manually verified: 640x400 red rectangle with black border | 29 # Manually verified: 640x400 red rectangle with black border |
| 30 # Standard expectations will be set up in such a way that this image fails |
| 31 # the comparison. |
| 30 RED_WHOLEIMAGE = { | 32 RED_WHOLEIMAGE = { |
| 31 "checksumAlgorithm" : "bitmap-64bitMD5", | 33 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 32 "checksumValue" : 11092453015575919668, | 34 "checksumValue" : 11092453015575919668, |
| 33 "comparisonResult" : "no-comparison", | 35 "comparisonResult" : "failed", |
| 34 "filepath" : "red_skp.png", | 36 "filepath" : "red_skp.png", |
| 35 } | 37 } |
| 36 | 38 |
| 37 # Manually verified: 640x400 green rectangle with black border | 39 # Manually verified: 640x400 green rectangle with black border |
| 40 # Standard expectations will be set up in such a way that this image passes |
| 41 # the comparison. |
| 38 GREEN_WHOLEIMAGE = { | 42 GREEN_WHOLEIMAGE = { |
| 39 "checksumAlgorithm" : "bitmap-64bitMD5", | 43 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 40 "checksumValue" : 8891695120562235492, | 44 "checksumValue" : 8891695120562235492, |
| 41 "comparisonResult" : "no-comparison", | 45 "comparisonResult" : "succeeded", |
| 42 "filepath" : "green_skp.png", | 46 "filepath" : "green_skp.png", |
| 43 } | 47 } |
| 44 | 48 |
| 45 # Manually verified these 6 images, all 256x256 tiles, | 49 # Manually verified these 6 images, all 256x256 tiles, |
| 46 # consistent with a tiled version of the 640x400 red rect | 50 # consistent with a tiled version of the 640x400 red rect |
| 47 # with black borders. | 51 # with black borders. |
| 52 # Standard expectations will be set up in such a way that these images fail |
| 53 # the comparison. |
| 48 RED_TILES = [{ | 54 RED_TILES = [{ |
| 49 "checksumAlgorithm" : "bitmap-64bitMD5", | 55 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 50 "checksumValue" : 5815827069051002745, | 56 "checksumValue" : 5815827069051002745, |
| 51 "comparisonResult" : "no-comparison", | 57 "comparisonResult" : "failed", |
| 52 "filepath" : "red_skp-tile0.png", | 58 "filepath" : "red_skp-tile0.png", |
| 53 },{ | 59 },{ |
| 54 "checksumAlgorithm" : "bitmap-64bitMD5", | 60 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 55 "checksumValue" : 9323613075234140270, | 61 "checksumValue" : 9323613075234140270, |
| 56 "comparisonResult" : "no-comparison", | 62 "comparisonResult" : "failed", |
| 57 "filepath" : "red_skp-tile1.png", | 63 "filepath" : "red_skp-tile1.png", |
| 58 }, { | 64 }, { |
| 59 "checksumAlgorithm" : "bitmap-64bitMD5", | 65 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 60 "checksumValue" : 16670399404877552232, | 66 "checksumValue" : 16670399404877552232, |
| 61 "comparisonResult" : "no-comparison", | 67 "comparisonResult" : "failed", |
| 62 "filepath" : "red_skp-tile2.png", | 68 "filepath" : "red_skp-tile2.png", |
| 63 }, { | 69 }, { |
| 64 "checksumAlgorithm" : "bitmap-64bitMD5", | 70 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 65 "checksumValue" : 2507897274083364964, | 71 "checksumValue" : 2507897274083364964, |
| 66 "comparisonResult" : "no-comparison", | 72 "comparisonResult" : "failed", |
| 67 "filepath" : "red_skp-tile3.png", | 73 "filepath" : "red_skp-tile3.png", |
| 68 }, { | 74 }, { |
| 69 "checksumAlgorithm" : "bitmap-64bitMD5", | 75 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 70 "checksumValue" : 7325267995523877959, | 76 "checksumValue" : 7325267995523877959, |
| 71 "comparisonResult" : "no-comparison", | 77 "comparisonResult" : "failed", |
| 72 "filepath" : "red_skp-tile4.png", | 78 "filepath" : "red_skp-tile4.png", |
| 73 }, { | 79 }, { |
| 74 "checksumAlgorithm" : "bitmap-64bitMD5", | 80 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 75 "checksumValue" : 2181381724594493116, | 81 "checksumValue" : 2181381724594493116, |
| 76 "comparisonResult" : "no-comparison", | 82 "comparisonResult" : "failed", |
| 77 "filepath" : "red_skp-tile5.png", | 83 "filepath" : "red_skp-tile5.png", |
| 78 }] | 84 }] |
| 79 | 85 |
| 80 # Manually verified these 6 images, all 256x256 tiles, | 86 # Manually verified these 6 images, all 256x256 tiles, |
| 81 # consistent with a tiled version of the 640x400 green rect | 87 # consistent with a tiled version of the 640x400 green rect |
| 82 # with black borders. | 88 # with black borders. |
| 89 # Standard expectations will be set up in such a way that these images pass |
| 90 # the comparison. |
| 83 GREEN_TILES = [{ | 91 GREEN_TILES = [{ |
| 84 "checksumAlgorithm" : "bitmap-64bitMD5", | 92 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 85 "checksumValue" : 12587324416545178013, | 93 "checksumValue" : 12587324416545178013, |
| 86 "comparisonResult" : "no-comparison", | 94 "comparisonResult" : "succeeded", |
| 87 "filepath" : "green_skp-tile0.png", | 95 "filepath" : "green_skp-tile0.png", |
| 88 }, { | 96 }, { |
| 89 "checksumAlgorithm" : "bitmap-64bitMD5", | 97 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 90 "checksumValue" : 7624374914829746293, | 98 "checksumValue" : 7624374914829746293, |
| 91 "comparisonResult" : "no-comparison", | 99 "comparisonResult" : "succeeded", |
| 92 "filepath" : "green_skp-tile1.png", | 100 "filepath" : "green_skp-tile1.png", |
| 93 }, { | 101 }, { |
| 94 "checksumAlgorithm" : "bitmap-64bitMD5", | 102 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 95 "checksumValue" : 5686489729535631913, | 103 "checksumValue" : 5686489729535631913, |
| 96 "comparisonResult" : "no-comparison", | 104 "comparisonResult" : "succeeded", |
| 97 "filepath" : "green_skp-tile2.png", | 105 "filepath" : "green_skp-tile2.png", |
| 98 }, { | 106 }, { |
| 99 "checksumAlgorithm" : "bitmap-64bitMD5", | 107 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 100 "checksumValue" : 7980646035555096146, | 108 "checksumValue" : 7980646035555096146, |
| 101 "comparisonResult" : "no-comparison", | 109 "comparisonResult" : "succeeded", |
| 102 "filepath" : "green_skp-tile3.png", | 110 "filepath" : "green_skp-tile3.png", |
| 103 }, { | 111 }, { |
| 104 "checksumAlgorithm" : "bitmap-64bitMD5", | 112 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 105 "checksumValue" : 17817086664365875131, | 113 "checksumValue" : 17817086664365875131, |
| 106 "comparisonResult" : "no-comparison", | 114 "comparisonResult" : "succeeded", |
| 107 "filepath" : "green_skp-tile4.png", | 115 "filepath" : "green_skp-tile4.png", |
| 108 }, { | 116 }, { |
| 109 "checksumAlgorithm" : "bitmap-64bitMD5", | 117 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 110 "checksumValue" : 10673669813016809363, | 118 "checksumValue" : 10673669813016809363, |
| 111 "comparisonResult" : "no-comparison", | 119 "comparisonResult" : "succeeded", |
| 112 "filepath" : "green_skp-tile5.png", | 120 "filepath" : "green_skp-tile5.png", |
| 113 }] | 121 }] |
| 114 | 122 |
| 115 | 123 |
| 124 def modified_dict(input_dict, modification_dict): |
| 125 """Returns a dict, with some modifications applied to it. |
| 126 |
| 127 Args: |
| 128 input_dict: a dictionary (which will be copied, not modified in place) |
| 129 modification_dict: a set of key/value pairs to overwrite in the dict |
| 130 """ |
| 131 output_dict = input_dict.copy() |
| 132 output_dict.update(modification_dict) |
| 133 return output_dict |
| 134 |
| 135 |
| 136 def modified_list_of_dicts(input_list, modification_dict): |
| 137 """Returns a list of dicts, with some modifications applied to each dict. |
| 138 |
| 139 Args: |
| 140 input_list: a list of dictionaries; these dicts will be copied, not |
| 141 modified in place |
| 142 modification_dict: a set of key/value pairs to overwrite in each dict |
| 143 within input_list |
| 144 """ |
| 145 output_list = [] |
| 146 for input_dict in input_list: |
| 147 output_dict = modified_dict(input_dict, modification_dict) |
| 148 output_list.append(output_dict) |
| 149 return output_list |
| 150 |
| 151 |
| 116 class RenderPicturesTest(base_unittest.TestCase): | 152 class RenderPicturesTest(base_unittest.TestCase): |
| 117 | 153 |
| 118 def setUp(self): | 154 def setUp(self): |
| 155 self.maxDiff = MAX_DIFF_LENGTH |
| 156 self._expectations_dir = tempfile.mkdtemp() |
| 119 self._input_skp_dir = tempfile.mkdtemp() | 157 self._input_skp_dir = tempfile.mkdtemp() |
| 120 self._temp_dir = tempfile.mkdtemp() | 158 self._temp_dir = tempfile.mkdtemp() |
| 121 self.maxDiff = MAX_DIFF_LENGTH | 159 |
| 160 # Set up standard expectations JSON file: green should succeed, red should |
| 161 # fail. |
| 162 expectations_dict = { |
| 163 "header" : EXPECTED_HEADER_CONTENTS, |
| 164 "expected-results" : { |
| 165 "red.skp": { |
| 166 "tiled-images": modified_list_of_dicts( |
| 167 RED_TILES, {'checksumValue': 11111}), |
| 168 "whole-image": modified_dict( |
| 169 RED_WHOLEIMAGE, {'checksumValue': 22222}), |
| 170 }, |
| 171 "green.skp": { |
| 172 "tiled-images": GREEN_TILES, |
| 173 "whole-image": GREEN_WHOLEIMAGE, |
| 174 } |
| 175 } |
| 176 } |
| 177 self._standard_expectations_path = os.path.join( |
| 178 self._expectations_dir, 'expectations.json') |
| 179 with open(self._standard_expectations_path, 'w') as fh: |
| 180 json.dump(expectations_dict, fh) |
| 122 | 181 |
| 123 def tearDown(self): | 182 def tearDown(self): |
| 183 shutil.rmtree(self._expectations_dir) |
| 124 shutil.rmtree(self._input_skp_dir) | 184 shutil.rmtree(self._input_skp_dir) |
| 125 shutil.rmtree(self._temp_dir) | 185 shutil.rmtree(self._temp_dir) |
| 126 | 186 |
| 127 def test_tiled_whole_image(self): | 187 def test_tiled_whole_image(self): |
| 128 """Run render_pictures with tiles and --writeWholeImage flag. | 188 """Run render_pictures with tiles and --writeWholeImage flag. |
| 129 | 189 |
| 130 TODO(epoger): This test generates undesired results! The JSON summary | 190 TODO(epoger): This test generates undesired results! The JSON summary |
| 131 includes both whole-image and tiled-images (as it should), but only | 191 includes both whole-image and tiled-images (as it should), but only |
| 132 whole-images are written out to disk. See http://skbug.com/2463 | 192 whole-images are written out to disk. See http://skbug.com/2463 |
| 133 | 193 |
| 134 TODO(epoger): I noticed that when this is run without --writePath being | 194 TODO(epoger): I noticed that when this is run without --writePath being |
| 135 specified, this test writes red_skp.png and green_skp.png to the current | 195 specified, this test writes red_skp.png and green_skp.png to the current |
| 136 directory. We should fix that... if --writePath is not specified, this | 196 directory. We should fix that... if --writePath is not specified, this |
| 137 probably shouldn't write out red_skp.png and green_skp.png at all! | 197 probably shouldn't write out red_skp.png and green_skp.png at all! |
| 138 See http://skbug.com/2464 | 198 See http://skbug.com/2464 |
| 139 """ | 199 """ |
| 140 output_json_path = os.path.join(self._temp_dir, 'output.json') | 200 output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
| 141 self._generate_skps() | 201 self._generate_skps() |
| 142 self._run_render_pictures(['-r', self._input_skp_dir, | 202 self._run_render_pictures([ |
| 143 '--bbh', 'grid', '256', '256', | 203 '-r', self._input_skp_dir, |
| 144 '--mode', 'tile', '256', '256', | 204 '--bbh', 'grid', '256', '256', |
| 145 '--writeJsonSummaryPath', output_json_path, | 205 '--mode', 'tile', '256', '256', |
| 146 '--writePath', self._temp_dir, | 206 '--readJsonSummaryPath', self._standard_expectations_path, |
| 147 '--writeWholeImage']) | 207 '--writeJsonSummaryPath', output_json_path, |
| 208 '--writePath', self._temp_dir, |
| 209 '--writeWholeImage']) |
| 148 expected_summary_dict = { | 210 expected_summary_dict = { |
| 149 "header" : EXPECTED_HEADER_CONTENTS, | 211 "header" : EXPECTED_HEADER_CONTENTS, |
| 150 "actual-results" : { | 212 "actual-results" : { |
| 151 "red.skp": { | 213 "red.skp": { |
| 152 "tiled-images": RED_TILES, | 214 "tiled-images": RED_TILES, |
| 153 "whole-image": RED_WHOLEIMAGE, | 215 "whole-image": RED_WHOLEIMAGE, |
| 154 }, | 216 }, |
| 155 "green.skp": { | 217 "green.skp": { |
| 156 "tiled-images": GREEN_TILES, | 218 "tiled-images": GREEN_TILES, |
| 157 "whole-image": GREEN_WHOLEIMAGE, | 219 "whole-image": GREEN_WHOLEIMAGE, |
| 158 } | 220 } |
| 159 } | 221 } |
| 160 } | 222 } |
| 161 self._assert_json_contents(output_json_path, expected_summary_dict) | 223 self._assert_json_contents(output_json_path, expected_summary_dict) |
| 162 self._assert_directory_contents( | 224 self._assert_directory_contents( |
| 163 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) | 225 self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json']) |
| 164 | 226 |
| 165 def test_untiled(self): | 227 def test_untiled(self): |
| 166 """Run without tiles.""" | 228 """Run without tiles.""" |
| 167 output_json_path = os.path.join(self._temp_dir, 'output.json') | 229 output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
| 168 self._generate_skps() | 230 self._generate_skps() |
| 169 self._run_render_pictures(['-r', self._input_skp_dir, | 231 self._run_render_pictures([ |
| 170 '--writePath', self._temp_dir, | 232 '-r', self._input_skp_dir, |
| 171 '--writeJsonSummaryPath', output_json_path]) | 233 '--readJsonSummaryPath', self._standard_expectations_path, |
| 234 '--writePath', self._temp_dir, |
| 235 '--writeJsonSummaryPath', output_json_path]) |
| 172 expected_summary_dict = { | 236 expected_summary_dict = { |
| 173 "header" : EXPECTED_HEADER_CONTENTS, | 237 "header" : EXPECTED_HEADER_CONTENTS, |
| 174 "actual-results" : { | 238 "actual-results" : { |
| 175 "red.skp": { | 239 "red.skp": { |
| 176 "whole-image": RED_WHOLEIMAGE, | 240 "whole-image": RED_WHOLEIMAGE, |
| 177 }, | 241 }, |
| 178 "green.skp": { | 242 "green.skp": { |
| 179 "whole-image": GREEN_WHOLEIMAGE, | 243 "whole-image": GREEN_WHOLEIMAGE, |
| 180 } | 244 } |
| 181 } | 245 } |
| 182 } | 246 } |
| 183 self._assert_json_contents(output_json_path, expected_summary_dict) | 247 self._assert_json_contents(output_json_path, expected_summary_dict) |
| 184 self._assert_directory_contents( | 248 self._assert_directory_contents( |
| 185 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) | 249 self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json']) |
| 186 | 250 |
| 187 def test_untiled_writeChecksumBasedFilenames(self): | 251 def test_untiled_writeChecksumBasedFilenames(self): |
| 188 """Same as test_untiled, but with --writeChecksumBasedFilenames.""" | 252 """Same as test_untiled, but with --writeChecksumBasedFilenames.""" |
| 189 output_json_path = os.path.join(self._temp_dir, 'output.json') | 253 output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
| 190 self._generate_skps() | 254 self._generate_skps() |
| 191 self._run_render_pictures(['-r', self._input_skp_dir, | 255 self._run_render_pictures(['-r', self._input_skp_dir, |
| 192 '--writeChecksumBasedFilenames', | 256 '--writeChecksumBasedFilenames', |
| 193 '--writePath', self._temp_dir, | 257 '--writePath', self._temp_dir, |
| 194 '--writeJsonSummaryPath', output_json_path]) | 258 '--writeJsonSummaryPath', output_json_path]) |
| 195 expected_summary_dict = { | 259 expected_summary_dict = { |
| 196 "header" : EXPECTED_HEADER_CONTENTS, | 260 "header" : EXPECTED_HEADER_CONTENTS, |
| 197 "actual-results" : { | 261 "actual-results" : { |
| 198 "red.skp": { | 262 "red.skp": { |
| 199 # Manually verified: 640x400 red rectangle with black border | 263 # Manually verified: 640x400 red rectangle with black border |
| (...skipping 10 matching lines...) Expand all Loading... |
| 210 "checksumAlgorithm" : "bitmap-64bitMD5", | 274 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 211 "checksumValue" : 8891695120562235492, | 275 "checksumValue" : 8891695120562235492, |
| 212 "comparisonResult" : "no-comparison", | 276 "comparisonResult" : "no-comparison", |
| 213 "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.
png", | 277 "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.
png", |
| 214 }, | 278 }, |
| 215 } | 279 } |
| 216 } | 280 } |
| 217 } | 281 } |
| 218 self._assert_json_contents(output_json_path, expected_summary_dict) | 282 self._assert_json_contents(output_json_path, expected_summary_dict) |
| 219 self._assert_directory_contents(self._temp_dir, [ | 283 self._assert_directory_contents(self._temp_dir, [ |
| 220 'red_skp', 'green_skp', 'output.json']) | 284 'red_skp', 'green_skp', 'actuals.json']) |
| 221 self._assert_directory_contents( | 285 self._assert_directory_contents( |
| 222 os.path.join(self._temp_dir, 'red_skp'), | 286 os.path.join(self._temp_dir, 'red_skp'), |
| 223 ['bitmap-64bitMD5_11092453015575919668.png']) | 287 ['bitmap-64bitMD5_11092453015575919668.png']) |
| 224 self._assert_directory_contents( | 288 self._assert_directory_contents( |
| 225 os.path.join(self._temp_dir, 'green_skp'), | 289 os.path.join(self._temp_dir, 'green_skp'), |
| 226 ['bitmap-64bitMD5_8891695120562235492.png']) | 290 ['bitmap-64bitMD5_8891695120562235492.png']) |
| 227 | 291 |
| 228 def test_untiled_validate(self): | 292 def test_untiled_validate(self): |
| 229 """Same as test_untiled, but with --validate.""" | 293 """Same as test_untiled, but with --validate.""" |
| 230 output_json_path = os.path.join(self._temp_dir, 'output.json') | 294 output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
| 231 self._generate_skps() | 295 self._generate_skps() |
| 232 self._run_render_pictures(['-r', self._input_skp_dir, | 296 self._run_render_pictures([ |
| 233 '--validate', | 297 '-r', self._input_skp_dir, |
| 234 '--writePath', self._temp_dir, | 298 '--readJsonSummaryPath', self._standard_expectations_path, |
| 235 '--writeJsonSummaryPath', output_json_path]) | 299 '--validate', |
| 300 '--writePath', self._temp_dir, |
| 301 '--writeJsonSummaryPath', output_json_path]) |
| 236 expected_summary_dict = { | 302 expected_summary_dict = { |
| 237 "header" : EXPECTED_HEADER_CONTENTS, | 303 "header" : EXPECTED_HEADER_CONTENTS, |
| 238 "actual-results" : { | 304 "actual-results" : { |
| 239 "red.skp": { | 305 "red.skp": { |
| 240 "whole-image": RED_WHOLEIMAGE, | 306 "whole-image": RED_WHOLEIMAGE, |
| 241 }, | 307 }, |
| 242 "green.skp": { | 308 "green.skp": { |
| 243 "whole-image": GREEN_WHOLEIMAGE, | 309 "whole-image": GREEN_WHOLEIMAGE, |
| 244 } | 310 } |
| 245 } | 311 } |
| 246 } | 312 } |
| 247 self._assert_json_contents(output_json_path, expected_summary_dict) | 313 self._assert_json_contents(output_json_path, expected_summary_dict) |
| 248 self._assert_directory_contents( | 314 self._assert_directory_contents( |
| 249 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) | 315 self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json']) |
| 250 | 316 |
| 251 def test_untiled_without_writePath(self): | 317 def test_untiled_without_writePath(self): |
| 252 """Same as test_untiled, but without --writePath.""" | 318 """Same as test_untiled, but without --writePath.""" |
| 253 output_json_path = os.path.join(self._temp_dir, 'output.json') | 319 output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
| 254 self._generate_skps() | 320 self._generate_skps() |
| 255 self._run_render_pictures(['-r', self._input_skp_dir, | 321 self._run_render_pictures([ |
| 256 '--writeJsonSummaryPath', output_json_path]) | 322 '-r', self._input_skp_dir, |
| 323 '--readJsonSummaryPath', self._standard_expectations_path, |
| 324 '--writeJsonSummaryPath', output_json_path]) |
| 257 expected_summary_dict = { | 325 expected_summary_dict = { |
| 258 "header" : EXPECTED_HEADER_CONTENTS, | 326 "header" : EXPECTED_HEADER_CONTENTS, |
| 259 "actual-results" : { | 327 "actual-results" : { |
| 260 "red.skp": { | 328 "red.skp": { |
| 261 "whole-image": RED_WHOLEIMAGE, | 329 "whole-image": RED_WHOLEIMAGE, |
| 262 }, | 330 }, |
| 263 "green.skp": { | 331 "green.skp": { |
| 264 "whole-image": GREEN_WHOLEIMAGE, | 332 "whole-image": GREEN_WHOLEIMAGE, |
| 265 } | 333 } |
| 266 } | 334 } |
| 267 } | 335 } |
| 268 self._assert_json_contents(output_json_path, expected_summary_dict) | 336 self._assert_json_contents(output_json_path, expected_summary_dict) |
| 269 | 337 |
| 270 def test_tiled(self): | 338 def test_tiled(self): |
| 271 """Generate individual tiles.""" | 339 """Generate individual tiles.""" |
| 272 output_json_path = os.path.join(self._temp_dir, 'output.json') | 340 output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
| 273 self._generate_skps() | 341 self._generate_skps() |
| 274 self._run_render_pictures(['-r', self._input_skp_dir, | 342 self._run_render_pictures([ |
| 275 '--bbh', 'grid', '256', '256', | 343 '-r', self._input_skp_dir, |
| 276 '--mode', 'tile', '256', '256', | 344 '--bbh', 'grid', '256', '256', |
| 277 '--writePath', self._temp_dir, | 345 '--mode', 'tile', '256', '256', |
| 278 '--writeJsonSummaryPath', output_json_path]) | 346 '--readJsonSummaryPath', self._standard_expectations_path, |
| 347 '--writePath', self._temp_dir, |
| 348 '--writeJsonSummaryPath', output_json_path]) |
| 279 expected_summary_dict = { | 349 expected_summary_dict = { |
| 280 "header" : EXPECTED_HEADER_CONTENTS, | 350 "header" : EXPECTED_HEADER_CONTENTS, |
| 281 "actual-results" : { | 351 "actual-results" : { |
| 282 "red.skp": { | 352 "red.skp": { |
| 283 "tiled-images": RED_TILES, | 353 "tiled-images": RED_TILES, |
| 284 }, | 354 }, |
| 285 "green.skp": { | 355 "green.skp": { |
| 286 "tiled-images": GREEN_TILES, | 356 "tiled-images": GREEN_TILES, |
| 287 } | 357 } |
| 288 } | 358 } |
| 289 } | 359 } |
| 290 self._assert_json_contents(output_json_path, expected_summary_dict) | 360 self._assert_json_contents(output_json_path, expected_summary_dict) |
| 291 self._assert_directory_contents( | 361 self._assert_directory_contents( |
| 292 self._temp_dir, | 362 self._temp_dir, |
| 293 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', | 363 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', |
| 294 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', | 364 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', |
| 295 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png', | 365 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png', |
| 296 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png', | 366 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png', |
| 297 'output.json']) | 367 'actuals.json']) |
| 298 | 368 |
| 299 def test_tiled_writeChecksumBasedFilenames(self): | 369 def test_tiled_writeChecksumBasedFilenames(self): |
| 300 """Same as test_tiled, but with --writeChecksumBasedFilenames.""" | 370 """Same as test_tiled, but with --writeChecksumBasedFilenames.""" |
| 301 output_json_path = os.path.join(self._temp_dir, 'output.json') | 371 output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
| 302 self._generate_skps() | 372 self._generate_skps() |
| 303 self._run_render_pictures(['-r', self._input_skp_dir, | 373 self._run_render_pictures(['-r', self._input_skp_dir, |
| 304 '--bbh', 'grid', '256', '256', | 374 '--bbh', 'grid', '256', '256', |
| 305 '--mode', 'tile', '256', '256', | 375 '--mode', 'tile', '256', '256', |
| 306 '--writeChecksumBasedFilenames', | 376 '--writeChecksumBasedFilenames', |
| 307 '--writePath', self._temp_dir, | 377 '--writePath', self._temp_dir, |
| 308 '--writeJsonSummaryPath', output_json_path]) | 378 '--writeJsonSummaryPath', output_json_path]) |
| 309 expected_summary_dict = { | 379 expected_summary_dict = { |
| 310 "header" : EXPECTED_HEADER_CONTENTS, | 380 "header" : EXPECTED_HEADER_CONTENTS, |
| 311 "actual-results" : { | 381 "actual-results" : { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 "checksumAlgorithm" : "bitmap-64bitMD5", | 448 "checksumAlgorithm" : "bitmap-64bitMD5", |
| 379 "checksumValue" : 10673669813016809363, | 449 "checksumValue" : 10673669813016809363, |
| 380 "comparisonResult" : "no-comparison", | 450 "comparisonResult" : "no-comparison", |
| 381 "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363
.png", | 451 "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363
.png", |
| 382 }], | 452 }], |
| 383 } | 453 } |
| 384 } | 454 } |
| 385 } | 455 } |
| 386 self._assert_json_contents(output_json_path, expected_summary_dict) | 456 self._assert_json_contents(output_json_path, expected_summary_dict) |
| 387 self._assert_directory_contents(self._temp_dir, [ | 457 self._assert_directory_contents(self._temp_dir, [ |
| 388 'red_skp', 'green_skp', 'output.json']) | 458 'red_skp', 'green_skp', 'actuals.json']) |
| 389 self._assert_directory_contents( | 459 self._assert_directory_contents( |
| 390 os.path.join(self._temp_dir, 'red_skp'), | 460 os.path.join(self._temp_dir, 'red_skp'), |
| 391 ['bitmap-64bitMD5_5815827069051002745.png', | 461 ['bitmap-64bitMD5_5815827069051002745.png', |
| 392 'bitmap-64bitMD5_9323613075234140270.png', | 462 'bitmap-64bitMD5_9323613075234140270.png', |
| 393 'bitmap-64bitMD5_16670399404877552232.png', | 463 'bitmap-64bitMD5_16670399404877552232.png', |
| 394 'bitmap-64bitMD5_2507897274083364964.png', | 464 'bitmap-64bitMD5_2507897274083364964.png', |
| 395 'bitmap-64bitMD5_7325267995523877959.png', | 465 'bitmap-64bitMD5_7325267995523877959.png', |
| 396 'bitmap-64bitMD5_2181381724594493116.png']) | 466 'bitmap-64bitMD5_2181381724594493116.png']) |
| 397 self._assert_directory_contents( | 467 self._assert_directory_contents( |
| 398 os.path.join(self._temp_dir, 'green_skp'), | 468 os.path.join(self._temp_dir, 'green_skp'), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 Args: | 515 Args: |
| 446 dir_path: Path to a directory on local disk. | 516 dir_path: Path to a directory on local disk. |
| 447 expected_filenames: Set containing the expected filenames within the dir. | 517 expected_filenames: Set containing the expected filenames within the dir. |
| 448 | 518 |
| 449 Raises: | 519 Raises: |
| 450 AssertionError: contents of the directory are not identical to | 520 AssertionError: contents of the directory are not identical to |
| 451 expected_filenames. | 521 expected_filenames. |
| 452 """ | 522 """ |
| 453 self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames)) | 523 self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames)) |
| 454 | 524 |
| 455 | |
| 456 def _assert_json_contents(self, json_path, expected_dict): | 525 def _assert_json_contents(self, json_path, expected_dict): |
| 457 """Asserts that contents of a JSON file are identical to expected_dict. | 526 """Asserts that contents of a JSON file are identical to expected_dict. |
| 458 | 527 |
| 459 Args: | 528 Args: |
| 460 json_path: Path to a JSON file. | 529 json_path: Path to a JSON file. |
| 461 expected_dict: Dictionary indicating the expected contents of the JSON | 530 expected_dict: Dictionary indicating the expected contents of the JSON |
| 462 file. | 531 file. |
| 463 | 532 |
| 464 Raises: | 533 Raises: |
| 465 AssertionError: contents of the JSON file are not identical to | 534 AssertionError: contents of the JSON file are not identical to |
| 466 expected_dict. | 535 expected_dict. |
| 467 """ | 536 """ |
| 468 file_contents = open(json_path, 'r').read() | 537 prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True, |
| 469 actual_dict = json.loads(file_contents) | 538 indent=2) |
| 470 self.assertEqual(actual_dict, expected_dict) | 539 with open(json_path, 'r') as fh: |
| 540 prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True, |
| 541 indent=2) |
| 542 self.assertMultiLineEqual(prettyprinted_expected_dict, |
| 543 prettyprinted_json_dict) |
| 471 | 544 |
| 472 | 545 |
| 473 def main(): | 546 def main(): |
| 474 base_unittest.main(RenderPicturesTest) | 547 base_unittest.main(RenderPicturesTest) |
| 475 | 548 |
| 476 | 549 |
| 477 if __name__ == '__main__': | 550 if __name__ == '__main__': |
| 478 main() | 551 main() |
| OLD | NEW |