Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: extensions/common/api/externs_checker_test.py

Issue 1718243003: [Extern Generation] Add a presubmit script to check externs not being updated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 os
7 import sys
8 import unittest
9
10 from externs_checker import ExternsChecker
11
12 sys.path.append(
13 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..'))
14
15 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile
16
Dan Beam 2016/02/24 00:50:42 \n\n
Devlin 2016/02/24 04:45:23 Done.
17 class ExternsCheckerTest(unittest.TestCase):
18 API_PAIRS = {'a': '1', 'b': '2', 'c': '3'}
19
20 def _runChecks(self, files):
21 input_api = MockInputApi()
22 input_api.files = [MockFile(f, '') for f in files]
23 output_api = MockOutputApi()
24 checker = ExternsChecker(input_api, output_api, self.API_PAIRS)
25 return checker.RunChecks()
26
27 def testModifiedSourceWithoutModifiedExtern(self):
28 results = self._runChecks(['b', 'test', 'random'])
29 self.assertEquals(1, len(results))
30 self.assertEquals(1, len(results[0].items))
31 self.assertEquals('b', results[0].items[0])
32 self.assertEquals(
33 'To update the externs, run:\n'
34 ' src/ $ python tools/json_schema_compiler/compiler.py b --root=. '
35 '--generator=externs > 2',
36 results[0].long_text)
37
38 def testModifiedSourceWithModifiedExtern(self):
39 results = self._runChecks(['b', '2', 'test', 'random'])
40 self.assertEquals(0, len(results))
41
42 def testModifiedMultipleSourcesWithNoModifiedExterns(self):
43 results = self._runChecks(['b', 'test', 'c', 'random'])
44 self.assertEquals(1, len(results))
45 self.assertEquals(2, len(results[0].items))
46 self.assertTrue('b' in results[0].items)
47 self.assertTrue('c' in results[0].items)
48 self.assertEquals(
49 'To update the externs, run:\n'
50 ' src/ $ python tools/json_schema_compiler/compiler.py <source_file> '
51 '--root=. --generator=externs > <output_file>',
52 results[0].long_text)
53
54 def testModifiedMultipleSourcesWithOneModifiedExtern(self):
55 results = self._runChecks(['b', 'test', 'c', 'random', '2'])
56 self.assertEquals(1, len(results))
57 self.assertEquals(1, len(results[0].items))
58 self.assertEquals('c', results[0].items[0])
59
Dan Beam 2016/02/24 00:50:42 \n\n
Devlin 2016/02/24 04:45:23 Done.
60 if __name__ == '__main__':
61 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698