Index: tools/about_flags_switches_histogram_ids_checker/about_flags_switches_histogram_ids_checker_test.py |
diff --git a/tools/strict_enum_value_checker/strict_enum_value_checker_test.py b/tools/about_flags_switches_histogram_ids_checker/about_flags_switches_histogram_ids_checker_test.py |
similarity index 69% |
copy from tools/strict_enum_value_checker/strict_enum_value_checker_test.py |
copy to tools/about_flags_switches_histogram_ids_checker/about_flags_switches_histogram_ids_checker_test.py |
index 4f95efe0cfd66439dfad50775be5c9225ff4afdf..61c21c9925325f5d408b6c31740d21a16749f15e 100755 |
--- a/tools/strict_enum_value_checker/strict_enum_value_checker_test.py |
+++ b/tools/about_flags_switches_histogram_ids_checker/about_flags_switches_histogram_ids_checker_test.py |
@@ -7,8 +7,9 @@ import difflib |
import os |
import re |
import unittest |
- |
-from strict_enum_value_checker import StrictEnumValueChecker |
+# about_flags_switches_histogram_ids_checker_test.py |
+from about_flags_switches_histogram_ids_checker \ |
+ import AboutFlagsSwitchesHistogramIDsChecker |
class MockLogging(object): |
def __init__(self): |
@@ -37,23 +38,32 @@ class MockOutputApi(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 +129,9 @@ class MockChange(object): |
return self._changed_files |
-class StrictEnumValueCheckerTest(unittest.TestCase): |
+class AboutFlagsSwitchesHistogramIDsCheckerTest(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 |
@@ -156,80 +164,56 @@ 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 = AboutFlagsSwitchesHistogramIDsChecker(input_api, output_api, |
+ self.MOCK_FILE_LOCAL_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.") |
+ self.assertEquals(True, len(results) > 0, |
+ "We should get a 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, |
+ "We should get a warning for an entry rename.") |
- 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.") |
+ self.assertEquals(True, len(results) == 0, |
+ "We should get no warning for a deprecated entry.") |
- def testMissingEnumEndOfEntry(self): |
+ def testIncorrectEntryName(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.") |
+ self.assertEquals(True, len(results) > 0, |
+ "We should get a warning for a new entry without valid previx.") |
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).") |
+ results = self._RunTest(self.TEST_FILE_PATTERN % "6") |
+ self.assertEquals(True, len(results) > 0, |
+ "We should get a warning in case of several insertions.") |
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), |
+ results = self._RunTest(self.TEST_FILE_PATTERN % "7") |
+ self.assertEquals(True, len(results) > 0, |
"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") |
- |
+ results = self._RunTest(self.TEST_FILE_PATTERN % "8") |
+ self.assertEquals(True, len(results) == 0, |
+ "We should not get a warning for valid insertions.") |
if __name__ == '__main__': |
unittest.main() |