OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import unittest | |
7 | |
8 from externs_checker import ExternsChecker | |
9 | |
10 class MockFile(object): | |
Dan Beam
2016/02/23 03:15:24
use src/PRESUBMIT_test_mocks.py
Devlin
2016/02/23 23:12:39
Hey, look at that!
Done.
| |
11 def __init__(self, path): | |
12 self.path = path | |
13 def LocalPath(self): | |
14 return self.path | |
15 | |
16 class MockWarning(object): | |
17 def __init__(self, message, items, long_message): | |
18 self.message = message | |
19 self.items = items | |
20 self.long_message = long_message | |
21 | |
22 class MockInputApi(object): | |
23 def __init__(self, files): | |
24 self.files = [MockFile(file) for file in files] | |
25 | |
26 def AffectedFiles(self): | |
27 return self.files | |
28 | |
29 class MockOutputApi(object): | |
30 def PresubmitPromptWarning(self, message, items, long_message): | |
31 return MockWarning(message, items, long_message) | |
32 | |
33 class ExternsCheckerTest(unittest.TestCase): | |
34 API_PAIRS = {'a': '1', 'b': '2', 'c': '3'} | |
35 | |
36 def _runChecks(self, files): | |
37 input_api = MockInputApi(files) | |
38 output_api = MockOutputApi() | |
39 checker = ExternsChecker(input_api, output_api, self.API_PAIRS) | |
40 return checker.RunChecks() | |
41 | |
42 def testModifiedSourceWithoutModifiedExtern(self): | |
43 results = self._runChecks(['b', 'test', 'random']) | |
44 self.assertEquals(1, len(results)) | |
45 self.assertEquals(1, len(results[0].items)) | |
46 self.assertEquals('b', results[0].items[0]) | |
47 self.assertEquals( | |
48 'To update the externs, run "' | |
49 'src/ $ python tools/json_schema_compiler/compiler.py b --root=. ' | |
50 '--generator=externs > 2"', | |
51 results[0].long_message) | |
52 | |
53 def testModifiedSourceWithModifiedExtern(self): | |
54 results = self._runChecks(['b', '2', 'test', 'random']) | |
55 self.assertEquals(0, len(results)) | |
56 | |
57 def testModifiedMultipleSourcesWithNoModifiedExterns(self): | |
58 results = self._runChecks(['b', 'test', 'c', 'random']) | |
59 self.assertEquals(1, len(results)) | |
60 self.assertEquals(2, len(results[0].items)) | |
61 self.assertTrue('b' in results[0].items) | |
62 self.assertTrue('c' in results[0].items) | |
63 self.assertEquals( | |
64 'To update the externs, run "' | |
65 'src/ $ python tools/json_schema_compiler/compiler.py <source_file> ' | |
66 '--root=. --generator=externs > <output_file>"', | |
67 results[0].long_message) | |
68 | |
69 def testModifiedMultipleSourcesWithOneModifiedExtern(self): | |
70 results = self._runChecks(['b', 'test', 'c', 'random', '2']) | |
71 self.assertEquals(1, len(results)) | |
72 self.assertEquals(1, len(results[0].items)) | |
73 self.assertEquals('c', results[0].items[0]) | |
74 | |
75 if __name__ == '__main__': | |
76 unittest.main() | |
OLD | NEW |