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

Side by Side Diff: gm/rebaseline_server/compare_rendered_pictures_test.py

Issue 274623002: make compare_rendered_pictures_test.py run end-to-end test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 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
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 compare_rendered_pictures.py 9 Test compare_rendered_pictures.py
10 10
(...skipping 13 matching lines...) Expand all
24 # Imports from within Skia 24 # Imports from within Skia
25 import base_unittest 25 import base_unittest
26 import compare_rendered_pictures 26 import compare_rendered_pictures
27 import results 27 import results
28 import gm_json # must import results first, so that gm_json will be in sys.path 28 import gm_json # must import results first, so that gm_json will be in sys.path
29 29
30 30
31 class CompareRenderedPicturesTest(base_unittest.TestCase): 31 class CompareRenderedPicturesTest(base_unittest.TestCase):
32 32
33 def test_endToEnd(self): 33 def test_endToEnd(self):
34 """Compare results of two render_pictures runs.""" 34 """Generate two sets of SKPs, run render_pictures over both, and compare
35 # TODO(epoger): Specify image_base_url pointing at the directory on local 35 the results."""
36 # disk containing our test images, so that we can actually compute pixel 36 self._generate_skps_and_run_render_pictures(
37 # diffs. For now, this test attempts to download images from 37 subdir='before_patch', skpdict={
38 # DEFAULT_IMAGE_BASE_URL, and there aren't any there yet. 38 'changed.skp': 200,
39 'unchanged.skp': 100,
40 'only-in-before.skp': 128,
41 })
42 self._generate_skps_and_run_render_pictures(
43 subdir='after_patch', skpdict={
44 'changed.skp': 201,
45 'unchanged.skp': 100,
46 'only-in-after.skp': 128,
47 })
48
39 results_obj = compare_rendered_pictures.RenderedPicturesComparisons( 49 results_obj = compare_rendered_pictures.RenderedPicturesComparisons(
40 actuals_root=os.path.join(self._input_dir, 'render_pictures_output'), 50 actuals_root=self._temp_dir,
41 subdirs=('before_patch', 'after_patch'), 51 subdirs=('before_patch', 'after_patch'),
42 generated_images_root=self._temp_dir, 52 generated_images_root=self._temp_dir,
43 diff_base_url='/static/generated-images') 53 diff_base_url='/static/generated-images')
44 results_obj.get_timestamp = mock_get_timestamp 54 results_obj.get_timestamp = mock_get_timestamp
55
45 gm_json.WriteToFile( 56 gm_json.WriteToFile(
46 results_obj.get_packaged_results_of_type( 57 results_obj.get_packaged_results_of_type(
47 results.KEY__HEADER__RESULTS_ALL), 58 results.KEY__HEADER__RESULTS_ALL),
48 os.path.join(self._output_dir_actual, 'compare_rendered_pictures.json')) 59 os.path.join(self._output_dir_actual, 'compare_rendered_pictures.json'))
49 60
61 def _generate_skps_and_run_render_pictures(self, subdir, skpdict):
62 """Generate SKPs and run render_pictures on them.
63
64 Args:
65 subdir: subdirectory (within self._temp_dir) to write all files into
66 skpdict: {skpname: redvalue} dictionary describing the SKP files to render
67 """
68 out_path = os.path.join(self._temp_dir, subdir)
69 os.makedirs(out_path)
70 for skpname, redvalue in skpdict.iteritems():
71 self._run_skpmaker(
72 output_path=os.path.join(out_path, skpname), red=redvalue)
73
74 # TODO(epoger): Add --mode tile 256 256 --writeWholeImage to the unittest,
75 # and fix its result! (imageURLs within whole-image entries are wrong when
76 # I tried adding that)
77 binary = self.find_path_to_program('render_pictures')
78 return self.run_command([
79 binary,
80 '--clone', '1',
81 '--config', '8888',
82 '-r', out_path,
83 '--writeChecksumBasedFilenames',
84 '--writeJsonSummaryPath', os.path.join(out_path, 'summary.json'),
85 '--writePath', out_path])
86
87 def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
88 width=640, height=400):
89 """Runs the skpmaker binary to generate SKP with known characteristics.
90
91 Args:
92 output_path: Filepath to write the SKP into.
93 red: Value of red color channel in image, 0-255.
94 green: Value of green color channel in image, 0-255.
95 blue: Value of blue color channel in image, 0-255.
96 width: Width of canvas to create.
97 height: Height of canvas to create.
98 """
99 binary = self.find_path_to_program('skpmaker')
100 return self.run_command([binary,
101 '--red', str(red),
102 '--green', str(green),
103 '--blue', str(blue),
104 '--width', str(width),
105 '--height', str(height),
106 '--writePath', str(output_path),
107 ])
50 108
51 def mock_get_timestamp(): 109 def mock_get_timestamp():
52 """Mock version of BaseComparisons.get_timestamp() for testing.""" 110 """Mock version of BaseComparisons.get_timestamp() for testing."""
53 return 12345678 111 return 12345678
54 112
55 113
56 def main(): 114 def main():
57 base_unittest.main(CompareRenderedPicturesTest) 115 base_unittest.main(CompareRenderedPicturesTest)
58 116
59 117
60 if __name__ == '__main__': 118 if __name__ == '__main__':
61 main() 119 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698