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 """ |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), | 235 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
236 }, | 236 }, |
237 "green.skp": { | 237 "green.skp": { |
238 "tiled-images": GREEN_TILES, | 238 "tiled-images": GREEN_TILES, |
239 "whole-image": GREEN_WHOLEIMAGE, | 239 "whole-image": GREEN_WHOLEIMAGE, |
240 } | 240 } |
241 } | 241 } |
242 } | 242 } |
243 self._assert_json_contents(output_json_path, expected_summary_dict) | 243 self._assert_json_contents(output_json_path, expected_summary_dict) |
244 | 244 |
245 def test_untiled(self): | 245 def _test_untiled(self, expectations_path=None, expected_summary_dict=None, |
246 """Run without tiles.""" | 246 additional_args=None): |
| 247 """Base for multiple tests without tiles. |
| 248 |
| 249 Args: |
| 250 expectations_path: path we should pass using --readJsonSummaryPath, or |
| 251 None if we should create the default expectations file |
| 252 expected_summary_dict: dict we should compare against the output actual |
| 253 results summary, or None if we should use a default comparison dict |
| 254 additional_args: array of command-line args to add when we run |
| 255 render_pictures |
| 256 """ |
247 output_json_path = os.path.join(self._output_dir, 'actuals.json') | 257 output_json_path = os.path.join(self._output_dir, 'actuals.json') |
248 write_path_dir = self.create_empty_dir( | 258 write_path_dir = self.create_empty_dir( |
249 path=os.path.join(self._output_dir, 'writePath')) | 259 path=os.path.join(self._output_dir, 'writePath')) |
250 self._generate_skps() | 260 self._generate_skps() |
251 expectations_path = self._create_expectations() | 261 if expectations_path == None: |
252 self._run_render_pictures([ | 262 expectations_path = self._create_expectations() |
| 263 args = [ |
253 '-r', self._input_skp_dir, | 264 '-r', self._input_skp_dir, |
254 '--readJsonSummaryPath', expectations_path, | 265 '--readJsonSummaryPath', expectations_path, |
255 '--writePath', write_path_dir, | 266 '--writePath', write_path_dir, |
256 '--writeJsonSummaryPath', output_json_path]) | 267 '--writeJsonSummaryPath', output_json_path, |
| 268 ] |
| 269 if additional_args: |
| 270 args.extend(additional_args) |
| 271 self._run_render_pictures(args) |
| 272 if expected_summary_dict == None: |
| 273 expected_summary_dict = { |
| 274 "header" : EXPECTED_HEADER_CONTENTS, |
| 275 "actual-results" : { |
| 276 "red.skp": { |
| 277 "whole-image": RED_WHOLEIMAGE, |
| 278 }, |
| 279 "green.skp": { |
| 280 "whole-image": GREEN_WHOLEIMAGE, |
| 281 } |
| 282 } |
| 283 } |
| 284 self._assert_json_contents(output_json_path, expected_summary_dict) |
| 285 self._assert_directory_contents( |
| 286 write_path_dir, ['red_skp.png', 'green_skp.png']) |
| 287 |
| 288 def test_untiled(self): |
| 289 """Basic test without tiles.""" |
| 290 self._test_untiled() |
| 291 |
| 292 def test_untiled_empty_expectations_file(self): |
| 293 """Same as test_untiled, but with an empty expectations file.""" |
| 294 expectations_path = os.path.join(self._expectations_dir, 'empty') |
| 295 with open(expectations_path, 'w') as fh: |
| 296 pass |
257 expected_summary_dict = { | 297 expected_summary_dict = { |
258 "header" : EXPECTED_HEADER_CONTENTS, | 298 "header" : EXPECTED_HEADER_CONTENTS, |
259 "actual-results" : { | 299 "actual-results" : { |
260 "red.skp": { | 300 "red.skp": { |
261 "whole-image": RED_WHOLEIMAGE, | 301 "whole-image": modified_dict( |
| 302 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
262 }, | 303 }, |
263 "green.skp": { | 304 "green.skp": { |
264 "whole-image": GREEN_WHOLEIMAGE, | 305 "whole-image": modified_dict( |
| 306 GREEN_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
265 } | 307 } |
266 } | 308 } |
267 } | 309 } |
268 self._assert_json_contents(output_json_path, expected_summary_dict) | 310 self._test_untiled(expectations_path=expectations_path, |
269 self._assert_directory_contents( | 311 expected_summary_dict=expected_summary_dict) |
270 write_path_dir, ['red_skp.png', 'green_skp.png']) | |
271 | 312 |
272 def test_untiled_writeChecksumBasedFilenames(self): | 313 def test_untiled_writeChecksumBasedFilenames(self): |
273 """Same as test_untiled, but with --writeChecksumBasedFilenames.""" | 314 """Same as test_untiled, but with --writeChecksumBasedFilenames.""" |
274 output_json_path = os.path.join(self._output_dir, 'actuals.json') | 315 output_json_path = os.path.join(self._output_dir, 'actuals.json') |
275 write_path_dir = self.create_empty_dir( | 316 write_path_dir = self.create_empty_dir( |
276 path=os.path.join(self._output_dir, 'writePath')) | 317 path=os.path.join(self._output_dir, 'writePath')) |
277 self._generate_skps() | 318 self._generate_skps() |
278 self._run_render_pictures(['-r', self._input_skp_dir, | 319 self._run_render_pictures(['-r', self._input_skp_dir, |
279 '--writeChecksumBasedFilenames', | 320 '--writeChecksumBasedFilenames', |
280 '--writePath', write_path_dir, | 321 '--writePath', write_path_dir, |
(...skipping 25 matching lines...) Expand all Loading... |
306 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp']) | 347 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp']) |
307 self._assert_directory_contents( | 348 self._assert_directory_contents( |
308 os.path.join(write_path_dir, 'red_skp'), | 349 os.path.join(write_path_dir, 'red_skp'), |
309 ['bitmap-64bitMD5_11092453015575919668.png']) | 350 ['bitmap-64bitMD5_11092453015575919668.png']) |
310 self._assert_directory_contents( | 351 self._assert_directory_contents( |
311 os.path.join(write_path_dir, 'green_skp'), | 352 os.path.join(write_path_dir, 'green_skp'), |
312 ['bitmap-64bitMD5_8891695120562235492.png']) | 353 ['bitmap-64bitMD5_8891695120562235492.png']) |
313 | 354 |
314 def test_untiled_validate(self): | 355 def test_untiled_validate(self): |
315 """Same as test_untiled, but with --validate.""" | 356 """Same as test_untiled, but with --validate.""" |
316 output_json_path = os.path.join(self._output_dir, 'actuals.json') | 357 self._test_untiled(additional_args=['--validate']) |
317 write_path_dir = self.create_empty_dir( | |
318 path=os.path.join(self._output_dir, 'writePath')) | |
319 self._generate_skps() | |
320 expectations_path = self._create_expectations() | |
321 self._run_render_pictures([ | |
322 '-r', self._input_skp_dir, | |
323 '--readJsonSummaryPath', expectations_path, | |
324 '--validate', | |
325 '--writePath', write_path_dir, | |
326 '--writeJsonSummaryPath', output_json_path]) | |
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( | |
340 write_path_dir, ['red_skp.png', 'green_skp.png']) | |
341 | 358 |
342 def test_untiled_without_writePath(self): | 359 def test_untiled_without_writePath(self): |
343 """Same as test_untiled, but without --writePath.""" | 360 """Same as test_untiled, but without --writePath.""" |
344 output_json_path = os.path.join(self._output_dir, 'actuals.json') | 361 output_json_path = os.path.join(self._output_dir, 'actuals.json') |
345 self._generate_skps() | 362 self._generate_skps() |
346 expectations_path = self._create_expectations() | 363 expectations_path = self._create_expectations() |
347 self._run_render_pictures([ | 364 self._run_render_pictures([ |
348 '-r', self._input_skp_dir, | 365 '-r', self._input_skp_dir, |
349 '--readJsonSummaryPath', expectations_path, | 366 '--readJsonSummaryPath', expectations_path, |
350 '--writeJsonSummaryPath', output_json_path]) | 367 '--writeJsonSummaryPath', output_json_path]) |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 self.assertMultiLineEqual(prettyprinted_expected_dict, | 658 self.assertMultiLineEqual(prettyprinted_expected_dict, |
642 prettyprinted_json_dict) | 659 prettyprinted_json_dict) |
643 | 660 |
644 | 661 |
645 def main(): | 662 def main(): |
646 base_unittest.main(RenderPicturesTest) | 663 base_unittest.main(RenderPicturesTest) |
647 | 664 |
648 | 665 |
649 if __name__ == '__main__': | 666 if __name__ == '__main__': |
650 main() | 667 main() |
OLD | NEW |