OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/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 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
7 | 7 |
8 import exceptions | 8 import exceptions |
9 import os | 9 import os |
10 import StringIO | 10 import StringIO |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 | 1207 |
1208 def testCheckChangeSvnEolStyleUpload(self): | 1208 def testCheckChangeSvnEolStyleUpload(self): |
1209 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, | 1209 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, |
1210 'svn:eol-style', 'LF', '', False, | 1210 'svn:eol-style', 'LF', '', False, |
1211 presubmit.OutputApi.PresubmitNotifyResult, True) | 1211 presubmit.OutputApi.PresubmitNotifyResult, True) |
1212 | 1212 |
1213 def testCheckSvnForCommonMimeTypes(self): | 1213 def testCheckSvnForCommonMimeTypes(self): |
1214 self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty') | 1214 self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty') |
1215 input_api = self.MockInputApi(None, False) | 1215 input_api = self.MockInputApi(None, False) |
1216 output_api = presubmit.OutputApi() | 1216 output_api = presubmit.OutputApi() |
1217 input_api.AffectedFiles(include_deletes=False).AndReturn([ | 1217 A = lambda x: presubmit.AffectedFile(x, 'M') |
1218 'a.pdf', 'b.bmp', 'c.gif', 'd.png', 'e.jpg', 'f.ico']) | 1218 files = [ |
| 1219 A('a.pdf'), A('b.bmp'), A('c.gif'), A('d.png'), A('e.jpg'), A('f.jpe'), |
| 1220 A('random'), A('g.jpeg'), A('h.ico'), |
| 1221 ] |
| 1222 input_api.AffectedFiles(include_deletes=False).AndReturn(files) |
1219 presubmit_canned_checks.CheckSvnProperty( | 1223 presubmit_canned_checks.CheckSvnProperty( |
1220 input_api, output_api, 'svn:mime-type', 'application/pdf', ['a.pdf'] | 1224 input_api, output_api, 'svn:mime-type', 'application/pdf', [files[0]] |
1221 ).AndReturn([1]) | 1225 ).AndReturn([1]) |
1222 presubmit_canned_checks.CheckSvnProperty( | 1226 presubmit_canned_checks.CheckSvnProperty( |
1223 input_api, output_api, 'svn:mime-type', 'image/bmp', ['b.bmp'] | 1227 input_api, output_api, 'svn:mime-type', 'image/bmp', [files[1]] |
1224 ).AndReturn([2]) | 1228 ).AndReturn([2]) |
1225 presubmit_canned_checks.CheckSvnProperty( | 1229 presubmit_canned_checks.CheckSvnProperty( |
1226 input_api, output_api, 'svn:mime-type', 'image/gif', ['c.gif'] | 1230 input_api, output_api, 'svn:mime-type', 'image/gif', [files[2]] |
1227 ).AndReturn([3]) | 1231 ).AndReturn([3]) |
1228 presubmit_canned_checks.CheckSvnProperty( | 1232 presubmit_canned_checks.CheckSvnProperty( |
1229 input_api, output_api, 'svn:mime-type', 'image/png', ['d.png'] | 1233 input_api, output_api, 'svn:mime-type', 'image/png', [files[3]] |
1230 ).AndReturn([4]) | 1234 ).AndReturn([4]) |
1231 presubmit_canned_checks.CheckSvnProperty( | 1235 presubmit_canned_checks.CheckSvnProperty( |
1232 input_api, output_api, 'svn:mime-type', 'image/jpeg', ['e.jpg'] | 1236 input_api, output_api, 'svn:mime-type', 'image/jpeg', |
| 1237 [files[4], files[5], files[7]] |
1233 ).AndReturn([5]) | 1238 ).AndReturn([5]) |
1234 presubmit_canned_checks.CheckSvnProperty( | 1239 presubmit_canned_checks.CheckSvnProperty( |
1235 input_api, output_api, 'svn:mime-type', 'image/vnd.microsoft.icon', | 1240 input_api, output_api, 'svn:mime-type', 'image/vnd.microsoft.icon', |
1236 ['f.ico']).AndReturn([6]) | 1241 [files[8]]).AndReturn([6]) |
1237 self.mox.ReplayAll() | 1242 self.mox.ReplayAll() |
1238 | 1243 |
1239 results = presubmit_canned_checks.CheckSvnForCommonMimeTypes( | 1244 results = presubmit_canned_checks.CheckSvnForCommonMimeTypes( |
1240 input_api, output_api) | 1245 input_api, output_api) |
1241 self.assertEquals(results, [1, 2, 3, 4, 5, 6]) | 1246 self.assertEquals(results, [1, 2, 3, 4, 5, 6]) |
1242 | 1247 |
1243 def testCannedCheckTreeIsOpenOpen(self): | 1248 def testCannedCheckTreeIsOpenOpen(self): |
1244 input_api = self.MockInputApi(None, True) | 1249 input_api = self.MockInputApi(None, True) |
1245 connection = self.mox.CreateMockAnything() | 1250 connection = self.mox.CreateMockAnything() |
1246 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) | 1251 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 process.communicate().AndReturn(('', '')) | 1362 process.communicate().AndReturn(('', '')) |
1358 self.mox.ReplayAll() | 1363 self.mox.ReplayAll() |
1359 | 1364 |
1360 results = presubmit_canned_checks.RunPythonUnitTests( | 1365 results = presubmit_canned_checks.RunPythonUnitTests( |
1361 input_api, presubmit.OutputApi, ['test_module']) | 1366 input_api, presubmit.OutputApi, ['test_module']) |
1362 self.assertEquals(len(results), 0) | 1367 self.assertEquals(len(results), 0) |
1363 | 1368 |
1364 | 1369 |
1365 if __name__ == '__main__': | 1370 if __name__ == '__main__': |
1366 unittest.main() | 1371 unittest.main() |
OLD | NEW |