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

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

Issue 493363002: create sk_tools::Expectation class, similar to skiagm::Expectations class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: properly handle ignoreFailure using sk_tools::Expectation class, with unittest to exercise Created 6 years, 4 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
« no previous file with comments | « 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 """
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 "green.skp": { 206 "green.skp": {
207 "tiled-images": GREEN_TILES, 207 "tiled-images": GREEN_TILES,
208 "whole-image": GREEN_WHOLEIMAGE, 208 "whole-image": GREEN_WHOLEIMAGE,
209 } 209 }
210 } 210 }
211 } 211 }
212 self._assert_json_contents(output_json_path, expected_summary_dict) 212 self._assert_json_contents(output_json_path, expected_summary_dict)
213 self._assert_directory_contents( 213 self._assert_directory_contents(
214 write_path_dir, ['red_skp.png', 'green_skp.png']) 214 write_path_dir, ['red_skp.png', 'green_skp.png'])
215 215
216 def test_ignore_some_failures(self):
217 """test_tiled_whole_image, but ignoring some failed tests.
218 """
219 output_json_path = os.path.join(self._output_dir, 'actuals.json')
220 write_path_dir = self.create_empty_dir(
221 path=os.path.join(self._output_dir, 'writePath'))
222 self._generate_skps()
223 expectations_path = self._create_expectations(ignore_some_failures=True)
224 self._run_render_pictures([
225 '-r', self._input_skp_dir,
226 '--bbh', 'grid', '256', '256',
227 '--mode', 'tile', '256', '256',
228 '--readJsonSummaryPath', expectations_path,
229 '--writeJsonSummaryPath', output_json_path,
230 '--writePath', write_path_dir,
231 '--writeWholeImage'])
232 modified_red_tiles = copy.deepcopy(RED_TILES)
233 modified_red_tiles[5]['comparisonResult'] = 'failure-ignored'
234 expected_summary_dict = {
235 "header" : EXPECTED_HEADER_CONTENTS,
236 "descriptions" : None,
237 "actual-results" : {
238 "red.skp": {
239 "tiled-images": modified_red_tiles,
240 "whole-image": modified_dict(
241 RED_WHOLEIMAGE, {"comparisonResult" : "failure-ignored"}),
242 },
243 "green.skp": {
244 "tiled-images": GREEN_TILES,
245 "whole-image": GREEN_WHOLEIMAGE,
246 }
247 }
248 }
249 self._assert_json_contents(output_json_path, expected_summary_dict)
250 self._assert_directory_contents(
251 write_path_dir, ['red_skp.png', 'green_skp.png'])
252
216 def test_missing_tile_and_whole_image(self): 253 def test_missing_tile_and_whole_image(self):
217 """test_tiled_whole_image, but missing expectations for some images. 254 """test_tiled_whole_image, but missing expectations for some images.
218 """ 255 """
219 output_json_path = os.path.join(self._output_dir, 'actuals.json') 256 output_json_path = os.path.join(self._output_dir, 'actuals.json')
220 write_path_dir = self.create_empty_dir( 257 write_path_dir = self.create_empty_dir(
221 path=os.path.join(self._output_dir, 'writePath')) 258 path=os.path.join(self._output_dir, 'writePath'))
222 self._generate_skps() 259 self._generate_skps()
223 expectations_path = self._create_expectations(missing_some_images=True) 260 expectations_path = self._create_expectations(missing_some_images=True)
224 self._run_render_pictures([ 261 self._run_render_pictures([
225 '-r', self._input_skp_dir, 262 '-r', self._input_skp_dir,
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 'bitmap-64bitMD5_7980646035555096146.png', 621 'bitmap-64bitMD5_7980646035555096146.png',
585 'bitmap-64bitMD5_17817086664365875131.png', 622 'bitmap-64bitMD5_17817086664365875131.png',
586 'bitmap-64bitMD5_10673669813016809363.png']) 623 'bitmap-64bitMD5_10673669813016809363.png'])
587 624
588 def _run_render_pictures(self, args): 625 def _run_render_pictures(self, args):
589 binary = find_run_binary.find_path_to_program('render_pictures') 626 binary = find_run_binary.find_path_to_program('render_pictures')
590 return find_run_binary.run_command( 627 return find_run_binary.run_command(
591 [binary, '--config', '8888'] + args) 628 [binary, '--config', '8888'] + args)
592 629
593 def _create_expectations(self, missing_some_images=False, 630 def _create_expectations(self, missing_some_images=False,
631 ignore_some_failures=False,
594 rel_path='expectations.json'): 632 rel_path='expectations.json'):
595 """Creates expectations JSON file within self._expectations_dir . 633 """Creates expectations JSON file within self._expectations_dir .
596 634
597 Args: 635 Args:
598 missing_some_images: (bool) whether to remove expectations for a subset 636 missing_some_images: (bool) whether to remove expectations for a subset
599 of the images 637 of the images
638 ignore_some_failures: (bool) whether to ignore some failing tests
600 rel_path: (string) relative path within self._expectations_dir to write 639 rel_path: (string) relative path within self._expectations_dir to write
601 the expectations into 640 the expectations into
602 641
603 Returns: full path to the expectations file created. 642 Returns: full path to the expectations file created.
604 """ 643 """
605 expectations_dict = { 644 expectations_dict = {
606 "header" : EXPECTED_HEADER_CONTENTS, 645 "header" : EXPECTED_HEADER_CONTENTS,
607 "descriptions" : None, 646 "descriptions" : None,
608 "expected-results" : { 647 "expected-results" : {
609 # red.skp: these should fail the comparison 648 # red.skp: these should fail the comparison
610 "red.skp": { 649 "red.skp": {
611 "tiled-images": modified_list_of_dicts( 650 "tiled-images": modified_list_of_dicts(
612 RED_TILES, {'checksumValue': 11111}), 651 RED_TILES, {'checksumValue': 11111}),
613 "whole-image": modified_dict( 652 "whole-image": modified_dict(
614 RED_WHOLEIMAGE, {'checksumValue': 22222}), 653 RED_WHOLEIMAGE, {'checksumValue': 22222}),
615 }, 654 },
616 # green.skp: these should pass the comparison 655 # green.skp: these should pass the comparison
617 "green.skp": { 656 "green.skp": {
618 "tiled-images": GREEN_TILES, 657 "tiled-images": GREEN_TILES,
619 "whole-image": GREEN_WHOLEIMAGE, 658 "whole-image": GREEN_WHOLEIMAGE,
620 } 659 }
621 } 660 }
622 } 661 }
623 if missing_some_images: 662 if missing_some_images:
624 del expectations_dict['expected-results']['red.skp']['whole-image'] 663 red_subdict = expectations_dict['expected-results']['red.skp']
625 del expectations_dict['expected-results']['red.skp']['tiled-images'][-1] 664 del red_subdict['whole-image']
665 del red_subdict['tiled-images'][-1]
666 elif ignore_some_failures:
667 red_subdict = expectations_dict['expected-results']['red.skp']
668 red_subdict['whole-image']['ignoreFailure'] = True
669 red_subdict['tiled-images'][-1]['ignoreFailure'] = True
626 path = os.path.join(self._expectations_dir, rel_path) 670 path = os.path.join(self._expectations_dir, rel_path)
627 with open(path, 'w') as fh: 671 with open(path, 'w') as fh:
628 json.dump(expectations_dict, fh) 672 json.dump(expectations_dict, fh)
629 return path 673 return path
630 674
631 def _generate_skps(self): 675 def _generate_skps(self):
632 """Runs the skpmaker binary to generate files in self._input_skp_dir.""" 676 """Runs the skpmaker binary to generate files in self._input_skp_dir."""
633 self._run_skpmaker( 677 self._run_skpmaker(
634 output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255) 678 output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255)
635 self._run_skpmaker( 679 self._run_skpmaker(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 self.assertMultiLineEqual(prettyprinted_expected_dict, 735 self.assertMultiLineEqual(prettyprinted_expected_dict,
692 prettyprinted_json_dict) 736 prettyprinted_json_dict)
693 737
694 738
695 def main(): 739 def main():
696 base_unittest.main(RenderPicturesTest) 740 base_unittest.main(RenderPicturesTest)
697 741
698 742
699 if __name__ == '__main__': 743 if __name__ == '__main__':
700 main() 744 main()
OLDNEW
« no previous file with comments | « tools/render_pictures_main.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698