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

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

Issue 1925273002: [Closure Externs] Fix presubmit check (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « extensions/common/api/externs_checker.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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()
OLDNEW
« no previous file with comments | « extensions/common/api/externs_checker.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698