Allow PRESUBMIT.py to handle deleted files.
This is a follow up to Issue 43098. Review URL: http://codereview.chromium.org/42086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11619 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -69,7 +69,7 @@ def LocalChecks(input_api, output_api, max_cols=80):
|
||||
eof_files = []
|
||||
results = []
|
||||
excluded_paths = [input_api.re.compile(x) for x in EXCLUDED_PATHS]
|
||||
files = input_api.AffectedFiles()
|
||||
files = input_api.AffectedFiles(include_deletes=False)
|
||||
for f in files:
|
||||
path = f.LocalPath()
|
||||
root, ext = input_api.os_path.splitext(path)
|
||||
|
@ -19,16 +19,23 @@ class MockInputApi(object):
|
||||
self.re = re
|
||||
self.os_path = os.path
|
||||
|
||||
def AffectedFiles(self):
|
||||
return self.affected_files
|
||||
def AffectedFiles(self, include_deletes=True):
|
||||
if include_deletes:
|
||||
return self.affected_files
|
||||
else:
|
||||
return filter(lambda x: x.Action() != 'D', self.affected_files)
|
||||
|
||||
def AffectedTextFiles(self, include_deletes=True):
|
||||
return self.affected_files
|
||||
|
||||
|
||||
class MockAffectedFile(object):
|
||||
def __init__(self, path):
|
||||
def __init__(self, path, action='A'):
|
||||
self.path = path
|
||||
self.action = action
|
||||
|
||||
def Action(self):
|
||||
return self.action
|
||||
|
||||
def LocalPath(self):
|
||||
return self.path
|
||||
@ -82,6 +89,14 @@ class PresubmitUnittest(unittest.TestCase):
|
||||
self.file_contents = 'file with\nzero \\t errors \\r\\n\n'
|
||||
self.failIf(PRESUBMIT.LocalChecks(api, MockOutputApi))
|
||||
|
||||
def testLocalChecksDeletedFile(self):
|
||||
api = MockInputApi()
|
||||
api.affected_files = [
|
||||
MockAffectedFile('foo/blat/source.py', 'D'),
|
||||
]
|
||||
self.file_contents = 'file with \n\terror\nhere\r\nyes there'
|
||||
self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user