OLD | NEW |
---|---|
(Empty) | |
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. | |
10 | |
11 TODO(epoger): Combine with overlapping tools/test_rendering.py and | |
12 tools/test_pictures.py . | |
13 See https://code.google.com/p/skia/issues/detail?id=1943#c2 | |
14 """ | |
15 | |
16 # System-level imports | |
17 import json | |
18 import os | |
19 import shutil | |
20 import tempfile | |
21 | |
22 # Imports from within Skia | |
23 import base_unittest | |
24 | |
25 | |
26 class RenderPicturesTest(base_unittest.TestCase): | |
27 | |
28 # Setup and teardown... | |
rmistry
2014/01/06 18:54:44
Do not need this comment.
epoger
2014/01/06 20:46:13
Removed. I like having the sections delineated, b
| |
29 | |
30 def setUp(self): | |
31 self._temp_dir = tempfile.mkdtemp() | |
32 | |
33 def tearDown(self): | |
34 shutil.rmtree(self._temp_dir) | |
35 | |
36 # Individual test cases... | |
rmistry
2014/01/06 18:54:44
Do not need this comment since it is obvious from
epoger
2014/01/06 20:46:13
Done.
| |
37 | |
38 def test_whole_image_no_comparison(self): | |
39 """Run render_pictures with --writeWholeImage flag.""" | |
40 input_skp_path = os.path.join(self._temp_dir, 'input.skp') | |
41 output_json_path = os.path.join(self._temp_dir, 'output.json') | |
42 self._run_skpmaker(['--writePath', input_skp_path]) | |
43 self._run_render_pictures(['-r', input_skp_path, | |
44 '--writeJsonSummaryPath', output_json_path, | |
45 '--writeWholeImage']) | |
46 expected_summary_dict = { | |
47 "actual-results" : { | |
48 "no-comparison" : { | |
49 "input.png" : [ "bitmap-64bitMD5", 12793741875005523433 ] | |
epoger
2014/01/03 21:46:12
I have not validated that this checksum is actuall
| |
50 } | |
51 } | |
52 } | |
53 self._assert_json_contents(output_json_path, expected_summary_dict) | |
54 | |
55 def test_tiles_no_comparison(self): | |
56 """Generate individual tiles. | |
57 | |
58 TODO(epoger): The results of this test are currently broken! | |
epoger
2014/01/03 21:46:12
I was surprised to see the results of this test!
| |
59 The summary should contain a list of tiles, but for some reason, it is | |
60 empty.""" | |
61 input_skp_path = os.path.join(self._temp_dir, 'input.skp') | |
62 output_json_path = os.path.join(self._temp_dir, 'output.json') | |
63 self._run_skpmaker(['--writePath', input_skp_path]) | |
64 self._run_render_pictures(['-r', input_skp_path, | |
65 '--writeJsonSummaryPath', output_json_path]) | |
66 expected_summary_dict = { | |
67 "actual-results" : { | |
68 "no-comparison" : None | |
69 } | |
70 } | |
71 self._assert_json_contents(output_json_path, expected_summary_dict) | |
72 | |
73 # Helper functions... | |
rmistry
2014/01/06 18:54:44
Do not need this comment as well.
epoger
2014/01/06 20:46:13
Done.
| |
74 | |
75 def _run_render_pictures(self, args): | |
76 binary = self.find_path_to_program('render_pictures') | |
77 return self.run_command([binary, | |
78 '--bbh', 'grid', '256', '256', | |
79 '--clone', '1', | |
80 '--config', '8888', | |
81 '--mode', 'tile', '256', '256', | |
rmistry
2014/01/06 18:54:44
It might also be worth doing a test with render_pi
epoger
2014/01/06 20:46:13
Sure, good idea. Note that it gives unexpected re
| |
82 '--validate' | |
83 ] + args) | |
84 | |
85 def _run_skpmaker(self, args): | |
86 binary = self.find_path_to_program('skpmaker') | |
87 return self.run_command([binary, | |
88 '--red', '255', | |
89 '--green', '0', | |
90 '--blue', '0', | |
91 '--width', '640', | |
92 '--height', '400', | |
93 ] + args) | |
94 | |
95 def _assert_json_contents(self, json_path, expected_dict): | |
96 """Asserts that contents of a JSON file are identical to expected_dict. | |
97 | |
98 Args: | |
99 json_path: Path to a JSON file. | |
100 expected_dict: Dictionary indicating the expected contents of the JSON | |
101 file. | |
102 | |
103 Raises: | |
104 AssertionError: contents of the JSON file are not identical to | |
105 expected_dict. | |
106 """ | |
107 file_contents = open(json_path, 'r').read() | |
108 actual_dict = json.loads(file_contents) | |
109 self.assertEqual(actual_dict, expected_dict) | |
110 | |
111 | |
112 def main(): | |
113 base_unittest.main(RenderPicturesTest) | |
114 | |
115 | |
116 if __name__ == '__main__': | |
117 main() | |
OLD | NEW |