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

Side by Side Diff: presubmit_canned_checks.py

Issue 149096: Fix CheckSvnProperty canned check. (Closed)
Patch Set: Created 11 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Generic presubmit checks that can be reused by other presubmit checks.""" 6 """Generic presubmit checks that can be reused by other presubmit checks."""
7 7
8 8
9 ### Description checks 9 ### Description checks
10 10
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 """Checks that the source files have svn:eol-style=LF.""" 191 """Checks that the source files have svn:eol-style=LF."""
192 return CheckSvnProperty(input_api, output_api, 192 return CheckSvnProperty(input_api, output_api,
193 'svn:eol-style', 'LF', 193 'svn:eol-style', 'LF',
194 input_api.AffectedSourceFiles(source_file_filter)) 194 input_api.AffectedSourceFiles(source_file_filter))
195 195
196 196
197 def CheckSvnForCommonMimeTypes(input_api, output_api): 197 def CheckSvnForCommonMimeTypes(input_api, output_api):
198 """Checks that common binary file types have the correct svn:mime-type.""" 198 """Checks that common binary file types have the correct svn:mime-type."""
199 output = [] 199 output = []
200 files = input_api.AffectedFiles(include_deletes=False) 200 files = input_api.AffectedFiles(include_deletes=False)
201 def IsExts(x, exts):
202 path = x.LocalPath()
203 for extension in exts:
204 if path.endswith(extension):
205 return True
206 return False
201 def FilterFiles(extension): 207 def FilterFiles(extension):
202 return filter(lambda x: x.endswith(extension), files) 208 return filter(lambda x: IsExts(x, extension), files)
203 def JpegFiles():
204 return filter(lambda x: (x.endswith('.jpg') or x.endswith('.jpeg') or
205 x.endswith('.jpe')),
206 files)
207 def RunCheck(mime_type, files): 209 def RunCheck(mime_type, files):
208 output.extend(CheckSvnProperty(input_api, output_api, 'svn:mime-type', 210 output.extend(CheckSvnProperty(input_api, output_api, 'svn:mime-type',
209 mime_type, files)) 211 mime_type, files))
210 RunCheck('application/pdf', FilterFiles('.pdf')) 212 RunCheck('application/pdf', FilterFiles(['.pdf']))
211 RunCheck('image/bmp', FilterFiles('.bmp')) 213 RunCheck('image/bmp', FilterFiles(['.bmp']))
212 RunCheck('image/gif', FilterFiles('.gif')) 214 RunCheck('image/gif', FilterFiles(['.gif']))
213 RunCheck('image/png', FilterFiles('.png')) 215 RunCheck('image/png', FilterFiles(['.png']))
214 RunCheck('image/jpeg', JpegFiles()) 216 RunCheck('image/jpeg', FilterFiles(['.jpg', '.jpeg', '.jpe']))
215 RunCheck('image/vnd.microsoft.icon', FilterFiles('.ico')) 217 RunCheck('image/vnd.microsoft.icon', FilterFiles(['.ico']))
216 return output 218 return output
217 219
218 220
219 def CheckSvnProperty(input_api, output_api, prop, expected, affected_files): 221 def CheckSvnProperty(input_api, output_api, prop, expected, affected_files):
220 """Checks that affected_files files have prop=expected.""" 222 """Checks that affected_files files have prop=expected."""
221 bad = filter(lambda f: f.scm == 'svn' and f.Property(prop) != expected, 223 bad = filter(lambda f: f.scm == 'svn' and f.Property(prop) != expected,
222 affected_files) 224 affected_files)
223 if bad: 225 if bad:
224 if input_api.is_committing: 226 if input_api.is_committing:
225 type = output_api.PresubmitError 227 type = output_api.PresubmitError
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 stderr=input_api.subprocess.PIPE) 301 stderr=input_api.subprocess.PIPE)
300 stdoutdata, stderrdata = subproc.communicate() 302 stdoutdata, stderrdata = subproc.communicate()
301 # Discard the output if returncode == 0 303 # Discard the output if returncode == 0
302 if subproc.returncode: 304 if subproc.returncode:
303 outputs.append("Test '%s' failed with code %d\n%s\n%s\n" % ( 305 outputs.append("Test '%s' failed with code %d\n%s\n%s\n" % (
304 unit_test_name, subproc.returncode, stdoutdata, stderrdata)) 306 unit_test_name, subproc.returncode, stdoutdata, stderrdata))
305 if outputs: 307 if outputs:
306 return [message_type("%d unit tests failed." % len(outputs), 308 return [message_type("%d unit tests failed." % len(outputs),
307 long_text='\n'.join(outputs))] 309 long_text='\n'.join(outputs))]
308 return [] 310 return []
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698