Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: tools/tests/render_pictures_test.py

Issue 273783004: add --readJsonSummaryPath to render_pictures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make BitmapAndDigest lazily compute the bitmap Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« tools/PictureRenderer.cpp ('K') | « tools/render_pictures_main.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 copy
13 import json 14 import json
14 import os 15 import os
15 import shutil 16 import shutil
16 import tempfile 17 import tempfile
17 18
18 # Imports from within Skia 19 # Imports from within Skia
19 import base_unittest 20 import base_unittest
20 21
21 # Maximum length of text diffs to show when tests fail 22 # Maximum length of text diffs to show when tests fail
22 MAX_DIFF_LENGTH = 30000 23 MAX_DIFF_LENGTH = 30000
23 24
24 EXPECTED_HEADER_CONTENTS = { 25 EXPECTED_HEADER_CONTENTS = {
25 "type" : "ChecksummedImages", 26 "type" : "ChecksummedImages",
26 "revision" : 1, 27 "revision" : 1,
27 } 28 }
28 29
29 # Manually verified: 640x400 red rectangle with black border 30 # Manually verified: 640x400 red rectangle with black border
31 # Standard expectations will be set up in such a way that this image fails
32 # the comparison.
30 RED_WHOLEIMAGE = { 33 RED_WHOLEIMAGE = {
31 "checksumAlgorithm" : "bitmap-64bitMD5", 34 "checksumAlgorithm" : "bitmap-64bitMD5",
32 "checksumValue" : 11092453015575919668, 35 "checksumValue" : 11092453015575919668,
33 "comparisonResult" : "no-comparison", 36 "comparisonResult" : "failed",
34 "filepath" : "red_skp.png", 37 "filepath" : "red_skp.png",
35 } 38 }
36 39
37 # Manually verified: 640x400 green rectangle with black border 40 # Manually verified: 640x400 green rectangle with black border
41 # Standard expectations will be set up in such a way that this image passes
42 # the comparison.
38 GREEN_WHOLEIMAGE = { 43 GREEN_WHOLEIMAGE = {
39 "checksumAlgorithm" : "bitmap-64bitMD5", 44 "checksumAlgorithm" : "bitmap-64bitMD5",
40 "checksumValue" : 8891695120562235492, 45 "checksumValue" : 8891695120562235492,
41 "comparisonResult" : "no-comparison", 46 "comparisonResult" : "succeeded",
42 "filepath" : "green_skp.png", 47 "filepath" : "green_skp.png",
43 } 48 }
44 49
45 # Manually verified these 6 images, all 256x256 tiles, 50 # Manually verified these 6 images, all 256x256 tiles,
46 # consistent with a tiled version of the 640x400 red rect 51 # consistent with a tiled version of the 640x400 red rect
47 # with black borders. 52 # with black borders.
53 # Standard expectations will be set up in such a way that these images fail
54 # the comparison.
48 RED_TILES = [{ 55 RED_TILES = [{
49 "checksumAlgorithm" : "bitmap-64bitMD5", 56 "checksumAlgorithm" : "bitmap-64bitMD5",
50 "checksumValue" : 5815827069051002745, 57 "checksumValue" : 5815827069051002745,
51 "comparisonResult" : "no-comparison", 58 "comparisonResult" : "failed",
52 "filepath" : "red_skp-tile0.png", 59 "filepath" : "red_skp-tile0.png",
53 },{ 60 },{
54 "checksumAlgorithm" : "bitmap-64bitMD5", 61 "checksumAlgorithm" : "bitmap-64bitMD5",
55 "checksumValue" : 9323613075234140270, 62 "checksumValue" : 9323613075234140270,
56 "comparisonResult" : "no-comparison", 63 "comparisonResult" : "failed",
57 "filepath" : "red_skp-tile1.png", 64 "filepath" : "red_skp-tile1.png",
58 }, { 65 }, {
59 "checksumAlgorithm" : "bitmap-64bitMD5", 66 "checksumAlgorithm" : "bitmap-64bitMD5",
60 "checksumValue" : 16670399404877552232, 67 "checksumValue" : 16670399404877552232,
61 "comparisonResult" : "no-comparison", 68 "comparisonResult" : "failed",
62 "filepath" : "red_skp-tile2.png", 69 "filepath" : "red_skp-tile2.png",
63 }, { 70 }, {
64 "checksumAlgorithm" : "bitmap-64bitMD5", 71 "checksumAlgorithm" : "bitmap-64bitMD5",
65 "checksumValue" : 2507897274083364964, 72 "checksumValue" : 2507897274083364964,
66 "comparisonResult" : "no-comparison", 73 "comparisonResult" : "failed",
67 "filepath" : "red_skp-tile3.png", 74 "filepath" : "red_skp-tile3.png",
68 }, { 75 }, {
69 "checksumAlgorithm" : "bitmap-64bitMD5", 76 "checksumAlgorithm" : "bitmap-64bitMD5",
70 "checksumValue" : 7325267995523877959, 77 "checksumValue" : 7325267995523877959,
71 "comparisonResult" : "no-comparison", 78 "comparisonResult" : "failed",
72 "filepath" : "red_skp-tile4.png", 79 "filepath" : "red_skp-tile4.png",
73 }, { 80 }, {
74 "checksumAlgorithm" : "bitmap-64bitMD5", 81 "checksumAlgorithm" : "bitmap-64bitMD5",
75 "checksumValue" : 2181381724594493116, 82 "checksumValue" : 2181381724594493116,
76 "comparisonResult" : "no-comparison", 83 "comparisonResult" : "failed",
77 "filepath" : "red_skp-tile5.png", 84 "filepath" : "red_skp-tile5.png",
78 }] 85 }]
79 86
80 # Manually verified these 6 images, all 256x256 tiles, 87 # Manually verified these 6 images, all 256x256 tiles,
81 # consistent with a tiled version of the 640x400 green rect 88 # consistent with a tiled version of the 640x400 green rect
82 # with black borders. 89 # with black borders.
90 # Standard expectations will be set up in such a way that these images pass
91 # the comparison.
83 GREEN_TILES = [{ 92 GREEN_TILES = [{
84 "checksumAlgorithm" : "bitmap-64bitMD5", 93 "checksumAlgorithm" : "bitmap-64bitMD5",
85 "checksumValue" : 12587324416545178013, 94 "checksumValue" : 12587324416545178013,
86 "comparisonResult" : "no-comparison", 95 "comparisonResult" : "succeeded",
87 "filepath" : "green_skp-tile0.png", 96 "filepath" : "green_skp-tile0.png",
88 }, { 97 }, {
89 "checksumAlgorithm" : "bitmap-64bitMD5", 98 "checksumAlgorithm" : "bitmap-64bitMD5",
90 "checksumValue" : 7624374914829746293, 99 "checksumValue" : 7624374914829746293,
91 "comparisonResult" : "no-comparison", 100 "comparisonResult" : "succeeded",
92 "filepath" : "green_skp-tile1.png", 101 "filepath" : "green_skp-tile1.png",
93 }, { 102 }, {
94 "checksumAlgorithm" : "bitmap-64bitMD5", 103 "checksumAlgorithm" : "bitmap-64bitMD5",
95 "checksumValue" : 5686489729535631913, 104 "checksumValue" : 5686489729535631913,
96 "comparisonResult" : "no-comparison", 105 "comparisonResult" : "succeeded",
97 "filepath" : "green_skp-tile2.png", 106 "filepath" : "green_skp-tile2.png",
98 }, { 107 }, {
99 "checksumAlgorithm" : "bitmap-64bitMD5", 108 "checksumAlgorithm" : "bitmap-64bitMD5",
100 "checksumValue" : 7980646035555096146, 109 "checksumValue" : 7980646035555096146,
101 "comparisonResult" : "no-comparison", 110 "comparisonResult" : "succeeded",
102 "filepath" : "green_skp-tile3.png", 111 "filepath" : "green_skp-tile3.png",
103 }, { 112 }, {
104 "checksumAlgorithm" : "bitmap-64bitMD5", 113 "checksumAlgorithm" : "bitmap-64bitMD5",
105 "checksumValue" : 17817086664365875131, 114 "checksumValue" : 17817086664365875131,
106 "comparisonResult" : "no-comparison", 115 "comparisonResult" : "succeeded",
107 "filepath" : "green_skp-tile4.png", 116 "filepath" : "green_skp-tile4.png",
108 }, { 117 }, {
109 "checksumAlgorithm" : "bitmap-64bitMD5", 118 "checksumAlgorithm" : "bitmap-64bitMD5",
110 "checksumValue" : 10673669813016809363, 119 "checksumValue" : 10673669813016809363,
111 "comparisonResult" : "no-comparison", 120 "comparisonResult" : "succeeded",
112 "filepath" : "green_skp-tile5.png", 121 "filepath" : "green_skp-tile5.png",
113 }] 122 }]
114 123
115 124
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
116 class RenderPicturesTest(base_unittest.TestCase): 153 class RenderPicturesTest(base_unittest.TestCase):
117 154
118 def setUp(self): 155 def setUp(self):
156 self.maxDiff = MAX_DIFF_LENGTH
157 self._expectations_dir = tempfile.mkdtemp()
119 self._input_skp_dir = tempfile.mkdtemp() 158 self._input_skp_dir = tempfile.mkdtemp()
120 self._temp_dir = tempfile.mkdtemp() 159 self._temp_dir = tempfile.mkdtemp()
121 self.maxDiff = MAX_DIFF_LENGTH
122 160
123 def tearDown(self): 161 def tearDown(self):
162 shutil.rmtree(self._expectations_dir)
124 shutil.rmtree(self._input_skp_dir) 163 shutil.rmtree(self._input_skp_dir)
125 shutil.rmtree(self._temp_dir) 164 shutil.rmtree(self._temp_dir)
126 165
127 def test_tiled_whole_image(self): 166 def test_tiled_whole_image(self):
128 """Run render_pictures with tiles and --writeWholeImage flag. 167 """Run render_pictures with tiles and --writeWholeImage flag.
129 168
130 TODO(epoger): This test generates undesired results! The JSON summary 169 TODO(epoger): This test generates undesired results! The JSON summary
131 includes both whole-image and tiled-images (as it should), but only 170 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 171 whole-images are written out to disk. See http://skbug.com/2463
133 172
134 TODO(epoger): I noticed that when this is run without --writePath being 173 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 174 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 175 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! 176 probably shouldn't write out red_skp.png and green_skp.png at all!
138 See http://skbug.com/2464 177 See http://skbug.com/2464
139 """ 178 """
140 output_json_path = os.path.join(self._temp_dir, 'output.json') 179 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
141 self._generate_skps() 180 self._generate_skps()
142 self._run_render_pictures(['-r', self._input_skp_dir, 181 expectations_path = self._create_expectations()
143 '--bbh', 'grid', '256', '256', 182 self._run_render_pictures([
144 '--mode', 'tile', '256', '256', 183 '-r', self._input_skp_dir,
145 '--writeJsonSummaryPath', output_json_path, 184 '--bbh', 'grid', '256', '256',
146 '--writePath', self._temp_dir, 185 '--mode', 'tile', '256', '256',
147 '--writeWholeImage']) 186 '--readJsonSummaryPath', expectations_path,
187 '--writeJsonSummaryPath', output_json_path,
188 '--writePath', self._temp_dir,
189 '--writeWholeImage'])
148 expected_summary_dict = { 190 expected_summary_dict = {
149 "header" : EXPECTED_HEADER_CONTENTS, 191 "header" : EXPECTED_HEADER_CONTENTS,
150 "actual-results" : { 192 "actual-results" : {
151 "red.skp": { 193 "red.skp": {
152 "tiled-images": RED_TILES, 194 "tiled-images": RED_TILES,
153 "whole-image": RED_WHOLEIMAGE, 195 "whole-image": RED_WHOLEIMAGE,
154 }, 196 },
155 "green.skp": { 197 "green.skp": {
156 "tiled-images": GREEN_TILES, 198 "tiled-images": GREEN_TILES,
157 "whole-image": GREEN_WHOLEIMAGE, 199 "whole-image": GREEN_WHOLEIMAGE,
158 } 200 }
159 } 201 }
160 } 202 }
161 self._assert_json_contents(output_json_path, expected_summary_dict) 203 self._assert_json_contents(output_json_path, expected_summary_dict)
162 self._assert_directory_contents( 204 self._assert_directory_contents(
163 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) 205 self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json'])
206
207 def test_missing_tile_and_whole_image(self):
208 """test_tiled_whole_image, but missing expectations for some images.
209 """
210 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
211 self._generate_skps()
212 expectations_path = self._create_expectations(missing_some_images=True)
213 self._run_render_pictures([
214 '-r', self._input_skp_dir,
215 '--bbh', 'grid', '256', '256',
216 '--mode', 'tile', '256', '256',
217 '--readJsonSummaryPath', expectations_path,
218 '--writeJsonSummaryPath', output_json_path,
219 '--writePath', self._temp_dir,
220 '--writeWholeImage'])
221 modified_red_tiles = copy.deepcopy(RED_TILES)
222 modified_red_tiles[5]['comparisonResult'] = 'no-comparison'
223 expected_summary_dict = {
224 "header" : EXPECTED_HEADER_CONTENTS,
225 "actual-results" : {
226 "red.skp": {
227 "tiled-images": modified_red_tiles,
228 "whole-image": modified_dict(
229 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}),
230 },
231 "green.skp": {
232 "tiled-images": GREEN_TILES,
233 "whole-image": GREEN_WHOLEIMAGE,
234 }
235 }
236 }
237 self._assert_json_contents(output_json_path, expected_summary_dict)
164 238
165 def test_untiled(self): 239 def test_untiled(self):
166 """Run without tiles.""" 240 """Run without tiles."""
167 output_json_path = os.path.join(self._temp_dir, 'output.json') 241 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
168 self._generate_skps() 242 self._generate_skps()
169 self._run_render_pictures(['-r', self._input_skp_dir, 243 expectations_path = self._create_expectations()
170 '--writePath', self._temp_dir, 244 self._run_render_pictures([
171 '--writeJsonSummaryPath', output_json_path]) 245 '-r', self._input_skp_dir,
246 '--readJsonSummaryPath', expectations_path,
247 '--writePath', self._temp_dir,
248 '--writeJsonSummaryPath', output_json_path])
172 expected_summary_dict = { 249 expected_summary_dict = {
173 "header" : EXPECTED_HEADER_CONTENTS, 250 "header" : EXPECTED_HEADER_CONTENTS,
174 "actual-results" : { 251 "actual-results" : {
175 "red.skp": { 252 "red.skp": {
176 "whole-image": RED_WHOLEIMAGE, 253 "whole-image": RED_WHOLEIMAGE,
177 }, 254 },
178 "green.skp": { 255 "green.skp": {
179 "whole-image": GREEN_WHOLEIMAGE, 256 "whole-image": GREEN_WHOLEIMAGE,
180 } 257 }
181 } 258 }
182 } 259 }
183 self._assert_json_contents(output_json_path, expected_summary_dict) 260 self._assert_json_contents(output_json_path, expected_summary_dict)
184 self._assert_directory_contents( 261 self._assert_directory_contents(
185 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) 262 self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json'])
186 263
187 def test_untiled_writeChecksumBasedFilenames(self): 264 def test_untiled_writeChecksumBasedFilenames(self):
188 """Same as test_untiled, but with --writeChecksumBasedFilenames.""" 265 """Same as test_untiled, but with --writeChecksumBasedFilenames."""
189 output_json_path = os.path.join(self._temp_dir, 'output.json') 266 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
190 self._generate_skps() 267 self._generate_skps()
191 self._run_render_pictures(['-r', self._input_skp_dir, 268 self._run_render_pictures(['-r', self._input_skp_dir,
192 '--writeChecksumBasedFilenames', 269 '--writeChecksumBasedFilenames',
193 '--writePath', self._temp_dir, 270 '--writePath', self._temp_dir,
194 '--writeJsonSummaryPath', output_json_path]) 271 '--writeJsonSummaryPath', output_json_path])
195 expected_summary_dict = { 272 expected_summary_dict = {
196 "header" : EXPECTED_HEADER_CONTENTS, 273 "header" : EXPECTED_HEADER_CONTENTS,
197 "actual-results" : { 274 "actual-results" : {
198 "red.skp": { 275 "red.skp": {
199 # Manually verified: 640x400 red rectangle with black border 276 # Manually verified: 640x400 red rectangle with black border
(...skipping 10 matching lines...) Expand all
210 "checksumAlgorithm" : "bitmap-64bitMD5", 287 "checksumAlgorithm" : "bitmap-64bitMD5",
211 "checksumValue" : 8891695120562235492, 288 "checksumValue" : 8891695120562235492,
212 "comparisonResult" : "no-comparison", 289 "comparisonResult" : "no-comparison",
213 "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492. png", 290 "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492. png",
214 }, 291 },
215 } 292 }
216 } 293 }
217 } 294 }
218 self._assert_json_contents(output_json_path, expected_summary_dict) 295 self._assert_json_contents(output_json_path, expected_summary_dict)
219 self._assert_directory_contents(self._temp_dir, [ 296 self._assert_directory_contents(self._temp_dir, [
220 'red_skp', 'green_skp', 'output.json']) 297 'red_skp', 'green_skp', 'actuals.json'])
221 self._assert_directory_contents( 298 self._assert_directory_contents(
222 os.path.join(self._temp_dir, 'red_skp'), 299 os.path.join(self._temp_dir, 'red_skp'),
223 ['bitmap-64bitMD5_11092453015575919668.png']) 300 ['bitmap-64bitMD5_11092453015575919668.png'])
224 self._assert_directory_contents( 301 self._assert_directory_contents(
225 os.path.join(self._temp_dir, 'green_skp'), 302 os.path.join(self._temp_dir, 'green_skp'),
226 ['bitmap-64bitMD5_8891695120562235492.png']) 303 ['bitmap-64bitMD5_8891695120562235492.png'])
227 304
228 def test_untiled_validate(self): 305 def test_untiled_validate(self):
229 """Same as test_untiled, but with --validate.""" 306 """Same as test_untiled, but with --validate."""
230 output_json_path = os.path.join(self._temp_dir, 'output.json') 307 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
231 self._generate_skps() 308 self._generate_skps()
232 self._run_render_pictures(['-r', self._input_skp_dir, 309 expectations_path = self._create_expectations()
233 '--validate', 310 self._run_render_pictures([
234 '--writePath', self._temp_dir, 311 '-r', self._input_skp_dir,
235 '--writeJsonSummaryPath', output_json_path]) 312 '--readJsonSummaryPath', expectations_path,
313 '--validate',
314 '--writePath', self._temp_dir,
315 '--writeJsonSummaryPath', output_json_path])
236 expected_summary_dict = { 316 expected_summary_dict = {
237 "header" : EXPECTED_HEADER_CONTENTS, 317 "header" : EXPECTED_HEADER_CONTENTS,
238 "actual-results" : { 318 "actual-results" : {
239 "red.skp": { 319 "red.skp": {
240 "whole-image": RED_WHOLEIMAGE, 320 "whole-image": RED_WHOLEIMAGE,
241 }, 321 },
242 "green.skp": { 322 "green.skp": {
243 "whole-image": GREEN_WHOLEIMAGE, 323 "whole-image": GREEN_WHOLEIMAGE,
244 } 324 }
245 } 325 }
246 } 326 }
247 self._assert_json_contents(output_json_path, expected_summary_dict) 327 self._assert_json_contents(output_json_path, expected_summary_dict)
248 self._assert_directory_contents( 328 self._assert_directory_contents(
249 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) 329 self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json'])
250 330
251 def test_untiled_without_writePath(self): 331 def test_untiled_without_writePath(self):
252 """Same as test_untiled, but without --writePath.""" 332 """Same as test_untiled, but without --writePath."""
253 output_json_path = os.path.join(self._temp_dir, 'output.json') 333 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
254 self._generate_skps() 334 self._generate_skps()
255 self._run_render_pictures(['-r', self._input_skp_dir, 335 expectations_path = self._create_expectations()
256 '--writeJsonSummaryPath', output_json_path]) 336 self._run_render_pictures([
337 '-r', self._input_skp_dir,
338 '--readJsonSummaryPath', expectations_path,
339 '--writeJsonSummaryPath', output_json_path])
257 expected_summary_dict = { 340 expected_summary_dict = {
258 "header" : EXPECTED_HEADER_CONTENTS, 341 "header" : EXPECTED_HEADER_CONTENTS,
259 "actual-results" : { 342 "actual-results" : {
260 "red.skp": { 343 "red.skp": {
261 "whole-image": RED_WHOLEIMAGE, 344 "whole-image": RED_WHOLEIMAGE,
262 }, 345 },
263 "green.skp": { 346 "green.skp": {
264 "whole-image": GREEN_WHOLEIMAGE, 347 "whole-image": GREEN_WHOLEIMAGE,
265 } 348 }
266 } 349 }
267 } 350 }
268 self._assert_json_contents(output_json_path, expected_summary_dict) 351 self._assert_json_contents(output_json_path, expected_summary_dict)
269 352
270 def test_tiled(self): 353 def test_tiled(self):
271 """Generate individual tiles.""" 354 """Generate individual tiles."""
272 output_json_path = os.path.join(self._temp_dir, 'output.json') 355 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
273 self._generate_skps() 356 self._generate_skps()
274 self._run_render_pictures(['-r', self._input_skp_dir, 357 expectations_path = self._create_expectations()
275 '--bbh', 'grid', '256', '256', 358 self._run_render_pictures([
276 '--mode', 'tile', '256', '256', 359 '-r', self._input_skp_dir,
277 '--writePath', self._temp_dir, 360 '--bbh', 'grid', '256', '256',
278 '--writeJsonSummaryPath', output_json_path]) 361 '--mode', 'tile', '256', '256',
362 '--readJsonSummaryPath', expectations_path,
363 '--writePath', self._temp_dir,
364 '--writeJsonSummaryPath', output_json_path])
279 expected_summary_dict = { 365 expected_summary_dict = {
280 "header" : EXPECTED_HEADER_CONTENTS, 366 "header" : EXPECTED_HEADER_CONTENTS,
281 "actual-results" : { 367 "actual-results" : {
282 "red.skp": { 368 "red.skp": {
283 "tiled-images": RED_TILES, 369 "tiled-images": RED_TILES,
284 }, 370 },
285 "green.skp": { 371 "green.skp": {
286 "tiled-images": GREEN_TILES, 372 "tiled-images": GREEN_TILES,
287 } 373 }
288 } 374 }
289 } 375 }
290 self._assert_json_contents(output_json_path, expected_summary_dict) 376 self._assert_json_contents(output_json_path, expected_summary_dict)
291 self._assert_directory_contents( 377 self._assert_directory_contents(
292 self._temp_dir, 378 self._temp_dir,
293 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', 379 ['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', 380 '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', 381 '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', 382 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png',
297 'output.json']) 383 'actuals.json'])
298 384
299 def test_tiled_writeChecksumBasedFilenames(self): 385 def test_tiled_writeChecksumBasedFilenames(self):
300 """Same as test_tiled, but with --writeChecksumBasedFilenames.""" 386 """Same as test_tiled, but with --writeChecksumBasedFilenames."""
301 output_json_path = os.path.join(self._temp_dir, 'output.json') 387 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
302 self._generate_skps() 388 self._generate_skps()
303 self._run_render_pictures(['-r', self._input_skp_dir, 389 self._run_render_pictures(['-r', self._input_skp_dir,
304 '--bbh', 'grid', '256', '256', 390 '--bbh', 'grid', '256', '256',
305 '--mode', 'tile', '256', '256', 391 '--mode', 'tile', '256', '256',
306 '--writeChecksumBasedFilenames', 392 '--writeChecksumBasedFilenames',
307 '--writePath', self._temp_dir, 393 '--writePath', self._temp_dir,
308 '--writeJsonSummaryPath', output_json_path]) 394 '--writeJsonSummaryPath', output_json_path])
309 expected_summary_dict = { 395 expected_summary_dict = {
310 "header" : EXPECTED_HEADER_CONTENTS, 396 "header" : EXPECTED_HEADER_CONTENTS,
311 "actual-results" : { 397 "actual-results" : {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 "checksumAlgorithm" : "bitmap-64bitMD5", 464 "checksumAlgorithm" : "bitmap-64bitMD5",
379 "checksumValue" : 10673669813016809363, 465 "checksumValue" : 10673669813016809363,
380 "comparisonResult" : "no-comparison", 466 "comparisonResult" : "no-comparison",
381 "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363 .png", 467 "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363 .png",
382 }], 468 }],
383 } 469 }
384 } 470 }
385 } 471 }
386 self._assert_json_contents(output_json_path, expected_summary_dict) 472 self._assert_json_contents(output_json_path, expected_summary_dict)
387 self._assert_directory_contents(self._temp_dir, [ 473 self._assert_directory_contents(self._temp_dir, [
388 'red_skp', 'green_skp', 'output.json']) 474 'red_skp', 'green_skp', 'actuals.json'])
389 self._assert_directory_contents( 475 self._assert_directory_contents(
390 os.path.join(self._temp_dir, 'red_skp'), 476 os.path.join(self._temp_dir, 'red_skp'),
391 ['bitmap-64bitMD5_5815827069051002745.png', 477 ['bitmap-64bitMD5_5815827069051002745.png',
392 'bitmap-64bitMD5_9323613075234140270.png', 478 'bitmap-64bitMD5_9323613075234140270.png',
393 'bitmap-64bitMD5_16670399404877552232.png', 479 'bitmap-64bitMD5_16670399404877552232.png',
394 'bitmap-64bitMD5_2507897274083364964.png', 480 'bitmap-64bitMD5_2507897274083364964.png',
395 'bitmap-64bitMD5_7325267995523877959.png', 481 'bitmap-64bitMD5_7325267995523877959.png',
396 'bitmap-64bitMD5_2181381724594493116.png']) 482 'bitmap-64bitMD5_2181381724594493116.png'])
397 self._assert_directory_contents( 483 self._assert_directory_contents(
398 os.path.join(self._temp_dir, 'green_skp'), 484 os.path.join(self._temp_dir, 'green_skp'),
399 ['bitmap-64bitMD5_12587324416545178013.png', 485 ['bitmap-64bitMD5_12587324416545178013.png',
400 'bitmap-64bitMD5_7624374914829746293.png', 486 'bitmap-64bitMD5_7624374914829746293.png',
401 'bitmap-64bitMD5_5686489729535631913.png', 487 'bitmap-64bitMD5_5686489729535631913.png',
402 'bitmap-64bitMD5_7980646035555096146.png', 488 'bitmap-64bitMD5_7980646035555096146.png',
403 'bitmap-64bitMD5_17817086664365875131.png', 489 'bitmap-64bitMD5_17817086664365875131.png',
404 'bitmap-64bitMD5_10673669813016809363.png']) 490 'bitmap-64bitMD5_10673669813016809363.png'])
405 491
406 def _run_render_pictures(self, args): 492 def _run_render_pictures(self, args):
407 binary = self.find_path_to_program('render_pictures') 493 binary = self.find_path_to_program('render_pictures')
408 return self.run_command([binary, 494 return self.run_command([binary,
409 '--clone', '1', 495 '--clone', '1',
410 '--config', '8888', 496 '--config', '8888',
411 ] + args) 497 ] + args)
412 498
499 def _create_expectations(self, missing_some_images=False,
500 rel_path='expectations.json'):
501 """Creates expectations JSON file within self._expectations_dir .
502
503 Args:
504 missing_some_images: (bool) whether to remove expectations for a subset
505 of the images
506 rel_path: (string) relative path within self._expectations_dir to write
507 the expectations into
508
509 Returns: full path to the expectations file created.
510 """
511 expectations_dict = {
512 "header" : EXPECTED_HEADER_CONTENTS,
513 "expected-results" : {
514 # red.skp: these should fail the comparison
515 "red.skp": {
516 "tiled-images": modified_list_of_dicts(
517 RED_TILES, {'checksumValue': 11111}),
518 "whole-image": modified_dict(
519 RED_WHOLEIMAGE, {'checksumValue': 22222}),
520 },
521 # green.skp: these should pass the comparison
522 "green.skp": {
523 "tiled-images": GREEN_TILES,
524 "whole-image": GREEN_WHOLEIMAGE,
525 }
526 }
527 }
528 if missing_some_images:
529 del expectations_dict['expected-results']['red.skp']['whole-image']
530 del expectations_dict['expected-results']['red.skp']['tiled-images'][-1]
531 path = os.path.join(self._expectations_dir, rel_path)
532 with open(path, 'w') as fh:
533 json.dump(expectations_dict, fh)
534 return path
535
413 def _generate_skps(self): 536 def _generate_skps(self):
414 """Runs the skpmaker binary to generate files in self._input_skp_dir.""" 537 """Runs the skpmaker binary to generate files in self._input_skp_dir."""
415 self._run_skpmaker( 538 self._run_skpmaker(
416 output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255) 539 output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255)
417 self._run_skpmaker( 540 self._run_skpmaker(
418 output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255) 541 output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255)
419 542
420 def _run_skpmaker(self, output_path, red=0, green=0, blue=0, 543 def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
421 width=640, height=400): 544 width=640, height=400):
422 """Runs the skpmaker binary to generate SKP with known characteristics. 545 """Runs the skpmaker binary to generate SKP with known characteristics.
(...skipping 22 matching lines...) Expand all
445 Args: 568 Args:
446 dir_path: Path to a directory on local disk. 569 dir_path: Path to a directory on local disk.
447 expected_filenames: Set containing the expected filenames within the dir. 570 expected_filenames: Set containing the expected filenames within the dir.
448 571
449 Raises: 572 Raises:
450 AssertionError: contents of the directory are not identical to 573 AssertionError: contents of the directory are not identical to
451 expected_filenames. 574 expected_filenames.
452 """ 575 """
453 self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames)) 576 self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames))
454 577
455
456 def _assert_json_contents(self, json_path, expected_dict): 578 def _assert_json_contents(self, json_path, expected_dict):
457 """Asserts that contents of a JSON file are identical to expected_dict. 579 """Asserts that contents of a JSON file are identical to expected_dict.
458 580
459 Args: 581 Args:
460 json_path: Path to a JSON file. 582 json_path: Path to a JSON file.
461 expected_dict: Dictionary indicating the expected contents of the JSON 583 expected_dict: Dictionary indicating the expected contents of the JSON
462 file. 584 file.
463 585
464 Raises: 586 Raises:
465 AssertionError: contents of the JSON file are not identical to 587 AssertionError: contents of the JSON file are not identical to
466 expected_dict. 588 expected_dict.
467 """ 589 """
468 file_contents = open(json_path, 'r').read() 590 prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True,
469 actual_dict = json.loads(file_contents) 591 indent=2)
470 self.assertEqual(actual_dict, expected_dict) 592 with open(json_path, 'r') as fh:
593 prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True,
594 indent=2)
595 self.assertMultiLineEqual(prettyprinted_expected_dict,
596 prettyprinted_json_dict)
471 597
472 598
473 def main(): 599 def main():
474 base_unittest.main(RenderPicturesTest) 600 base_unittest.main(RenderPicturesTest)
475 601
476 602
477 if __name__ == '__main__': 603 if __name__ == '__main__':
478 main() 604 main()
OLDNEW
« tools/PictureRenderer.cpp ('K') | « tools/render_pictures_main.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698