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

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

Issue 479613002: Add ability to output ImageBaseGSUrl to render_picture and use in rebaseline server (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix render_pictures_test after rebase 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
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 14 matching lines...) Expand all
25 25
26 # Must fix up PYTHONPATH before importing from within Skia 26 # Must fix up PYTHONPATH before importing from within Skia
27 import rs_fixpypath # pylint: disable=W0611 27 import rs_fixpypath # pylint: disable=W0611
28 28
29 # Imports from within Skia 29 # Imports from within Skia
30 import base_unittest 30 import base_unittest
31 import compare_rendered_pictures 31 import compare_rendered_pictures
32 import find_run_binary 32 import find_run_binary
33 import gm_json 33 import gm_json
34 import imagediffdb 34 import imagediffdb
35 import imagepairset
35 import results 36 import results
36 37
37 38
38 class CompareRenderedPicturesTest(base_unittest.TestCase): 39 class CompareRenderedPicturesTest(base_unittest.TestCase):
39 40
40 def test_endToEnd(self): 41 def test_endToEnd(self):
41 """Generate two sets of SKPs, run render_pictures over both, and compare 42 """Generate two sets of SKPs, run render_pictures over both, and compare
42 the results.""" 43 the results."""
43 setA_subdir = 'before_patch' 44 setA_subdir = 'before_patch'
44 setB_subdir = 'after_patch' 45 setB_subdir = 'after_patch'
(...skipping 26 matching lines...) Expand all
71 results_obj._setA_descriptions[results.KEY__SET_DESCRIPTIONS__DIR] = [ 72 results_obj._setA_descriptions[results.KEY__SET_DESCRIPTIONS__DIR] = [
72 'before-patch-fake-dir'] 73 'before-patch-fake-dir']
73 results_obj._setB_descriptions[results.KEY__SET_DESCRIPTIONS__DIR] = [ 74 results_obj._setB_descriptions[results.KEY__SET_DESCRIPTIONS__DIR] = [
74 'after-patch-fake-dir'] 75 'after-patch-fake-dir']
75 76
76 gm_json.WriteToFile( 77 gm_json.WriteToFile(
77 results_obj.get_packaged_results_of_type( 78 results_obj.get_packaged_results_of_type(
78 results.KEY__HEADER__RESULTS_ALL), 79 results.KEY__HEADER__RESULTS_ALL),
79 os.path.join(self.output_dir_actual, 'compare_rendered_pictures.json')) 80 os.path.join(self.output_dir_actual, 'compare_rendered_pictures.json'))
80 81
82 def test_endToEnd_withImageBaseGSUrl(self):
83 """Generate two sets of SKPs, run render_pictures over both, and compare
84 the results."""
85 setA_subdir = 'before_patch'
86 setB_subdir = 'after_patch'
87 imageA_gs_base = 'superman/kent-camera/pictures'
88 imageB_gs_base = 'batman/batarang/pictures'
89 self._generate_skps_and_run_render_pictures(
90 subdir=setA_subdir, skpdict={
91 'changed.skp': 200,
92 'unchanged.skp': 100,
93 'only-in-before.skp': 128,
94 },
95 image_base_gs_url='gs://%s' % imageA_gs_base)
96 self._generate_skps_and_run_render_pictures(
97 subdir=setB_subdir, skpdict={
98 'changed.skp': 201,
99 'unchanged.skp': 100,
100 'only-in-after.skp': 128,
101 },
102 image_base_gs_url='gs://%s' % imageB_gs_base)
103
104 results_obj = compare_rendered_pictures.RenderedPicturesComparisons(
105 setA_dir=os.path.join(self.temp_dir, setA_subdir),
106 setB_dir=os.path.join(self.temp_dir, setB_subdir),
107 setA_section=gm_json.JSONKEY_ACTUALRESULTS,
108 setB_section=gm_json.JSONKEY_ACTUALRESULTS,
109 image_diff_db=imagediffdb.ImageDiffDB(self.temp_dir),
110 image_base_gs_url='gs://fakebucket/fake/path',
111 diff_base_url='/static/generated-images')
112 results_obj.get_timestamp = mock_get_timestamp
113
114 output_dict = results_obj.get_packaged_results_of_type(
115 results.KEY__HEADER__RESULTS_ALL)
116 # Assert that the baseURLs are as expected.
117 self.assertEquals(
118 output_dict[imagepairset.KEY__ROOT__IMAGESETS]
119 [imagepairset.KEY__IMAGESETS__SET__IMAGE_A]
120 [imagepairset.KEY__IMAGESETS__FIELD__BASE_URL],
121 'http://storage.cloud.google.com/%s' % imageA_gs_base)
122 self.assertEquals(
123 output_dict[imagepairset.KEY__ROOT__IMAGESETS]
124 [imagepairset.KEY__IMAGESETS__SET__IMAGE_B]
125 [imagepairset.KEY__IMAGESETS__FIELD__BASE_URL],
126 'http://storage.cloud.google.com/%s' % imageB_gs_base)
127 # Overwrite elements within the results that change from one test run
128 # to the next.
129 # pylint: disable=W0212
130 results_obj._setA_descriptions[results.KEY__SET_DESCRIPTIONS__DIR] = [
131 'before-patch-fake-dir']
132 results_obj._setB_descriptions[results.KEY__SET_DESCRIPTIONS__DIR] = [
133 'after-patch-fake-dir']
134
135 gm_json.WriteToFile(
136 output_dict,
137 os.path.join(self.output_dir_actual,
138 'compare_rendered_pictures.json'))
139
81 def test_repo_url(self): 140 def test_repo_url(self):
82 """Use repo: URL to specify summary files.""" 141 """Use repo: URL to specify summary files."""
83 base_repo_url = 'repo:gm/rebaseline_server/testdata/inputs/skp-summaries' 142 base_repo_url = 'repo:gm/rebaseline_server/testdata/inputs/skp-summaries'
84 results_obj = compare_rendered_pictures.RenderedPicturesComparisons( 143 results_obj = compare_rendered_pictures.RenderedPicturesComparisons(
85 setA_dir=posixpath.join(base_repo_url, 'expectations'), 144 setA_dir=posixpath.join(base_repo_url, 'expectations'),
86 setB_dir=posixpath.join(base_repo_url, 'actuals'), 145 setB_dir=posixpath.join(base_repo_url, 'actuals'),
87 setA_section=gm_json.JSONKEY_EXPECTEDRESULTS, 146 setA_section=gm_json.JSONKEY_EXPECTEDRESULTS,
88 setB_section=gm_json.JSONKEY_ACTUALRESULTS, 147 setB_section=gm_json.JSONKEY_ACTUALRESULTS,
89 image_diff_db=imagediffdb.ImageDiffDB(self.temp_dir), 148 image_diff_db=imagediffdb.ImageDiffDB(self.temp_dir),
90 image_base_gs_url='gs://fakebucket/fake/path', 149 image_base_gs_url='gs://fakebucket/fake/path',
91 diff_base_url='/static/generated-images') 150 diff_base_url='/static/generated-images')
92 results_obj.get_timestamp = mock_get_timestamp 151 results_obj.get_timestamp = mock_get_timestamp
93 152
94 # Overwrite elements within the results that change from one test run 153 # Overwrite elements within the results that change from one test run
95 # to the next. 154 # to the next.
96 # pylint: disable=W0212 155 # pylint: disable=W0212
97 results_obj._setA_descriptions\ 156 results_obj._setA_descriptions\
98 [results.KEY__SET_DESCRIPTIONS__REPO_REVISION] = 'fake-repo-revision' 157 [results.KEY__SET_DESCRIPTIONS__REPO_REVISION] = 'fake-repo-revision'
99 results_obj._setB_descriptions\ 158 results_obj._setB_descriptions\
100 [results.KEY__SET_DESCRIPTIONS__REPO_REVISION] = 'fake-repo-revision' 159 [results.KEY__SET_DESCRIPTIONS__REPO_REVISION] = 'fake-repo-revision'
101 160
102 gm_json.WriteToFile( 161 gm_json.WriteToFile(
103 results_obj.get_packaged_results_of_type( 162 results_obj.get_packaged_results_of_type(
104 results.KEY__HEADER__RESULTS_ALL), 163 results.KEY__HEADER__RESULTS_ALL),
105 os.path.join(self.output_dir_actual, 'compare_rendered_pictures.json')) 164 os.path.join(self.output_dir_actual, 'compare_rendered_pictures.json'))
106 165
107 def _generate_skps_and_run_render_pictures(self, subdir, skpdict): 166 def _generate_skps_and_run_render_pictures(self, subdir, skpdict,
167 image_base_gs_url=None):
108 """Generate SKPs and run render_pictures on them. 168 """Generate SKPs and run render_pictures on them.
109 169
110 Args: 170 Args:
111 subdir: subdirectory (within self.temp_dir) to write all files into 171 subdir: subdirectory (within self.temp_dir) to write all files into
112 skpdict: {skpname: redvalue} dictionary describing the SKP files to render 172 skpdict: {skpname: redvalue} dictionary describing the SKP files to render
113 """ 173 """
114 out_path = os.path.join(self.temp_dir, subdir) 174 out_path = os.path.join(self.temp_dir, subdir)
115 os.makedirs(out_path) 175 os.makedirs(out_path)
116 for skpname, redvalue in skpdict.iteritems(): 176 for skpname, redvalue in skpdict.iteritems():
117 self._run_skpmaker( 177 self._run_skpmaker(
118 output_path=os.path.join(out_path, skpname), red=redvalue) 178 output_path=os.path.join(out_path, skpname), red=redvalue)
119 179
120 # TODO(epoger): Add --mode tile 256 256 --writeWholeImage to the unittest, 180 # TODO(epoger): Add --mode tile 256 256 --writeWholeImage to the unittest,
121 # and fix its result! (imageURLs within whole-image entries are wrong when 181 # and fix its result! (imageURLs within whole-image entries are wrong when
122 # I tried adding that) 182 # I tried adding that)
123 binary = find_run_binary.find_path_to_program('render_pictures') 183 binary = find_run_binary.find_path_to_program('render_pictures')
124 return subprocess.check_output([ 184 render_pictures_cmd = [
125 binary, 185 binary,
126 '--config', '8888', 186 '--config', '8888',
127 '-r', out_path, 187 '-r', out_path,
128 '--writeChecksumBasedFilenames', 188 '--writeChecksumBasedFilenames',
129 '--writeJsonSummaryPath', os.path.join(out_path, 'summary.json'), 189 '--writeJsonSummaryPath', os.path.join(out_path, 'summary.json'),
130 '--writePath', out_path]) 190 '--writePath', out_path]
191 if image_base_gs_url:
192 render_pictures_cmd.extend(['--imageBaseGSUrl', image_base_gs_url])
193 return subprocess.check_output(render_pictures_cmd)
131 194
132 def _run_skpmaker(self, output_path, red=0, green=0, blue=0, 195 def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
133 width=640, height=400): 196 width=640, height=400):
134 """Runs the skpmaker binary to generate SKP with known characteristics. 197 """Runs the skpmaker binary to generate SKP with known characteristics.
135 198
136 Args: 199 Args:
137 output_path: Filepath to write the SKP into. 200 output_path: Filepath to write the SKP into.
138 red: Value of red color channel in image, 0-255. 201 red: Value of red color channel in image, 0-255.
139 green: Value of green color channel in image, 0-255. 202 green: Value of green color channel in image, 0-255.
140 blue: Value of blue color channel in image, 0-255. 203 blue: Value of blue color channel in image, 0-255.
(...skipping 14 matching lines...) Expand all
155 """Mock version of BaseComparisons.get_timestamp() for testing.""" 218 """Mock version of BaseComparisons.get_timestamp() for testing."""
156 return 12345678 219 return 12345678
157 220
158 221
159 def main(): 222 def main():
160 base_unittest.main(CompareRenderedPicturesTest) 223 base_unittest.main(CompareRenderedPicturesTest)
161 224
162 225
163 if __name__ == '__main__': 226 if __name__ == '__main__':
164 main() 227 main()
OLDNEW
« no previous file with comments | « gm/rebaseline_server/compare_rendered_pictures.py ('k') | gm/rebaseline_server/compare_to_expectations.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698