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 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 |
| 17 |
| 18 class ExternsCheckerTest(unittest.TestCase): |
| 19 API_PAIRS = {'a': '1', 'b': '2', 'c': '3'} |
| 20 |
| 21 def _runChecks(self, files): |
| 22 input_api = MockInputApi() |
| 23 input_api.files = [MockFile(f, '') for f in files] |
| 24 output_api = MockOutputApi() |
| 25 checker = ExternsChecker(input_api, output_api, self.API_PAIRS) |
| 26 return checker.RunChecks() |
| 27 |
| 28 def testModifiedSourceWithoutModifiedExtern(self): |
| 29 results = self._runChecks(['b', 'test', 'random']) |
| 30 self.assertEquals(1, len(results)) |
| 31 self.assertEquals(1, len(results[0].items)) |
| 32 self.assertEquals('b', results[0].items[0]) |
| 33 self.assertEquals( |
| 34 'To update the externs, run:\n' |
| 35 ' src/ $ python tools/json_schema_compiler/compiler.py b --root=. ' |
| 36 '--generator=externs > 2', |
| 37 results[0].long_text) |
| 38 |
| 39 def testModifiedSourceWithModifiedExtern(self): |
| 40 results = self._runChecks(['b', '2', 'test', 'random']) |
| 41 self.assertEquals(0, len(results)) |
| 42 |
| 43 def testModifiedMultipleSourcesWithNoModifiedExterns(self): |
| 44 results = self._runChecks(['b', 'test', 'c', 'random']) |
| 45 self.assertEquals(1, len(results)) |
| 46 self.assertEquals(2, len(results[0].items)) |
| 47 self.assertTrue('b' in results[0].items) |
| 48 self.assertTrue('c' in results[0].items) |
| 49 self.assertEquals( |
| 50 'To update the externs, run:\n' |
| 51 ' src/ $ python tools/json_schema_compiler/compiler.py <source_file> ' |
| 52 '--root=. --generator=externs > <output_file>', |
| 53 results[0].long_text) |
| 54 |
| 55 def testModifiedMultipleSourcesWithOneModifiedExtern(self): |
| 56 results = self._runChecks(['b', 'test', 'c', 'random', '2']) |
| 57 self.assertEquals(1, len(results)) |
| 58 self.assertEquals(1, len(results[0].items)) |
| 59 self.assertEquals('c', results[0].items[0]) |
| 60 |
| 61 |
| 62 if __name__ == '__main__': |
| 63 unittest.main() |
OLD | NEW |