| 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 A wrapper around the standard Python unittest library, adding features we need | 9 A wrapper around the standard Python unittest library, adding features we need |
| 10 for various unittests within this directory. | 10 for various unittests within this directory. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import filecmp | 13 import filecmp |
| 14 import os | 14 import os |
| 15 import shutil | 15 import shutil |
| 16 import tempfile | 16 import tempfile |
| 17 import unittest | 17 import unittest |
| 18 | 18 |
| 19 PARENT_DIR = os.path.dirname(os.path.realpath(__file__)) | 19 PARENT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 20 TRUNK_DIR = os.path.dirname(os.path.dirname(PARENT_DIR)) |
| 20 TESTDATA_DIR = os.path.join(PARENT_DIR, 'testdata') | 21 TESTDATA_DIR = os.path.join(PARENT_DIR, 'testdata') |
| 21 OUTPUT_DIR_ACTUAL = os.path.join(TESTDATA_DIR, 'outputs', 'actual') | 22 OUTPUT_DIR_ACTUAL = os.path.join(TESTDATA_DIR, 'outputs', 'actual') |
| 22 OUTPUT_DIR_EXPECTED = os.path.join(TESTDATA_DIR, 'outputs', 'expected') | 23 OUTPUT_DIR_EXPECTED = os.path.join(TESTDATA_DIR, 'outputs', 'expected') |
| 23 | 24 |
| 24 | 25 |
| 25 class TestCase(unittest.TestCase): | 26 class TestCase(unittest.TestCase): |
| 26 | 27 |
| 27 def setUp(self): | 28 def setUp(self): |
| 28 self._input_dir = os.path.join(TESTDATA_DIR, 'inputs') | 29 self._input_dir = os.path.join(TESTDATA_DIR, 'inputs') |
| 29 self._output_dir_actual = os.path.join(OUTPUT_DIR_ACTUAL, self.id()) | 30 self._output_dir_actual = os.path.join(OUTPUT_DIR_ACTUAL, self.id()) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 52 ('found differing files:\n' + | 53 ('found differing files:\n' + |
| 53 '\n'.join(['tkdiff %s %s &' % ( | 54 '\n'.join(['tkdiff %s %s &' % ( |
| 54 os.path.join(self._output_dir_actual, basename), | 55 os.path.join(self._output_dir_actual, basename), |
| 55 os.path.join(self._output_dir_expected, basename)) | 56 os.path.join(self._output_dir_expected, basename)) |
| 56 for basename in different_files])) | 57 for basename in different_files])) |
| 57 | 58 |
| 58 def shortDescription(self): | 59 def shortDescription(self): |
| 59 """Tell unittest framework to not print docstrings for test cases.""" | 60 """Tell unittest framework to not print docstrings for test cases.""" |
| 60 return None | 61 return None |
| 61 | 62 |
| 63 def find_path_to_program(self, program): |
| 64 """Returns path to an existing program binary. |
| 65 |
| 66 Args: |
| 67 program: Basename of the program to find (e.g., 'render_pictures'). |
| 68 |
| 69 Returns: |
| 70 Absolute path to the program binary, as a string. |
| 71 |
| 72 Raises: |
| 73 Exception: unable to find the program binary. |
| 74 """ |
| 75 possible_paths = [os.path.join(TRUNK_DIR, 'out', 'Release', program), |
| 76 os.path.join(TRUNK_DIR, 'out', 'Debug', program), |
| 77 os.path.join(TRUNK_DIR, 'out', 'Release', |
| 78 program + '.exe'), |
| 79 os.path.join(TRUNK_DIR, 'out', 'Debug', |
| 80 program + '.exe')] |
| 81 for try_path in possible_paths: |
| 82 if os.path.isfile(try_path): |
| 83 return try_path |
| 84 raise Exception('cannot find %s in paths %s; maybe you need to ' |
| 85 'build %s?' % (program, possible_paths, program)) |
| 86 |
| 62 | 87 |
| 63 def create_empty_dir(path): | 88 def create_empty_dir(path): |
| 64 """Create an empty directory at the given path.""" | 89 """Create an empty directory at the given path.""" |
| 65 if os.path.isdir(path): | 90 if os.path.isdir(path): |
| 66 shutil.rmtree(path) | 91 shutil.rmtree(path) |
| 67 elif os.path.lexists(path): | 92 elif os.path.lexists(path): |
| 68 os.remove(path) | 93 os.remove(path) |
| 69 os.makedirs(path) | 94 os.makedirs(path) |
| 70 | 95 |
| 71 | 96 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 94 for common_dir in dircmp.common_dirs: | 119 for common_dir in dircmp.common_dirs: |
| 95 differing_files.extend(find_different_files( | 120 differing_files.extend(find_different_files( |
| 96 os.path.join(dir1, common_dir), os.path.join(dir2, common_dir))) | 121 os.path.join(dir1, common_dir), os.path.join(dir2, common_dir))) |
| 97 return differing_files | 122 return differing_files |
| 98 | 123 |
| 99 | 124 |
| 100 def main(test_case_class): | 125 def main(test_case_class): |
| 101 """Run the unit tests within the given class.""" | 126 """Run the unit tests within the given class.""" |
| 102 suite = unittest.TestLoader().loadTestsFromTestCase(test_case_class) | 127 suite = unittest.TestLoader().loadTestsFromTestCase(test_case_class) |
| 103 results = unittest.TextTestRunner(verbosity=2).run(suite) | 128 results = unittest.TextTestRunner(verbosity=2).run(suite) |
| OLD | NEW |