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