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

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

Issue 124253002: add unittest for render_pictures binary (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 11 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/tests/base_unittest.py ('k') | tools/tests/run_all.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 def setUp(self):
29 self._temp_dir = tempfile.mkdtemp()
30
31 def tearDown(self):
32 shutil.rmtree(self._temp_dir)
33
34 def test_tiled_whole_image_no_comparison(self):
35 """Run render_pictures with tiles and --writeWholeImage flag."""
36 input_skp_path = os.path.join(self._temp_dir, 'input.skp')
37 output_json_path = os.path.join(self._temp_dir, 'output.json')
38 self._run_skpmaker(['--writePath', input_skp_path])
39 self._run_render_pictures(['-r', input_skp_path,
40 '--bbh', 'grid', '256', '256',
41 '--mode', 'tile', '256', '256',
42 '--writeJsonSummaryPath', output_json_path,
43 '--writeWholeImage'])
44 expected_summary_dict = {
45 "actual-results" : {
46 "no-comparison" : {
47 "input.png" : [ "bitmap-64bitMD5", 12793741875005523433 ]
48 }
49 }
50 }
51 self._assert_json_contents(output_json_path, expected_summary_dict)
52
53 def test_tiled_no_comparison(self):
54 """Generate individual tiles.
55
56 TODO(epoger): The results of this test are currently broken!
57 The summary should contain a list of tiles, but for some reason, it is
58 empty."""
59 input_skp_path = os.path.join(self._temp_dir, 'input.skp')
60 output_json_path = os.path.join(self._temp_dir, 'output.json')
61 self._run_skpmaker(['--writePath', input_skp_path])
62 self._run_render_pictures(['-r', input_skp_path,
63 '--bbh', 'grid', '256', '256',
64 '--mode', 'tile', '256', '256',
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 def test_untiled_no_comparison(self):
74 """Run without tiles.
75
76 TODO(epoger): The results of this test are currently broken!
77 The summary should contain a single image, but for some reason, it is
78 empty."""
79 input_skp_path = os.path.join(self._temp_dir, 'input.skp')
80 output_json_path = os.path.join(self._temp_dir, 'output.json')
81 self._run_skpmaker(['--writePath', input_skp_path])
82 self._run_render_pictures(['-r', input_skp_path,
83 '--writeJsonSummaryPath', output_json_path])
84 expected_summary_dict = {
85 "actual-results" : {
86 "no-comparison" : None
87 }
88 }
89 self._assert_json_contents(output_json_path, expected_summary_dict)
90
91 def _run_render_pictures(self, args):
92 binary = self.find_path_to_program('render_pictures')
93 return self.run_command([binary,
94 '--clone', '1',
95 '--config', '8888',
96 '--validate'
97 ] + args)
98
99 def _run_skpmaker(self, args):
100 binary = self.find_path_to_program('skpmaker')
101 return self.run_command([binary,
102 '--red', '255',
103 '--green', '0',
104 '--blue', '0',
105 '--width', '640',
106 '--height', '400',
107 ] + args)
108
109 def _assert_json_contents(self, json_path, expected_dict):
110 """Asserts that contents of a JSON file are identical to expected_dict.
111
112 Args:
113 json_path: Path to a JSON file.
114 expected_dict: Dictionary indicating the expected contents of the JSON
115 file.
116
117 Raises:
118 AssertionError: contents of the JSON file are not identical to
119 expected_dict.
120 """
121 file_contents = open(json_path, 'r').read()
122 actual_dict = json.loads(file_contents)
123 self.assertEqual(actual_dict, expected_dict)
124
125
126 def main():
127 base_unittest.main(RenderPicturesTest)
128
129
130 if __name__ == '__main__':
131 main()
OLDNEW
« no previous file with comments | « tools/tests/base_unittest.py ('k') | tools/tests/run_all.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698