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

Unified 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: Created 6 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: tools/tests/render_pictures_test.py
diff --git a/tools/tests/render_pictures_test.py b/tools/tests/render_pictures_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..95d43387623d0e2aca0dafc40aabb3c99d514165
--- /dev/null
+++ b/tools/tests/render_pictures_test.py
@@ -0,0 +1,117 @@
+#!/usr/bin/python
+
+"""
+Copyright 2014 Google Inc.
+
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+
+Test the render_pictures binary.
+
+TODO(epoger): Combine with overlapping tools/test_rendering.py and
+tools/test_pictures.py .
+See https://code.google.com/p/skia/issues/detail?id=1943#c2
+"""
+
+# System-level imports
+import json
+import os
+import shutil
+import tempfile
+
+# Imports from within Skia
+import base_unittest
+
+
+class RenderPicturesTest(base_unittest.TestCase):
+
+ # 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
+
+ def setUp(self):
+ self._temp_dir = tempfile.mkdtemp()
+
+ def tearDown(self):
+ shutil.rmtree(self._temp_dir)
+
+ # 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.
+
+ def test_whole_image_no_comparison(self):
+ """Run render_pictures with --writeWholeImage flag."""
+ input_skp_path = os.path.join(self._temp_dir, 'input.skp')
+ output_json_path = os.path.join(self._temp_dir, 'output.json')
+ self._run_skpmaker(['--writePath', input_skp_path])
+ self._run_render_pictures(['-r', input_skp_path,
+ '--writeJsonSummaryPath', output_json_path,
+ '--writeWholeImage'])
+ expected_summary_dict = {
+ "actual-results" : {
+ "no-comparison" : {
+ "input.png" : [ "bitmap-64bitMD5", 12793741875005523433 ]
epoger 2014/01/03 21:46:12 I have not validated that this checksum is actuall
+ }
+ }
+ }
+ self._assert_json_contents(output_json_path, expected_summary_dict)
+
+ def test_tiles_no_comparison(self):
+ """Generate individual tiles.
+
+ 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!
+ The summary should contain a list of tiles, but for some reason, it is
+ empty."""
+ input_skp_path = os.path.join(self._temp_dir, 'input.skp')
+ output_json_path = os.path.join(self._temp_dir, 'output.json')
+ self._run_skpmaker(['--writePath', input_skp_path])
+ self._run_render_pictures(['-r', input_skp_path,
+ '--writeJsonSummaryPath', output_json_path])
+ expected_summary_dict = {
+ "actual-results" : {
+ "no-comparison" : None
+ }
+ }
+ self._assert_json_contents(output_json_path, expected_summary_dict)
+
+ # Helper functions...
rmistry 2014/01/06 18:54:44 Do not need this comment as well.
epoger 2014/01/06 20:46:13 Done.
+
+ def _run_render_pictures(self, args):
+ binary = self.find_path_to_program('render_pictures')
+ return self.run_command([binary,
+ '--bbh', 'grid', '256', '256',
+ '--clone', '1',
+ '--config', '8888',
+ '--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
+ '--validate'
+ ] + args)
+
+ def _run_skpmaker(self, args):
+ binary = self.find_path_to_program('skpmaker')
+ return self.run_command([binary,
+ '--red', '255',
+ '--green', '0',
+ '--blue', '0',
+ '--width', '640',
+ '--height', '400',
+ ] + args)
+
+ def _assert_json_contents(self, json_path, expected_dict):
+ """Asserts that contents of a JSON file are identical to expected_dict.
+
+ Args:
+ json_path: Path to a JSON file.
+ expected_dict: Dictionary indicating the expected contents of the JSON
+ file.
+
+ Raises:
+ AssertionError: contents of the JSON file are not identical to
+ expected_dict.
+ """
+ file_contents = open(json_path, 'r').read()
+ actual_dict = json.loads(file_contents)
+ self.assertEqual(actual_dict, expected_dict)
+
+
+def main():
+ base_unittest.main(RenderPicturesTest)
+
+
+if __name__ == '__main__':
+ main()

Powered by Google App Engine
This is Rietveld 408576698