Index: tools/extra_imports/strict_enum_value_checker_test.py |
diff --git a/chrome/browser/extensions/PRESUBMIT_test.py b/tools/extra_imports/strict_enum_value_checker_test.py |
similarity index 71% |
copy from chrome/browser/extensions/PRESUBMIT_test.py |
copy to tools/extra_imports/strict_enum_value_checker_test.py |
index ba7f9160f9c968b09c86c19ac522f06ae007e841..f3adf5b40a341b1c2bd39b8fc6c99aab22045326 100755 |
--- a/chrome/browser/extensions/PRESUBMIT_test.py |
+++ b/tools/extra_imports/strict_enum_value_checker_test.py |
@@ -1,5 +1,5 @@ |
#!/usr/bin/env python |
-# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Copyright (c) 2014 The Chromium Authors. All rights reserved. |
rpaquay
2014/02/18 21:39:26
nit: not "(c)"
|
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
@@ -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 = '' |
rpaquay
2014/02/18 21:39:26
nit: why changing usage to single quote?
|
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,70 +165,70 @@ 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') |
if __name__ == '__main__': |