Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 """ | 3 """ |
| 4 Copyright 2013 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 results.py | 9 Test download.py |
|
epoger
2014/01/22 19:58:10
git decided that this file is a modified version o
| |
| 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 OUTPUT_DIR_EXPECTED) when appropriate. For now, you should: | 12 OUTPUT_DIR_EXPECTED) when appropriate. For now, you should: |
| 13 1. examine the results in OUTPUT_DIR_ACTUAL and make sure they are ok | 13 1. examine the results in OUTPUT_DIR_ACTUAL and make sure they are ok |
| 14 2. rm -rf OUTPUT_DIR_EXPECTED | 14 2. rm -rf OUTPUT_DIR_EXPECTED |
| 15 3. mv OUTPUT_DIR_ACTUAL OUTPUT_DIR_EXPECTED | 15 3. mv OUTPUT_DIR_ACTUAL 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 OUTPUT_DIR_EXPECTED, which wouldn't be good... | 17 within OUTPUT_DIR_EXPECTED, which wouldn't be good... |
| 18 | 18 |
| 19 """ | 19 """ |
| 20 | 20 |
| 21 # System-level imports | |
| 21 import filecmp | 22 import filecmp |
| 22 import os | 23 import os |
| 23 import shutil | 24 import shutil |
| 24 import sys | |
| 25 import tempfile | 25 import tempfile |
| 26 import unittest | 26 import unittest |
| 27 import url_or_path | |
| 27 | 28 |
| 28 # Imports from within Skia | 29 # Imports from within Skia |
| 29 import results | 30 import download |
| 30 import gm_json # must import results first, so that gm_json will be in sys.path | |
| 31 | 31 |
| 32 PARENT_DIR = os.path.dirname(os.path.realpath(__file__)) | 32 PARENT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 33 INPUT_DIR = os.path.join(PARENT_DIR, 'tests', 'inputs') | 33 INPUT_DIR = os.path.join(PARENT_DIR, 'tests', 'inputs') |
| 34 OUTPUT_DIR_ACTUAL = os.path.join(PARENT_DIR, 'tests', 'outputs', 'actual') | 34 OUTPUT_DIR_ACTUAL = os.path.join(PARENT_DIR, 'tests', 'outputs', 'actual') |
| 35 OUTPUT_DIR_EXPECTED = os.path.join(PARENT_DIR, 'tests', 'outputs', 'expected') | 35 OUTPUT_DIR_EXPECTED = os.path.join(PARENT_DIR, 'tests', 'outputs', 'expected') |
| 36 | 36 |
| 37 | 37 |
| 38 class ResultsTest(unittest.TestCase): | 38 class DownloadTest(unittest.TestCase): |
| 39 | 39 |
| 40 def setUp(self): | 40 def setUp(self): |
| 41 self._temp_dir = tempfile.mkdtemp() | 41 self._temp_dir = tempfile.mkdtemp() |
| 42 self._output_dir_actual = os.path.join(OUTPUT_DIR_ACTUAL, self.id()) | 42 self._output_dir_actual = os.path.join(OUTPUT_DIR_ACTUAL, self.id()) |
| 43 self._output_dir_expected = os.path.join(OUTPUT_DIR_EXPECTED, self.id()) | 43 self._output_dir_expected = os.path.join(OUTPUT_DIR_EXPECTED, self.id()) |
| 44 create_empty_dir(self._output_dir_actual) | 44 create_empty_dir(self._output_dir_actual) |
| 45 | 45 |
| 46 def tearDown(self): | 46 def tearDown(self): |
| 47 shutil.rmtree(self._temp_dir) | 47 shutil.rmtree(self._temp_dir) |
| 48 different_files = find_different_files(self._output_dir_actual, | 48 different_files = find_different_files(self._output_dir_actual, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 60 # Ravi notes: if somebody later comes along and adds cleanup code below the | 60 # Ravi notes: if somebody later comes along and adds cleanup code below the |
| 61 # assert, then if tests fail, the artifacts will not be cleaned up. | 61 # assert, then if tests fail, the artifacts will not be cleaned up. |
| 62 assert (not different_files), \ | 62 assert (not different_files), \ |
| 63 ('found differing files between actual dir %s and expected dir %s: %s' % | 63 ('found differing files between actual dir %s and expected dir %s: %s' % |
| 64 (self._output_dir_actual, self._output_dir_expected, different_files)) | 64 (self._output_dir_actual, self._output_dir_expected, different_files)) |
| 65 | 65 |
| 66 def shortDescription(self): | 66 def shortDescription(self): |
| 67 """Tell unittest framework to not print docstrings for test cases.""" | 67 """Tell unittest framework to not print docstrings for test cases.""" |
| 68 return None | 68 return None |
| 69 | 69 |
| 70 def test_gm(self): | 70 def test_fetch(self): |
| 71 """Process results of a GM run with the Results object.""" | 71 """Tests fetch() of GM results from actual-results.json .""" |
| 72 results_obj = results.Results( | 72 downloader = download.Download( |
| 73 actuals_root=os.path.join(INPUT_DIR, 'gm-actuals'), | 73 actuals_base_url=os.path.join(INPUT_DIR, 'gm-actuals'), |
| 74 expected_root=os.path.join(INPUT_DIR, 'gm-expectations'), | 74 gm_actuals_root_url=url_or_path.create_filepath_url( |
| 75 generated_images_root=self._temp_dir) | 75 os.path.join(INPUT_DIR, 'fake-gm-imagefiles'))) |
| 76 gm_json.WriteToFile(results_obj.get_results_of_type(results.RESULTS_ALL), | 76 downloader.fetch( |
| 77 os.path.join(self._output_dir_actual, 'gm.json')) | 77 builder_name='Test-Android-GalaxyNexus-SGX540-Arm7-Release', |
| 78 dest_dir=self._output_dir_actual) | |
| 78 | 79 |
| 79 | 80 |
| 81 # TODO(epoger): create_empty_dir(), find_different_files(), etc. should be | |
| 82 # extracted from this file to some common location, where they can be shared | |
| 83 # with results_test.py and other users. | |
| 84 | |
| 80 def create_empty_dir(path): | 85 def create_empty_dir(path): |
| 81 """Create an empty directory at the given path.""" | 86 """Create an empty directory at the given path.""" |
| 82 if os.path.isdir(path): | 87 if os.path.isdir(path): |
| 83 shutil.rmtree(path) | 88 shutil.rmtree(path) |
| 84 elif os.path.lexists(path): | 89 elif os.path.lexists(path): |
| 85 os.remove(path) | 90 os.remove(path) |
| 86 os.makedirs(path) | 91 os.makedirs(path) |
| 87 | 92 |
| 88 | 93 |
| 89 def find_different_files(dir1, dir2, ignore_subtree_names=None): | 94 def find_different_files(dir1, dir2, ignore_subtree_names=None): |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 108 differing_files.extend(dircmp.common_funny) | 113 differing_files.extend(dircmp.common_funny) |
| 109 differing_files.extend(dircmp.diff_files) | 114 differing_files.extend(dircmp.diff_files) |
| 110 differing_files.extend(dircmp.funny_files) | 115 differing_files.extend(dircmp.funny_files) |
| 111 for common_dir in dircmp.common_dirs: | 116 for common_dir in dircmp.common_dirs: |
| 112 differing_files.extend(find_different_files( | 117 differing_files.extend(find_different_files( |
| 113 os.path.join(dir1, common_dir), os.path.join(dir2, common_dir))) | 118 os.path.join(dir1, common_dir), os.path.join(dir2, common_dir))) |
| 114 return differing_files | 119 return differing_files |
| 115 | 120 |
| 116 | 121 |
| 117 def main(): | 122 def main(): |
| 118 suite = unittest.TestLoader().loadTestsFromTestCase(ResultsTest) | 123 suite = unittest.TestLoader().loadTestsFromTestCase(DownloadTest) |
| 119 unittest.TextTestRunner(verbosity=2).run(suite) | 124 unittest.TextTestRunner(verbosity=2).run(suite) |
| 120 | 125 |
| 121 | 126 |
| 122 if __name__ == '__main__': | 127 if __name__ == '__main__': |
| 123 main() | 128 main() |
| OLD | NEW |