| 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 |
| 11 TODO(epoger): Create a command to update the expected results (in | 11 TODO(epoger): Create a command to update the expected results (in |
| 12 self._output_dir_expected) when appropriate. For now, you should: | 12 self._output_dir_expected) when appropriate. For now, you should: |
| 13 1. examine the results in self._output_dir_actual and make sure they are ok | 13 1. examine the results in self.output_dir_actual and make sure they are ok |
| 14 2. rm -rf self._output_dir_expected | 14 2. rm -rf self._output_dir_expected |
| 15 3. mv self._output_dir_actual self._output_dir_expected | 15 3. mv self.output_dir_actual self._output_dir_expected |
| 16 Although, if you're using an SVN checkout, this will blow away .svn directories | 16 Although, if you're using an SVN checkout, this will blow away .svn directories |
| 17 within self._output_dir_expected, which wouldn't be good... | 17 within self._output_dir_expected, which wouldn't be good... |
| 18 | 18 |
| 19 """ | 19 """ |
| 20 | 20 |
| 21 # System-level imports |
| 21 import os | 22 import os |
| 22 import subprocess | 23 import subprocess |
| 23 import sys | 24 import sys |
| 24 | 25 |
| 26 # Must fix up PYTHONPATH before importing from within Skia |
| 27 import fix_pythonpath # pylint: disable=W0611 |
| 28 |
| 25 # Imports from within Skia | 29 # Imports from within Skia |
| 26 import base_unittest | 30 import base_unittest |
| 27 import compare_rendered_pictures | 31 import compare_rendered_pictures |
| 32 import find_run_binary |
| 33 import gm_json |
| 28 import results | 34 import results |
| 29 import gm_json # must import results first, so that gm_json will be in sys.path | |
| 30 | 35 |
| 31 | 36 |
| 32 class CompareRenderedPicturesTest(base_unittest.TestCase): | 37 class CompareRenderedPicturesTest(base_unittest.TestCase): |
| 33 | 38 |
| 34 def test_endToEnd(self): | 39 def test_endToEnd(self): |
| 35 """Generate two sets of SKPs, run render_pictures over both, and compare | 40 """Generate two sets of SKPs, run render_pictures over both, and compare |
| 36 the results.""" | 41 the results.""" |
| 37 self._generate_skps_and_run_render_pictures( | 42 self._generate_skps_and_run_render_pictures( |
| 38 subdir='before_patch', skpdict={ | 43 subdir='before_patch', skpdict={ |
| 39 'changed.skp': 200, | 44 'changed.skp': 200, |
| 40 'unchanged.skp': 100, | 45 'unchanged.skp': 100, |
| 41 'only-in-before.skp': 128, | 46 'only-in-before.skp': 128, |
| 42 }) | 47 }) |
| 43 self._generate_skps_and_run_render_pictures( | 48 self._generate_skps_and_run_render_pictures( |
| 44 subdir='after_patch', skpdict={ | 49 subdir='after_patch', skpdict={ |
| 45 'changed.skp': 201, | 50 'changed.skp': 201, |
| 46 'unchanged.skp': 100, | 51 'unchanged.skp': 100, |
| 47 'only-in-after.skp': 128, | 52 'only-in-after.skp': 128, |
| 48 }) | 53 }) |
| 49 | 54 |
| 50 results_obj = compare_rendered_pictures.RenderedPicturesComparisons( | 55 results_obj = compare_rendered_pictures.RenderedPicturesComparisons( |
| 51 actuals_root=self._temp_dir, | 56 actuals_root=self.temp_dir, |
| 52 subdirs=('before_patch', 'after_patch'), | 57 subdirs=('before_patch', 'after_patch'), |
| 53 generated_images_root=self._temp_dir, | 58 generated_images_root=self.temp_dir, |
| 54 diff_base_url='/static/generated-images') | 59 diff_base_url='/static/generated-images') |
| 55 results_obj.get_timestamp = mock_get_timestamp | 60 results_obj.get_timestamp = mock_get_timestamp |
| 56 | 61 |
| 57 gm_json.WriteToFile( | 62 gm_json.WriteToFile( |
| 58 results_obj.get_packaged_results_of_type( | 63 results_obj.get_packaged_results_of_type( |
| 59 results.KEY__HEADER__RESULTS_ALL), | 64 results.KEY__HEADER__RESULTS_ALL), |
| 60 os.path.join(self._output_dir_actual, 'compare_rendered_pictures.json')) | 65 os.path.join(self.output_dir_actual, 'compare_rendered_pictures.json')) |
| 61 | 66 |
| 62 def _generate_skps_and_run_render_pictures(self, subdir, skpdict): | 67 def _generate_skps_and_run_render_pictures(self, subdir, skpdict): |
| 63 """Generate SKPs and run render_pictures on them. | 68 """Generate SKPs and run render_pictures on them. |
| 64 | 69 |
| 65 Args: | 70 Args: |
| 66 subdir: subdirectory (within self._temp_dir) to write all files into | 71 subdir: subdirectory (within self.temp_dir) to write all files into |
| 67 skpdict: {skpname: redvalue} dictionary describing the SKP files to render | 72 skpdict: {skpname: redvalue} dictionary describing the SKP files to render |
| 68 """ | 73 """ |
| 69 out_path = os.path.join(self._temp_dir, subdir) | 74 out_path = os.path.join(self.temp_dir, subdir) |
| 70 os.makedirs(out_path) | 75 os.makedirs(out_path) |
| 71 for skpname, redvalue in skpdict.iteritems(): | 76 for skpname, redvalue in skpdict.iteritems(): |
| 72 self._run_skpmaker( | 77 self._run_skpmaker( |
| 73 output_path=os.path.join(out_path, skpname), red=redvalue) | 78 output_path=os.path.join(out_path, skpname), red=redvalue) |
| 74 | 79 |
| 75 # TODO(epoger): Add --mode tile 256 256 --writeWholeImage to the unittest, | 80 # TODO(epoger): Add --mode tile 256 256 --writeWholeImage to the unittest, |
| 76 # and fix its result! (imageURLs within whole-image entries are wrong when | 81 # and fix its result! (imageURLs within whole-image entries are wrong when |
| 77 # I tried adding that) | 82 # I tried adding that) |
| 78 binary = self.find_path_to_program('render_pictures') | 83 binary = find_run_binary.find_path_to_program('render_pictures') |
| 79 return subprocess.check_output([ | 84 return subprocess.check_output([ |
| 80 binary, | 85 binary, |
| 81 '--config', '8888', | 86 '--config', '8888', |
| 82 '-r', out_path, | 87 '-r', out_path, |
| 83 '--writeChecksumBasedFilenames', | 88 '--writeChecksumBasedFilenames', |
| 84 '--writeJsonSummaryPath', os.path.join(out_path, 'summary.json'), | 89 '--writeJsonSummaryPath', os.path.join(out_path, 'summary.json'), |
| 85 '--writePath', out_path]) | 90 '--writePath', out_path]) |
| 86 | 91 |
| 87 def _run_skpmaker(self, output_path, red=0, green=0, blue=0, | 92 def _run_skpmaker(self, output_path, red=0, green=0, blue=0, |
| 88 width=640, height=400): | 93 width=640, height=400): |
| 89 """Runs the skpmaker binary to generate SKP with known characteristics. | 94 """Runs the skpmaker binary to generate SKP with known characteristics. |
| 90 | 95 |
| 91 Args: | 96 Args: |
| 92 output_path: Filepath to write the SKP into. | 97 output_path: Filepath to write the SKP into. |
| 93 red: Value of red color channel in image, 0-255. | 98 red: Value of red color channel in image, 0-255. |
| 94 green: Value of green color channel in image, 0-255. | 99 green: Value of green color channel in image, 0-255. |
| 95 blue: Value of blue color channel in image, 0-255. | 100 blue: Value of blue color channel in image, 0-255. |
| 96 width: Width of canvas to create. | 101 width: Width of canvas to create. |
| 97 height: Height of canvas to create. | 102 height: Height of canvas to create. |
| 98 """ | 103 """ |
| 99 binary = self.find_path_to_program('skpmaker') | 104 binary = find_run_binary.find_path_to_program('skpmaker') |
| 100 return subprocess.check_output([ | 105 return subprocess.check_output([ |
| 101 binary, | 106 binary, |
| 102 '--red', str(red), | 107 '--red', str(red), |
| 103 '--green', str(green), | 108 '--green', str(green), |
| 104 '--blue', str(blue), | 109 '--blue', str(blue), |
| 105 '--width', str(width), | 110 '--width', str(width), |
| 106 '--height', str(height), | 111 '--height', str(height), |
| 107 '--writePath', str(output_path)]) | 112 '--writePath', str(output_path)]) |
| 108 | 113 |
| 109 def mock_get_timestamp(): | 114 def mock_get_timestamp(): |
| 110 """Mock version of BaseComparisons.get_timestamp() for testing.""" | 115 """Mock version of BaseComparisons.get_timestamp() for testing.""" |
| 111 return 12345678 | 116 return 12345678 |
| 112 | 117 |
| 113 | 118 |
| 114 def main(): | 119 def main(): |
| 115 base_unittest.main(CompareRenderedPicturesTest) | 120 base_unittest.main(CompareRenderedPicturesTest) |
| 116 | 121 |
| 117 | 122 |
| 118 if __name__ == '__main__': | 123 if __name__ == '__main__': |
| 119 main() | 124 main() |
| OLD | NEW |