| 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 TRUNK_DIR = os.path.dirname(os.path.dirname(PARENT_DIR)) |
| 21 TESTDATA_DIR = os.path.join(PARENT_DIR, 'testdata') | 21 TESTDATA_DIR = os.path.join(PARENT_DIR, 'testdata') |
| 22 OUTPUT_DIR_ACTUAL = os.path.join(TESTDATA_DIR, 'outputs', 'actual') | 22 OUTPUT_DIR_ACTUAL = os.path.join(TESTDATA_DIR, 'outputs', 'actual') |
| 23 OUTPUT_DIR_EXPECTED = os.path.join(TESTDATA_DIR, 'outputs', 'expected') | 23 OUTPUT_DIR_EXPECTED = os.path.join(TESTDATA_DIR, 'outputs', 'expected') |
| 24 | 24 |
| 25 | 25 |
| 26 class TestCase(unittest.TestCase): | 26 class TestCase(unittest.TestCase): |
| 27 | 27 |
| 28 def setUp(self): | 28 def setUp(self): |
| 29 # Get the name of this test, in such a way that it will be consistent |
| 30 # regardless of the directory it is run from (throw away package names, |
| 31 # if any). |
| 32 test_name = '.'.join(self.id().split('.')[-3:]) |
| 33 |
| 29 self._input_dir = os.path.join(TESTDATA_DIR, 'inputs') | 34 self._input_dir = os.path.join(TESTDATA_DIR, 'inputs') |
| 30 self._output_dir_actual = os.path.join(OUTPUT_DIR_ACTUAL, self.id()) | 35 self._output_dir_actual = os.path.join(OUTPUT_DIR_ACTUAL, test_name) |
| 31 self._output_dir_expected = os.path.join(OUTPUT_DIR_EXPECTED, self.id()) | 36 self._output_dir_expected = os.path.join(OUTPUT_DIR_EXPECTED, test_name) |
| 32 create_empty_dir(self._output_dir_actual) | 37 create_empty_dir(self._output_dir_actual) |
| 33 self._temp_dir = tempfile.mkdtemp() | 38 self._temp_dir = tempfile.mkdtemp() |
| 34 | 39 |
| 35 def tearDown(self): | 40 def tearDown(self): |
| 36 shutil.rmtree(self._temp_dir) | 41 shutil.rmtree(self._temp_dir) |
| 37 if os.path.exists(self._output_dir_expected): | 42 if os.path.exists(self._output_dir_expected): |
| 38 different_files = find_different_files(self._output_dir_actual, | 43 different_files = find_different_files(self._output_dir_actual, |
| 39 self._output_dir_expected) | 44 self._output_dir_expected) |
| 40 # Maybe we should move this assert elsewhere? It's unusual to see an | 45 # Maybe we should move this assert elsewhere? It's unusual to see an |
| 41 # assert within tearDown(), but my thinking was: | 46 # assert within tearDown(), but my thinking was: |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 differing_files.extend(dircmp.funny_files) | 123 differing_files.extend(dircmp.funny_files) |
| 119 for common_dir in dircmp.common_dirs: | 124 for common_dir in dircmp.common_dirs: |
| 120 differing_files.extend(find_different_files( | 125 differing_files.extend(find_different_files( |
| 121 os.path.join(dir1, common_dir), os.path.join(dir2, common_dir))) | 126 os.path.join(dir1, common_dir), os.path.join(dir2, common_dir))) |
| 122 return differing_files | 127 return differing_files |
| 123 | 128 |
| 124 | 129 |
| 125 def main(test_case_class): | 130 def main(test_case_class): |
| 126 """Run the unit tests within the given class.""" | 131 """Run the unit tests within the given class.""" |
| 127 suite = unittest.TestLoader().loadTestsFromTestCase(test_case_class) | 132 suite = unittest.TestLoader().loadTestsFromTestCase(test_case_class) |
| 128 results = unittest.TextTestRunner(verbosity=2).run(suite) | 133 unittest.TextTestRunner(verbosity=2).run(suite) |
| OLD | NEW |