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 MockChange) |
16 | 17 |
17 | 18 |
18 class ExternsCheckerTest(unittest.TestCase): | 19 class ExternsCheckerTest(unittest.TestCase): |
19 API_PAIRS = {'a': '1', 'b': '2', 'c': '3'} | 20 API_PAIRS = {'a': '1', 'b': '2', 'c': '3'} |
20 | 21 |
21 def _runChecks(self, files, exists=lambda f: True): | 22 def _runChecks(self, files, exists=lambda f: True): |
22 input_api = MockInputApi() | 23 input_api = MockInputApi() |
23 input_api.os_path.exists = exists | 24 input_api.os_path.exists = exists |
24 input_api.files = [MockFile(f, '') for f in files] | 25 input_api.files = [MockFile(f, '') for f in files] |
| 26 input_api.change = MockChange(input_api.files) |
25 output_api = MockOutputApi() | 27 output_api = MockOutputApi() |
26 checker = ExternsChecker(input_api, output_api, self.API_PAIRS) | 28 checker = ExternsChecker(input_api, output_api, self.API_PAIRS) |
27 return checker.RunChecks() | 29 return checker.RunChecks() |
28 | 30 |
29 def testModifiedSourceWithoutModifiedExtern(self): | 31 def testModifiedSourceWithoutModifiedExtern(self): |
30 results = self._runChecks(['b', 'test', 'random']) | 32 results = self._runChecks(['b', 'test', 'random']) |
31 self.assertEquals(1, len(results)) | 33 self.assertEquals(1, len(results)) |
32 self.assertEquals(1, len(results[0].items)) | 34 self.assertEquals(1, len(results[0].items)) |
33 self.assertEquals('b', results[0].items[0]) | 35 self.assertEquals('b', results[0].items[0]) |
34 self.assertEquals( | 36 self.assertEquals( |
(...skipping 26 matching lines...) Expand all Loading... |
61 | 63 |
62 def testApiFileDoesNotExist(self): | 64 def testApiFileDoesNotExist(self): |
63 exists = lambda f: f in ['a', 'b', 'c', '1', '2'] | 65 exists = lambda f: f in ['a', 'b', 'c', '1', '2'] |
64 with self.assertRaises(OSError) as e: | 66 with self.assertRaises(OSError) as e: |
65 self._runChecks(['a'], exists) | 67 self._runChecks(['a'], exists) |
66 self.assertEqual('Path Not Found: 3', str(e.exception)) | 68 self.assertEqual('Path Not Found: 3', str(e.exception)) |
67 | 69 |
68 | 70 |
69 if __name__ == '__main__': | 71 if __name__ == '__main__': |
70 unittest.main() | 72 unittest.main() |
OLD | NEW |