OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 import unittest | 8 import unittest |
9 | 9 |
10 from externs_checker import ExternsChecker | 10 from externs_checker import ExternsChecker |
11 | 11 |
12 sys.path.append( | 12 sys.path.append( |
13 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..')) | 13 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..')) |
14 | 14 |
15 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile | 15 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile |
16 | 16 |
17 | 17 |
18 class ExternsCheckerTest(unittest.TestCase): | 18 class ExternsCheckerTest(unittest.TestCase): |
19 API_PAIRS = {'a': '1', 'b': '2', 'c': '3'} | 19 API_PAIRS = {'a': '1', 'b': '2', 'c': '3'} |
20 | 20 |
21 def _runChecks(self, files): | 21 def _runChecks(self, files, exists=lambda f: True): |
22 input_api = MockInputApi() | 22 input_api = MockInputApi() |
| 23 input_api.os_path.exists = exists |
23 input_api.files = [MockFile(f, '') for f in files] | 24 input_api.files = [MockFile(f, '') for f in files] |
24 output_api = MockOutputApi() | 25 output_api = MockOutputApi() |
25 checker = ExternsChecker(input_api, output_api, self.API_PAIRS) | 26 checker = ExternsChecker(input_api, output_api, self.API_PAIRS) |
26 return checker.RunChecks() | 27 return checker.RunChecks() |
27 | 28 |
28 def testModifiedSourceWithoutModifiedExtern(self): | 29 def testModifiedSourceWithoutModifiedExtern(self): |
29 results = self._runChecks(['b', 'test', 'random']) | 30 results = self._runChecks(['b', 'test', 'random']) |
30 self.assertEquals(1, len(results)) | 31 self.assertEquals(1, len(results)) |
31 self.assertEquals(1, len(results[0].items)) | 32 self.assertEquals(1, len(results[0].items)) |
32 self.assertEquals('b', results[0].items[0]) | 33 self.assertEquals('b', results[0].items[0]) |
(...skipping 18 matching lines...) Expand all Loading... |
51 ' src/ $ python tools/json_schema_compiler/compiler.py <source_file> ' | 52 ' src/ $ python tools/json_schema_compiler/compiler.py <source_file> ' |
52 '--root=. --generator=externs > <output_file>', | 53 '--root=. --generator=externs > <output_file>', |
53 results[0].long_text) | 54 results[0].long_text) |
54 | 55 |
55 def testModifiedMultipleSourcesWithOneModifiedExtern(self): | 56 def testModifiedMultipleSourcesWithOneModifiedExtern(self): |
56 results = self._runChecks(['b', 'test', 'c', 'random', '2']) | 57 results = self._runChecks(['b', 'test', 'c', 'random', '2']) |
57 self.assertEquals(1, len(results)) | 58 self.assertEquals(1, len(results)) |
58 self.assertEquals(1, len(results[0].items)) | 59 self.assertEquals(1, len(results[0].items)) |
59 self.assertEquals('c', results[0].items[0]) | 60 self.assertEquals('c', results[0].items[0]) |
60 | 61 |
| 62 def testApiFileDoesNotExist(self): |
| 63 exists = lambda f: f in ['a', 'b', 'c', '1', '2'] |
| 64 with self.assertRaises(OSError) as e: |
| 65 self._runChecks(['a'], exists) |
| 66 self.assertEqual('Path Not Found: 3', str(e.exception)) |
| 67 |
61 | 68 |
62 if __name__ == '__main__': | 69 if __name__ == '__main__': |
63 unittest.main() | 70 unittest.main() |
OLD | NEW |