| Index: tools/metrics/histograms/verify_enum_custom_flags_test.py
|
| diff --git a/tools/strict_enum_value_checker/strict_enum_value_checker_test.py b/tools/metrics/histograms/verify_enum_custom_flags_test.py
|
| similarity index 59%
|
| copy from tools/strict_enum_value_checker/strict_enum_value_checker_test.py
|
| copy to tools/metrics/histograms/verify_enum_custom_flags_test.py
|
| index 4f95efe0cfd66439dfad50775be5c9225ff4afdf..adcfd520f8d6baa1757894e8228e26204d897f6b 100755
|
| --- a/tools/strict_enum_value_checker/strict_enum_value_checker_test.py
|
| +++ b/tools/metrics/histograms/verify_enum_custom_flags_test.py
|
| @@ -8,7 +8,8 @@ import os
|
| import re
|
| import unittest
|
|
|
| -from strict_enum_value_checker import StrictEnumValueChecker
|
| +from verify_enum_custom_flags \
|
| + import LoginCustomFlagsChecker
|
|
|
| class MockLogging(object):
|
| def __init__(self):
|
| @@ -31,29 +32,40 @@ class MockInputApi(object):
|
| def AffectedFiles(self, include_deletes=None):
|
| return self.files
|
|
|
| + def basename(self, path):
|
| + return os.path.basename(path)
|
| +
|
|
|
| class MockOutputApi(object):
|
| class PresubmitResult(object):
|
| def __init__(self, message, items=None, long_text=""):
|
| self.message = message
|
| self.items = items
|
| - self.long_text = long_text
|
|
|
| class PresubmitError(PresubmitResult):
|
| def __init__(self, message, items, long_text=""):
|
| MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
|
| self.type = "error"
|
|
|
| + def write(self):
|
| + print "E: " + self.message
|
| +
|
| class PresubmitPromptWarning(PresubmitResult):
|
| def __init__(self, message, items, long_text=""):
|
| MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
|
| self.type = "warning"
|
|
|
| + def write(self):
|
| + print "W: " + self.message
|
| +
|
| class PresubmitNotifyResult(PresubmitResult):
|
| def __init__(self, message, items, long_text=""):
|
| MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
|
| self.type = "notify"
|
|
|
| + def write(self):
|
| + print "N: " + self.message
|
| +
|
|
|
| class MockFile(object):
|
| def __init__(self, local_path, old_contents, new_contents):
|
| @@ -119,11 +131,11 @@ class MockChange(object):
|
| return self._changed_files
|
|
|
|
|
| -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"
|
| +class LoginCustomFlagsCheckerTest(unittest.TestCase):
|
| + TEST_FILE_PATTERN = os.path.join("verify_enum_custom_flags_test_data",
|
| + "changed_file_%s.xml")
|
| + MOCK_FILE_LOCAL_PATH = os.path.join("verify_enum_custom_flags_test_data",
|
| + "mock_histograms.xml")
|
|
|
| def _ReadTextFileContents(self, path):
|
| """Given a path, returns a list of strings corresponding to the text lines
|
| @@ -138,7 +150,7 @@ class StrictEnumValueCheckerTest(unittest.TestCase):
|
| return contents
|
|
|
| def _ReadInputFile(self):
|
| - return self._ReadTextFileContents("mock_enum.h")
|
| + return self._ReadTextFileContents(self.MOCK_FILE_LOCAL_PATH)
|
|
|
| def _PrepareTest(self, new_file_path):
|
| old_contents = self._ReadInputFile()
|
| @@ -147,7 +159,7 @@ class StrictEnumValueCheckerTest(unittest.TestCase):
|
| else:
|
| new_contents = self._ReadTextFileContents(new_file_path)
|
| input_api = MockInputApi()
|
| - mock_file = MockFile(self.MOCK_FILE_LOCAL_PATH,
|
| + mock_file = MockFile(new_file_path,
|
| old_contents,
|
| new_contents)
|
| input_api.files.append(mock_file)
|
| @@ -156,80 +168,31 @@ class StrictEnumValueCheckerTest(unittest.TestCase):
|
|
|
| def _RunTest(self, new_file_path):
|
| input_api, output_api = self._PrepareTest(new_file_path)
|
| - checker = StrictEnumValueChecker(input_api, output_api, self.START_MARKER,
|
| - self.END_MARKER, self.MOCK_FILE_LOCAL_PATH)
|
| + checker = LoginCustomFlagsChecker(input_api, output_api,
|
| + new_file_path)
|
| results = checker.Run()
|
| return results
|
|
|
| - def testDeleteFile(self):
|
| - results = self._RunTest(new_file_path=None)
|
| - # TODO(rpaquay) How to check it's the expected warning?'
|
| - self.assertEquals(1, len(results),
|
| - "We should get a single warning about file deletion.")
|
| -
|
| def testSimpleValidEdit(self):
|
| 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.")
|
| + self.assertEquals(True, len(results) == 0,
|
| + "We should get no warning for valid addition.")
|
|
|
| def testSingleDeletionOfEntry(self):
|
| results = self._RunTest(self.TEST_FILE_PATTERN % "2")
|
| - # TODO(rpaquay) How to check it's the expected warning?'
|
| - self.assertEquals(1, len(results),
|
| + self.assertEquals(True, len(results) > 0,
|
| "We should get a warning for an entry deletion.")
|
|
|
| def testSingleRenameOfEntry(self):
|
| 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.")
|
| + self.assertEquals(True, len(results) == 0,
|
| + str("We should get no warning for an entry description"
|
| + "replacement."))
|
|
|
| - def testMissingEnumStartOfEntry(self):
|
| + def testSingleDeprecatedEntry(self):
|
| 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.")
|
| -
|
| - def testMissingEnumEndOfEntry(self):
|
| - 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.")
|
| -
|
| - def testInvertedEnumMarkersOfEntry(self):
|
| - 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.")
|
| -
|
| - def testMultipleInvalidEdits(self):
|
| - 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).")
|
| -
|
| - def testSingleInvalidInserts(self):
|
| - 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.")
|
| -
|
| - def testMulitpleValidInserts(self):
|
| - 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")
|
| -
|
| - def testSingleValidDeleteOutsideOfEnum(self):
|
| - 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")
|
| -
|
| + self.assertEquals(True, len(results) == 0,
|
| + "We should get no warning for entries reordering.")
|
|
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|