Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 | |
| 128 gm_json.WriteToFile( | |
| 129 output_dict, | |
| 130 os.path.join(self.output_dir_actual, | |
| 131 'compare_rendered_pictures.json')) | |
|
epoger
2014/08/21 18:25:06
Where is the expectation for this test? If you do
rmistry
2014/08/21 19:07:01
I wanted to add a new test so that the case where
| |
| 132 | |
| 81 def test_repo_url(self): | 133 def test_repo_url(self): |
| 82 """Use repo: URL to specify summary files.""" | 134 """Use repo: URL to specify summary files.""" |
| 83 base_repo_url = 'repo:gm/rebaseline_server/testdata/inputs/skp-summaries' | 135 base_repo_url = 'repo:gm/rebaseline_server/testdata/inputs/skp-summaries' |
| 84 results_obj = compare_rendered_pictures.RenderedPicturesComparisons( | 136 results_obj = compare_rendered_pictures.RenderedPicturesComparisons( |
| 85 setA_dir=posixpath.join(base_repo_url, 'expectations'), | 137 setA_dir=posixpath.join(base_repo_url, 'expectations'), |
| 86 setB_dir=posixpath.join(base_repo_url, 'actuals'), | 138 setB_dir=posixpath.join(base_repo_url, 'actuals'), |
| 87 setA_section=gm_json.JSONKEY_EXPECTEDRESULTS, | 139 setA_section=gm_json.JSONKEY_EXPECTEDRESULTS, |
| 88 setB_section=gm_json.JSONKEY_ACTUALRESULTS, | 140 setB_section=gm_json.JSONKEY_ACTUALRESULTS, |
| 89 image_diff_db=imagediffdb.ImageDiffDB(self.temp_dir), | 141 image_diff_db=imagediffdb.ImageDiffDB(self.temp_dir), |
| 90 image_base_gs_url='gs://fakebucket/fake/path', | 142 image_base_gs_url='gs://fakebucket/fake/path', |
| 91 diff_base_url='/static/generated-images') | 143 diff_base_url='/static/generated-images') |
| 92 results_obj.get_timestamp = mock_get_timestamp | 144 results_obj.get_timestamp = mock_get_timestamp |
| 93 | 145 |
| 94 # Overwrite elements within the results that change from one test run | 146 # Overwrite elements within the results that change from one test run |
| 95 # to the next. | 147 # to the next. |
| 96 # pylint: disable=W0212 | 148 # pylint: disable=W0212 |
| 97 results_obj._setA_descriptions\ | 149 results_obj._setA_descriptions\ |
| 98 [results.KEY__SET_DESCRIPTIONS__REPO_REVISION] = 'fake-repo-revision' | 150 [results.KEY__SET_DESCRIPTIONS__REPO_REVISION] = 'fake-repo-revision' |
| 99 results_obj._setB_descriptions\ | 151 results_obj._setB_descriptions\ |
| 100 [results.KEY__SET_DESCRIPTIONS__REPO_REVISION] = 'fake-repo-revision' | 152 [results.KEY__SET_DESCRIPTIONS__REPO_REVISION] = 'fake-repo-revision' |
| 101 | 153 |
| 102 gm_json.WriteToFile( | 154 gm_json.WriteToFile( |
| 103 results_obj.get_packaged_results_of_type( | 155 results_obj.get_packaged_results_of_type( |
| 104 results.KEY__HEADER__RESULTS_ALL), | 156 results.KEY__HEADER__RESULTS_ALL), |
| 105 os.path.join(self.output_dir_actual, 'compare_rendered_pictures.json')) | 157 os.path.join(self.output_dir_actual, 'compare_rendered_pictures.json')) |
| 106 | 158 |
| 107 def _generate_skps_and_run_render_pictures(self, subdir, skpdict): | 159 def _generate_skps_and_run_render_pictures(self, subdir, skpdict, |
| 160 image_base_gs_url=None): | |
| 108 """Generate SKPs and run render_pictures on them. | 161 """Generate SKPs and run render_pictures on them. |
| 109 | 162 |
| 110 Args: | 163 Args: |
| 111 subdir: subdirectory (within self.temp_dir) to write all files into | 164 subdir: subdirectory (within self.temp_dir) to write all files into |
| 112 skpdict: {skpname: redvalue} dictionary describing the SKP files to render | 165 skpdict: {skpname: redvalue} dictionary describing the SKP files to render |
| 113 """ | 166 """ |
| 114 out_path = os.path.join(self.temp_dir, subdir) | 167 out_path = os.path.join(self.temp_dir, subdir) |
| 115 os.makedirs(out_path) | 168 os.makedirs(out_path) |
| 116 for skpname, redvalue in skpdict.iteritems(): | 169 for skpname, redvalue in skpdict.iteritems(): |
| 117 self._run_skpmaker( | 170 self._run_skpmaker( |
| 118 output_path=os.path.join(out_path, skpname), red=redvalue) | 171 output_path=os.path.join(out_path, skpname), red=redvalue) |
| 119 | 172 |
| 120 # TODO(epoger): Add --mode tile 256 256 --writeWholeImage to the unittest, | 173 # TODO(epoger): Add --mode tile 256 256 --writeWholeImage to the unittest, |
| 121 # and fix its result! (imageURLs within whole-image entries are wrong when | 174 # and fix its result! (imageURLs within whole-image entries are wrong when |
| 122 # I tried adding that) | 175 # I tried adding that) |
| 123 binary = find_run_binary.find_path_to_program('render_pictures') | 176 binary = find_run_binary.find_path_to_program('render_pictures') |
| 124 return subprocess.check_output([ | 177 render_pictures_cmd = [ |
| 125 binary, | 178 binary, |
| 126 '--config', '8888', | 179 '--config', '8888', |
| 127 '-r', out_path, | 180 '-r', out_path, |
| 128 '--writeChecksumBasedFilenames', | 181 '--writeChecksumBasedFilenames', |
| 129 '--writeJsonSummaryPath', os.path.join(out_path, 'summary.json'), | 182 '--writeJsonSummaryPath', os.path.join(out_path, 'summary.json'), |
| 130 '--writePath', out_path]) | 183 '--writePath', out_path] |
| 184 if image_base_gs_url: | |
| 185 render_pictures_cmd.extend(['--imageBaseGSUrl', image_base_gs_url]) | |
| 186 return subprocess.check_output(render_pictures_cmd) | |
| 131 | 187 |
| 132 def _run_skpmaker(self, output_path, red=0, green=0, blue=0, | 188 def _run_skpmaker(self, output_path, red=0, green=0, blue=0, |
| 133 width=640, height=400): | 189 width=640, height=400): |
| 134 """Runs the skpmaker binary to generate SKP with known characteristics. | 190 """Runs the skpmaker binary to generate SKP with known characteristics. |
| 135 | 191 |
| 136 Args: | 192 Args: |
| 137 output_path: Filepath to write the SKP into. | 193 output_path: Filepath to write the SKP into. |
| 138 red: Value of red color channel in image, 0-255. | 194 red: Value of red color channel in image, 0-255. |
| 139 green: Value of green color channel in image, 0-255. | 195 green: Value of green color channel in image, 0-255. |
| 140 blue: Value of blue color channel in image, 0-255. | 196 blue: Value of blue color channel in image, 0-255. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 155 """Mock version of BaseComparisons.get_timestamp() for testing.""" | 211 """Mock version of BaseComparisons.get_timestamp() for testing.""" |
| 156 return 12345678 | 212 return 12345678 |
| 157 | 213 |
| 158 | 214 |
| 159 def main(): | 215 def main(): |
| 160 base_unittest.main(CompareRenderedPicturesTest) | 216 base_unittest.main(CompareRenderedPicturesTest) |
| 161 | 217 |
| 162 | 218 |
| 163 if __name__ == '__main__': | 219 if __name__ == '__main__': |
| 164 main() | 220 main() |
| OLD | NEW |