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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: extensions/common/api/externs_checker_test.py
diff --git a/extensions/common/api/externs_checker_test.py b/extensions/common/api/externs_checker_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..c570cdbb18e150ec708cad28245b4c8d52dcd276
--- /dev/null
+++ b/extensions/common/api/externs_checker_test.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+
+from externs_checker import ExternsChecker
+
+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.
+ def __init__(self, path):
+ self.path = path
+ def LocalPath(self):
+ return self.path
+
+class MockWarning(object):
+ def __init__(self, message, items, long_message):
+ self.message = message
+ self.items = items
+ self.long_message = long_message
+
+class MockInputApi(object):
+ def __init__(self, files):
+ self.files = [MockFile(file) for file in files]
+
+ def AffectedFiles(self):
+ return self.files
+
+class MockOutputApi(object):
+ def PresubmitPromptWarning(self, message, items, long_message):
+ return MockWarning(message, items, long_message)
+
+class ExternsCheckerTest(unittest.TestCase):
+ API_PAIRS = {'a': '1', 'b': '2', 'c': '3'}
+
+ def _runChecks(self, files):
+ input_api = MockInputApi(files)
+ output_api = MockOutputApi()
+ checker = ExternsChecker(input_api, output_api, self.API_PAIRS)
+ return checker.RunChecks()
+
+ def testModifiedSourceWithoutModifiedExtern(self):
+ results = self._runChecks(['b', 'test', 'random'])
+ self.assertEquals(1, len(results))
+ self.assertEquals(1, len(results[0].items))
+ self.assertEquals('b', results[0].items[0])
+ self.assertEquals(
+ 'To update the externs, run "'
+ 'src/ $ python tools/json_schema_compiler/compiler.py b --root=. '
+ '--generator=externs > 2"',
+ results[0].long_message)
+
+ def testModifiedSourceWithModifiedExtern(self):
+ results = self._runChecks(['b', '2', 'test', 'random'])
+ self.assertEquals(0, len(results))
+
+ def testModifiedMultipleSourcesWithNoModifiedExterns(self):
+ results = self._runChecks(['b', 'test', 'c', 'random'])
+ self.assertEquals(1, len(results))
+ self.assertEquals(2, len(results[0].items))
+ self.assertTrue('b' in results[0].items)
+ self.assertTrue('c' in results[0].items)
+ self.assertEquals(
+ 'To update the externs, run "'
+ 'src/ $ python tools/json_schema_compiler/compiler.py <source_file> '
+ '--root=. --generator=externs > <output_file>"',
+ results[0].long_message)
+
+ def testModifiedMultipleSourcesWithOneModifiedExtern(self):
+ results = self._runChecks(['b', 'test', 'c', 'random', '2'])
+ self.assertEquals(1, len(results))
+ self.assertEquals(1, len(results[0].items))
+ self.assertEquals('c', results[0].items[0])
+
+if __name__ == '__main__':
+ unittest.main()

Powered by Google App Engine
This is Rietveld 408576698