| Index: tools/strict_enum_value_checker/strict_enum_value_checker_test.py
|
| diff --git a/extensions/browser/PRESUBMIT_test.py b/tools/strict_enum_value_checker/strict_enum_value_checker_test.py
|
| similarity index 71%
|
| rename from extensions/browser/PRESUBMIT_test.py
|
| rename to tools/strict_enum_value_checker/strict_enum_value_checker_test.py
|
| index 99cabf53c82b172083ab0c3350443d9fa4edc418..e40f33f7a5458800aedf2cd1d969e77ec3a1ba7e 100755
|
| --- a/extensions/browser/PRESUBMIT_test.py
|
| +++ b/tools/strict_enum_value_checker/strict_enum_value_checker_test.py
|
| @@ -8,7 +8,7 @@ import os
|
| import re
|
| import unittest
|
|
|
| -import PRESUBMIT
|
| +from strict_enum_value_checker import StrictEnumValueChecker
|
|
|
| class MockLogging(object):
|
| def __init__(self):
|
| @@ -75,7 +75,7 @@ class MockFile(object):
|
| return False
|
|
|
| def GenerateScmDiff(self):
|
| - result = ""
|
| + result = ''
|
| for line in difflib.unified_diff(self._old_contents, self._new_contents,
|
| self._local_path, self._local_path):
|
| result += line
|
| @@ -84,13 +84,13 @@ class MockFile(object):
|
| # NOTE: This method is a copy of ChangeContents method of AffectedFile in
|
| # presubmit_support.py
|
| def ChangedContents(self):
|
| - """Returns a list of tuples (line number, line text) of all new lines.
|
| + '''Returns a list of tuples (line number, line text) of all new lines.
|
|
|
| This relies on the scm diff output describing each changed code section
|
| with a line of the form
|
|
|
| ^@@ <old line num>,<old size> <new line num>,<new size> @@$
|
| - """
|
| + '''
|
| if self._cached_changed_contents is not None:
|
| return self._cached_changed_contents[:]
|
| self._cached_changed_contents = []
|
| @@ -119,14 +119,17 @@ class MockChange(object):
|
| return self._changed_files
|
|
|
|
|
| -class HistogramValueCheckerTest(unittest.TestCase):
|
| - TEST_FILE_PATTERN = "PRESUBMIT_test_new_file_%s.txt"
|
| +class StrictEnumValueCheckerTest(unittest.TestCase):
|
| + TEST_FILE_PATTERN = 'changed_file_%s.h'
|
| + MOCK_FILE_LOCAL_PATH = 'mock_enum.h'
|
| + START_MARKER = 'enum MockEnum {'
|
| + END_MARKER = ' mBoundary'
|
|
|
| def _ReadTextFileContents(self, path):
|
| - """Given a path, returns a list of strings corresponding to the text lines
|
| + '''Given a path, returns a list of strings corresponding to the text lines
|
| in the file. Reads files in text format.
|
|
|
| - """
|
| + '''
|
| fo = open(path, 'r')
|
| try:
|
| contents = fo.readlines()
|
| @@ -135,7 +138,7 @@ class HistogramValueCheckerTest(unittest.TestCase):
|
| return contents
|
|
|
| def _ReadInputFile(self):
|
| - return self._ReadTextFileContents("PRESUBMIT_test_old_file.txt")
|
| + return self._ReadTextFileContents('mock_enum.h')
|
|
|
| def _PrepareTest(self, new_file_path):
|
| old_contents = self._ReadInputFile()
|
| @@ -144,7 +147,7 @@ class HistogramValueCheckerTest(unittest.TestCase):
|
| else:
|
| new_contents = self._ReadTextFileContents(new_file_path)
|
| input_api = MockInputApi()
|
| - mock_file = MockFile(PRESUBMIT.HistogramValueChecker.LOCAL_PATH,
|
| + mock_file = MockFile(self.MOCK_FILE_LOCAL_PATH,
|
| old_contents,
|
| new_contents)
|
| input_api.files.append(mock_file)
|
| @@ -153,7 +156,8 @@ class HistogramValueCheckerTest(unittest.TestCase):
|
|
|
| def _RunTest(self, new_file_path):
|
| input_api, output_api = self._PrepareTest(new_file_path)
|
| - checker = PRESUBMIT.HistogramValueChecker(input_api, output_api)
|
| + checker = StrictEnumValueChecker(input_api, output_api, self.START_MARKER,
|
| + self.END_MARKER, self.MOCK_FILE_LOCAL_PATH)
|
| results = checker.Run()
|
| return results
|
|
|
| @@ -161,76 +165,71 @@ class HistogramValueCheckerTest(unittest.TestCase):
|
| results = self._RunTest(new_file_path=None)
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(1, len(results),
|
| - "We hould get a single warning about file deletion.")
|
| + 'We should get a single warning about file deletion.')
|
|
|
| def testSimpleValidEdit(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "1")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '1')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(0, len(results),
|
| - "We should get no warning for simple edits.")
|
| + 'We should get no warning for simple edits.')
|
|
|
| def testSingleDeletionOfEntry(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "2")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '2')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(1, len(results),
|
| - "We should get a warning for an entry deletion.")
|
| + 'We should get a warning for an entry deletion.')
|
|
|
| def testSingleRenameOfEntry(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "3")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '3')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(1, len(results),
|
| - "We should get a warning for an entry rename, even "
|
| - "though it is not optimal.")
|
| + 'We should get a warning for an entry rename, even '
|
| + 'though it is not optimal.')
|
|
|
| def testMissingEnumStartOfEntry(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "4")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '4')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(1, len(results),
|
| - "We should get a warning for a missing enum marker.")
|
| + 'We should get a warning for a missing enum marker.')
|
|
|
| def testMissingEnumEndOfEntry(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "5")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '5')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(1, len(results),
|
| - "We should get a warning for a missing enum marker.")
|
| + 'We should get a warning for a missing enum marker.')
|
|
|
| def testInvertedEnumMarkersOfEntry(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "6")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '6')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(1, len(results),
|
| - "We should get a warning for inverted enum markers.")
|
| + 'We should get a warning for inverted enum markers.')
|
|
|
| def testMultipleInvalidEdits(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "7")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '7')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(3, len(results),
|
| - "We should get 3 warnings (one per edit).")
|
| + 'We should get 3 warnings (one per edit).')
|
|
|
| def testSingleInvalidInserts(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "8")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '8')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(1, len(results),
|
| - "We should get a warning for a single invalid "
|
| - "insertion inside the enum.")
|
| + 'We should get a warning for a single invalid '
|
| + 'insertion inside the enum.')
|
|
|
| def testMulitpleValidInserts(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "9")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '9')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(0, len(results),
|
| - "We should not get a warning mulitple valid edits")
|
| + 'We should not get a warning mulitple valid edits')
|
|
|
| def testSingleValidDeleteOutsideOfEnum(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "10")
|
| + results = self._RunTest(self.TEST_FILE_PATTERN % '10')
|
| # TODO(rpaquay) How to check it's the expected warning?'
|
| self.assertEquals(0, len(results),
|
| - "We should not get a warning for a deletion outside of "
|
| - "the enum")
|
| + 'We should not get a warning for a deletion outside of '
|
| + 'the enum')
|
|
|
| - def testCommentIsNotEnumEndMarker(self):
|
| - results = self._RunTest(self.TEST_FILE_PATTERN % "11")
|
| - self.assertEquals(1, len(results),
|
| - "We should get a warning if '// Last Entry' is not the "
|
| - "enum end marker")
|
|
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|