Commit e49187c2 authored by maruel@chromium.org's avatar maruel@chromium.org

Fix CheckSvnProperty canned check.

It was totally broken until I actually tried it. Fix the test accordingly.

TEST=unit test
BUG=none
Review URL: http://codereview.chromium.org/149096

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@19433 0039d316-1c4b-4281-b951-d872f2087c98
parent ce8e46b3
......@@ -198,21 +198,23 @@ def CheckSvnForCommonMimeTypes(input_api, output_api):
"""Checks that common binary file types have the correct svn:mime-type."""
output = []
files = input_api.AffectedFiles(include_deletes=False)
def IsExts(x, exts):
path = x.LocalPath()
for extension in exts:
if path.endswith(extension):
return True
return False
def FilterFiles(extension):
return filter(lambda x: x.endswith(extension), files)
def JpegFiles():
return filter(lambda x: (x.endswith('.jpg') or x.endswith('.jpeg') or
x.endswith('.jpe')),
files)
return filter(lambda x: IsExts(x, extension), files)
def RunCheck(mime_type, files):
output.extend(CheckSvnProperty(input_api, output_api, 'svn:mime-type',
mime_type, files))
RunCheck('application/pdf', FilterFiles('.pdf'))
RunCheck('image/bmp', FilterFiles('.bmp'))
RunCheck('image/gif', FilterFiles('.gif'))
RunCheck('image/png', FilterFiles('.png'))
RunCheck('image/jpeg', JpegFiles())
RunCheck('image/vnd.microsoft.icon', FilterFiles('.ico'))
RunCheck('application/pdf', FilterFiles(['.pdf']))
RunCheck('image/bmp', FilterFiles(['.bmp']))
RunCheck('image/gif', FilterFiles(['.gif']))
RunCheck('image/png', FilterFiles(['.png']))
RunCheck('image/jpeg', FilterFiles(['.jpg', '.jpeg', '.jpe']))
RunCheck('image/vnd.microsoft.icon', FilterFiles(['.ico']))
return output
......
......@@ -1227,26 +1227,31 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty')
input_api = self.MockInputApi(None, False)
output_api = presubmit.OutputApi()
input_api.AffectedFiles(include_deletes=False).AndReturn([
'a.pdf', 'b.bmp', 'c.gif', 'd.png', 'e.jpg', 'f.ico'])
A = lambda x: presubmit.AffectedFile(x, 'M')
files = [
A('a.pdf'), A('b.bmp'), A('c.gif'), A('d.png'), A('e.jpg'), A('f.jpe'),
A('random'), A('g.jpeg'), A('h.ico'),
]
input_api.AffectedFiles(include_deletes=False).AndReturn(files)
presubmit_canned_checks.CheckSvnProperty(
input_api, output_api, 'svn:mime-type', 'application/pdf', ['a.pdf']
input_api, output_api, 'svn:mime-type', 'application/pdf', [files[0]]
).AndReturn([1])
presubmit_canned_checks.CheckSvnProperty(
input_api, output_api, 'svn:mime-type', 'image/bmp', ['b.bmp']
input_api, output_api, 'svn:mime-type', 'image/bmp', [files[1]]
).AndReturn([2])
presubmit_canned_checks.CheckSvnProperty(
input_api, output_api, 'svn:mime-type', 'image/gif', ['c.gif']
input_api, output_api, 'svn:mime-type', 'image/gif', [files[2]]
).AndReturn([3])
presubmit_canned_checks.CheckSvnProperty(
input_api, output_api, 'svn:mime-type', 'image/png', ['d.png']
input_api, output_api, 'svn:mime-type', 'image/png', [files[3]]
).AndReturn([4])
presubmit_canned_checks.CheckSvnProperty(
input_api, output_api, 'svn:mime-type', 'image/jpeg', ['e.jpg']
input_api, output_api, 'svn:mime-type', 'image/jpeg',
[files[4], files[5], files[7]]
).AndReturn([5])
presubmit_canned_checks.CheckSvnProperty(
input_api, output_api, 'svn:mime-type', 'image/vnd.microsoft.icon',
['f.ico']).AndReturn([6])
[files[8]]).AndReturn([6])
self.mox.ReplayAll()
results = presubmit_canned_checks.CheckSvnForCommonMimeTypes(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment