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

Unified Diff: PRESUBMIT_unittest.py

Issue 118484: Use input_api.ReadFile() instead of rolling out its own. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT_unittest.py
===================================================================
--- PRESUBMIT_unittest.py (revision 18008)
+++ PRESUBMIT_unittest.py (working copy)
@@ -14,10 +14,11 @@
class MockInputApi(object):
- def __init__(self):
+ def __init__(self, test):
self.affected_files = []
self.re = re
self.os_path = os.path
+ self._test = test
def AffectedFiles(self, include_deletes=True):
if include_deletes:
@@ -28,7 +29,11 @@
def AffectedTextFiles(self, include_deletes=True):
return self.affected_files
+ def ReadFile(self, file):
+ self._test.failIf(file.LocalPath().endswith('notsource'))
+ return file.file_contents
+
class MockAffectedFile(object):
def __init__(self, path, action='A'):
self.path = path
@@ -52,19 +57,8 @@
class PresubmitUnittest(unittest.TestCase):
- def setUp(self):
- self.file_contents = ''
- def MockReadFile(path):
- self.failIf(path.endswith('notsource'))
- return self.file_contents
- self._ReadFile = PRESUBMIT.ReadFile
- PRESUBMIT.ReadFile = MockReadFile
-
- def tearDown(self):
- PRESUBMIT.ReadFile = self._ReadFile
-
def testLocalChecks(self):
- api = MockInputApi()
+ api = MockInputApi(self)
api.affected_files = [
MockAffectedFile('foo/blat/yoo.notsource'),
MockAffectedFile('third_party/blat/source.cc'),
@@ -72,33 +66,39 @@
MockAffectedFile('foo/blat/source.mm'),
MockAffectedFile('foo/blat/source.py'),
]
- self.file_contents = 'file with \n\terror\nhere\r\nyes there'
+ for item in api.affected_files:
+ item.file_contents = 'file with \n\terror\nhere\r\nyes there'
# 3 source files, 2 errors by file + 1 global CR + 1 global EOF error.
self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 8)
- self.file_contents = 'file\twith\ttabs\n'
+ for item in api.affected_files:
+ item.file_contents = 'file\twith\ttabs\n'
# 3 source files, 1 error by file.
self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 3)
- self.file_contents = 'file\rusing\rCRs\n'
+ for item in api.affected_files:
+ item.file_contents = 'file\rusing\rCRs\n'
# One global CR error.
self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 1)
self.failUnless(
len(PRESUBMIT.LocalChecks(api, MockOutputApi)[0].items) == 3)
- self.file_contents = 'both\ttabs and\r\nCRLF\n'
+ for item in api.affected_files:
+ item.file_contents = 'both\ttabs and\r\nCRLF\n'
# 3 source files, 1 error by file + 1 global CR error.
self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 4)
- self.file_contents = 'file with\nzero \\t errors \\r\\n\n'
+ for item in api.affected_files:
+ item.file_contents = 'file with\nzero \\t errors \\r\\n\n'
self.failIf(PRESUBMIT.LocalChecks(api, MockOutputApi))
def testLocalChecksDeletedFile(self):
- api = MockInputApi()
+ api = MockInputApi(self)
api.affected_files = [
MockAffectedFile('foo/blat/source.py', 'D'),
]
- self.file_contents = 'file with \n\terror\nhere\r\nyes there'
+ api.affected_files[0].file_contents = (
+ 'file with \n\terror\nhere\r\nyes there')
self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 0)
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698