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 StringIO | 9 import StringIO |
10 import unittest | 10 import unittest |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 presubmit.os.path.splitext = os_path_splitext | 49 presubmit.os.path.splitext = os_path_splitext |
50 self.mox.StubOutWithMock(presubmit, 'sys') | 50 self.mox.StubOutWithMock(presubmit, 'sys') |
51 # Special mocks. | 51 # Special mocks. |
52 def MockAbsPath(f): | 52 def MockAbsPath(f): |
53 return f | 53 return f |
54 presubmit.os.path.abspath = MockAbsPath | 54 presubmit.os.path.abspath = MockAbsPath |
55 self.fake_root_dir = self.RootDir() | 55 self.fake_root_dir = self.RootDir() |
56 self.mox.StubOutWithMock(presubmit.gclient, 'CaptureSVNInfo') | 56 self.mox.StubOutWithMock(presubmit.gclient, 'CaptureSVNInfo') |
57 self.mox.StubOutWithMock(presubmit.gcl, 'GetSVNFileProperty') | 57 self.mox.StubOutWithMock(presubmit.gcl, 'GetSVNFileProperty') |
58 self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile') | 58 self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile') |
59 self.mox.StubOutWithMock(presubmit.gcl, 'ChangeInfo') | 59 # Stub any non-getter function in gcl.ChangeInfo. |
60 | 60 to_skip = lambda x: not x.startswith('_') and not x.startswith('Get') |
61 def MakeChangeInfo(self, name, issue, patchset, description): | 61 for member in filter(to_skip, dir(presubmit.gcl.ChangeInfo)): |
62 ci = self.mox.CreateMock(presubmit.gcl.ChangeInfo) | 62 self.mox.StubOutWithMock(presubmit.gcl.ChangeInfo, member) |
63 ci.name = name | 63 |
64 ci.issue = issue | 64 def MakeChangeInfo(self, name, issue, patchset, description, files): |
65 ci.patchset = patchset | 65 ci = presubmit.gcl.ChangeInfo(name, issue, patchset, description, files, |
66 ci.description = description | 66 self.fake_root_dir) |
67 ci.patch = None | |
68 ci.local_root = self.fake_root_dir | |
69 return ci | 67 return ci |
70 | 68 |
71 | 69 |
72 class PresubmitUnittest(PresubmitTestsBase): | 70 class PresubmitUnittest(PresubmitTestsBase): |
73 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 71 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" |
74 def testMembersChanged(self): | 72 def testMembersChanged(self): |
75 self.mox.ReplayAll() | 73 self.mox.ReplayAll() |
76 members = [ | 74 members = [ |
77 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', | 75 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', |
78 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', | 76 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 notfound, 'svn:mime-type').AndReturn('') | 163 notfound, 'svn:mime-type').AndReturn('') |
166 presubmit.gclient.CaptureSVNInfo(blat).AndReturn( | 164 presubmit.gclient.CaptureSVNInfo(blat).AndReturn( |
167 {'URL': 'svn:/foo/foo/blat.cc'}) | 165 {'URL': 'svn:/foo/foo/blat.cc'}) |
168 presubmit.gclient.CaptureSVNInfo(binary).AndReturn( | 166 presubmit.gclient.CaptureSVNInfo(binary).AndReturn( |
169 {'URL': 'svn:/foo/binary.dll'}) | 167 {'URL': 'svn:/foo/binary.dll'}) |
170 presubmit.gclient.CaptureSVNInfo(notfound).AndReturn({}) | 168 presubmit.gclient.CaptureSVNInfo(notfound).AndReturn({}) |
171 presubmit.gclient.CaptureSVNInfo(flap).AndReturn( | 169 presubmit.gclient.CaptureSVNInfo(flap).AndReturn( |
172 {'URL': 'svn:/foo/boo/flap.h'}) | 170 {'URL': 'svn:/foo/boo/flap.h'}) |
173 presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?') | 171 presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?') |
174 presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?') | 172 presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?') |
175 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines)) | 173 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines), |
176 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | 174 files) |
177 ci.GetFiles().AndReturn(files) | |
178 self.mox.ReplayAll() | 175 self.mox.ReplayAll() |
179 | 176 |
180 change = presubmit.GclChange(ci) | 177 change = presubmit.GclChange(ci) |
181 | 178 |
182 self.failUnless(change.Name() == 'mychange') | 179 self.failUnless(change.Name() == 'mychange') |
183 self.failUnless(change.DescriptionText() == | 180 self.failUnless(change.DescriptionText() == |
184 'Hello there\nthis is a change\nand some more regular text') | 181 'Hello there\nthis is a change\nand some more regular text') |
185 self.failUnless(change.FullDescriptionText() == | 182 self.failUnless(change.FullDescriptionText() == |
186 '\n'.join(description_lines)) | 183 '\n'.join(description_lines)) |
187 | 184 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 self.assertEquals(rhs_lines[3][2], 'there?') | 230 self.assertEquals(rhs_lines[3][2], 'there?') |
234 | 231 |
235 def testExecPresubmitScript(self): | 232 def testExecPresubmitScript(self): |
236 description_lines = ('Hello there', | 233 description_lines = ('Hello there', |
237 'this is a change', | 234 'this is a change', |
238 'STORY=http://tracker/123') | 235 'STORY=http://tracker/123') |
239 files = [ | 236 files = [ |
240 ['A', 'foo\\blat.cc'], | 237 ['A', 'foo\\blat.cc'], |
241 ] | 238 ] |
242 fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') | 239 fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') |
243 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines)) | 240 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines), |
244 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | 241 files) |
245 ci.GetFiles().AndReturn(files) | |
246 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
247 ci.GetFiles().AndReturn(files) | |
248 self.mox.ReplayAll() | 242 self.mox.ReplayAll() |
249 | 243 |
250 executer = presubmit.PresubmitExecuter(ci, False) | 244 executer = presubmit.PresubmitExecuter(ci, False) |
251 self.failIf(executer.ExecPresubmitScript('', fake_presubmit)) | 245 self.failIf(executer.ExecPresubmitScript('', fake_presubmit)) |
252 # No error if no on-upload entry point | 246 # No error if no on-upload entry point |
253 self.failIf(executer.ExecPresubmitScript( | 247 self.failIf(executer.ExecPresubmitScript( |
254 ('def CheckChangeOnCommit(input_api, output_api):\n' | 248 ('def CheckChangeOnCommit(input_api, output_api):\n' |
255 ' return (output_api.PresubmitError("!!"))\n'), | 249 ' return (output_api.PresubmitError("!!"))\n'), |
256 fake_presubmit | 250 fake_presubmit |
257 )) | 251 )) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 ['A', join('haspresubmit', 'blat.cc')], | 297 ['A', join('haspresubmit', 'blat.cc')], |
304 ] | 298 ] |
305 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') | 299 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') |
306 root_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 300 root_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
307 presubmit.os.path.isfile(root_path).AndReturn(True) | 301 presubmit.os.path.isfile(root_path).AndReturn(True) |
308 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) | 302 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) |
309 presubmit.gcl.ReadFile(root_path, | 303 presubmit.gcl.ReadFile(root_path, |
310 'rU').AndReturn(self.presubmit_text) | 304 'rU').AndReturn(self.presubmit_text) |
311 presubmit.gcl.ReadFile(haspresubmit_path, | 305 presubmit.gcl.ReadFile(haspresubmit_path, |
312 'rU').AndReturn(self.presubmit_text) | 306 'rU').AndReturn(self.presubmit_text) |
313 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines)) | 307 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines), |
314 ci.GetFileNames().AndReturn([item[1] for item in files]) | 308 files) |
315 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
316 ci.GetFiles().AndReturn(files) | |
317 self.mox.ReplayAll() | 309 self.mox.ReplayAll() |
318 | 310 |
319 output = StringIO.StringIO() | 311 output = StringIO.StringIO() |
320 input = StringIO.StringIO('y\n') | 312 input = StringIO.StringIO('y\n') |
321 | 313 |
322 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, | 314 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, |
323 None, False)) | 315 None, False)) |
324 self.assertEqual(output.getvalue().count('!!'), 2) | 316 self.assertEqual(output.getvalue().count('!!'), 2) |
325 | 317 |
326 def testDoPresubmitChecksPromptsAfterWarnings(self): | 318 def testDoPresubmitChecksPromptsAfterWarnings(self): |
327 join = presubmit.os.path.join | 319 join = presubmit.os.path.join |
328 description_lines = ('Hello there', | 320 description_lines = ('Hello there', |
329 'this is a change', | 321 'this is a change', |
330 'NOSUCHKEY=http://tracker/123') | 322 'NOSUCHKEY=http://tracker/123') |
331 files = [ | 323 files = [ |
332 ['A', join('haspresubmit', 'blat.cc')], | 324 ['A', join('haspresubmit', 'blat.cc')], |
333 ] | 325 ] |
334 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 326 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
335 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') | 327 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') |
336 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines)) | 328 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines), |
| 329 files) |
337 for i in range(2): | 330 for i in range(2): |
338 presubmit.os.path.isfile(presubmit_path).AndReturn(True) | 331 presubmit.os.path.isfile(presubmit_path).AndReturn(True) |
339 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) | 332 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) |
340 presubmit.gcl.ReadFile(presubmit_path, 'rU' | 333 presubmit.gcl.ReadFile(presubmit_path, 'rU' |
341 ).AndReturn(self.presubmit_text) | 334 ).AndReturn(self.presubmit_text) |
342 presubmit.gcl.ReadFile(haspresubmit_path, 'rU' | 335 presubmit.gcl.ReadFile(haspresubmit_path, 'rU' |
343 ).AndReturn(self.presubmit_text) | 336 ).AndReturn(self.presubmit_text) |
344 ci.GetFileNames().AndReturn([item[1] for item in files]) | |
345 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
346 ci.GetFiles().AndReturn(files) | |
347 self.mox.ReplayAll() | 337 self.mox.ReplayAll() |
348 | 338 |
349 output = StringIO.StringIO() | 339 output = StringIO.StringIO() |
350 input = StringIO.StringIO('n\n') # say no to the warning | 340 input = StringIO.StringIO('n\n') # say no to the warning |
351 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, | 341 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, |
352 None, True)) | 342 None, True)) |
353 self.assertEqual(output.getvalue().count('??'), 2) | 343 self.assertEqual(output.getvalue().count('??'), 2) |
354 | 344 |
355 output = StringIO.StringIO() | 345 output = StringIO.StringIO() |
356 input = StringIO.StringIO('y\n') # say yes to the warning | 346 input = StringIO.StringIO('y\n') # say yes to the warning |
(...skipping 11 matching lines...) Expand all Loading... |
368 ['A', join('haspresubmit', 'blat.cc')], | 358 ['A', join('haspresubmit', 'blat.cc')], |
369 ] | 359 ] |
370 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 360 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
371 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', | 361 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', |
372 'PRESUBMIT.py') | 362 'PRESUBMIT.py') |
373 presubmit.os.path.isfile(presubmit_path).AndReturn(True) | 363 presubmit.os.path.isfile(presubmit_path).AndReturn(True) |
374 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) | 364 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) |
375 presubmit.gcl.ReadFile(presubmit_path, 'rU').AndReturn(self.presubmit_text) | 365 presubmit.gcl.ReadFile(presubmit_path, 'rU').AndReturn(self.presubmit_text) |
376 presubmit.gcl.ReadFile(haspresubmit_path, 'rU').AndReturn( | 366 presubmit.gcl.ReadFile(haspresubmit_path, 'rU').AndReturn( |
377 self.presubmit_text) | 367 self.presubmit_text) |
378 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines)) | 368 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines), |
379 ci.GetFileNames().AndReturn([item[1] for item in files]) | 369 files) |
380 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
381 ci.GetFiles().AndReturn(files) | |
382 self.mox.ReplayAll() | 370 self.mox.ReplayAll() |
383 | 371 |
384 output = StringIO.StringIO() | 372 output = StringIO.StringIO() |
385 input = StringIO.StringIO() # should be unused | 373 input = StringIO.StringIO() # should be unused |
386 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, | 374 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, |
387 None, False)) | 375 None, False)) |
388 self.assertEqual(output.getvalue().count('??'), 2) | 376 self.assertEqual(output.getvalue().count('??'), 2) |
389 self.assertEqual(output.getvalue().count('XX!!XX'), 2) | 377 self.assertEqual(output.getvalue().count('XX!!XX'), 2) |
390 self.assertEqual(output.getvalue().count('(y/N)'), 0) | 378 self.assertEqual(output.getvalue().count('(y/N)'), 0) |
391 | 379 |
392 def testDoDefaultPresubmitChecks(self): | 380 def testDoDefaultPresubmitChecks(self): |
393 join = presubmit.os.path.join | 381 join = presubmit.os.path.join |
394 description_lines = ('Hello there', | 382 description_lines = ('Hello there', |
395 'this is a change', | 383 'this is a change', |
396 'STORY=http://tracker/123') | 384 'STORY=http://tracker/123') |
397 files = [ | 385 files = [ |
398 ['A', join('haspresubmit', 'blat.cc')], | 386 ['A', join('haspresubmit', 'blat.cc')], |
399 ] | 387 ] |
400 DEFAULT_SCRIPT = """ | 388 DEFAULT_SCRIPT = """ |
401 def CheckChangeOnUpload(input_api, output_api): | 389 def CheckChangeOnUpload(input_api, output_api): |
402 return [output_api.PresubmitError("!!")] | 390 return [output_api.PresubmitError("!!")] |
403 def CheckChangeOnCommit(input_api, output_api): | 391 def CheckChangeOnCommit(input_api, output_api): |
404 raise Exception("Test error") | 392 raise Exception("Test error") |
405 """ | 393 """ |
406 presubmit.os.path.isfile(join(self.fake_root_dir, 'PRESUBMIT.py') | 394 presubmit.os.path.isfile(join(self.fake_root_dir, 'PRESUBMIT.py') |
407 ).AndReturn(False) | 395 ).AndReturn(False) |
408 presubmit.os.path.isfile(join(self.fake_root_dir, | 396 presubmit.os.path.isfile(join(self.fake_root_dir, |
409 'haspresubmit', | 397 'haspresubmit', |
410 'PRESUBMIT.py')).AndReturn(False) | 398 'PRESUBMIT.py')).AndReturn(False) |
411 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines)) | 399 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines), |
412 ci.GetFileNames().AndReturn([item[1] for item in files]) | 400 files) |
413 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
414 ci.GetFiles().AndReturn(files) | |
415 self.mox.ReplayAll() | 401 self.mox.ReplayAll() |
416 | 402 |
417 output = StringIO.StringIO() | 403 output = StringIO.StringIO() |
418 input = StringIO.StringIO('y\n') | 404 input = StringIO.StringIO('y\n') |
419 # Always fail. | 405 # Always fail. |
420 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, | 406 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, |
421 DEFAULT_SCRIPT, False)) | 407 DEFAULT_SCRIPT, False)) |
422 self.assertEquals(output.getvalue().count('!!'), 1) | 408 self.assertEquals(output.getvalue().count('!!'), 1) |
423 | 409 |
424 def testDirectoryHandling(self): | 410 def testDirectoryHandling(self): |
425 files = [ | 411 files = [ |
426 ['A', 'isdir'], | 412 ['A', 'isdir'], |
427 ['A', 'isdir\\blat.cc'], | 413 ['A', 'isdir\\blat.cc'], |
428 ] | 414 ] |
429 isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir') | 415 isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir') |
430 blat = presubmit.os.path.join(isdir, 'blat.cc') | 416 blat = presubmit.os.path.join(isdir, 'blat.cc') |
431 presubmit.os.path.exists(isdir).AndReturn(True) | 417 presubmit.os.path.exists(isdir).AndReturn(True) |
432 presubmit.os.path.isdir(isdir).AndReturn(True) | 418 presubmit.os.path.isdir(isdir).AndReturn(True) |
433 presubmit.os.path.exists(blat).AndReturn(True) | 419 presubmit.os.path.exists(blat).AndReturn(True) |
434 presubmit.os.path.isdir(blat).AndReturn(False) | 420 presubmit.os.path.isdir(blat).AndReturn(False) |
435 ci = self.MakeChangeInfo('mychange', 0, 0, 'foo') | 421 ci = self.MakeChangeInfo('mychange', 0, 0, 'foo', files) |
436 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
437 ci.GetFiles().AndReturn(files) | |
438 self.mox.ReplayAll() | 422 self.mox.ReplayAll() |
439 | 423 |
440 change = presubmit.GclChange(ci) | 424 change = presubmit.GclChange(ci) |
441 affected_files = change.AffectedFiles(include_dirs=False) | 425 affected_files = change.AffectedFiles(include_dirs=False) |
442 self.failUnless(len(affected_files) == 1) | 426 self.failUnless(len(affected_files) == 1) |
443 self.failUnless(affected_files[0].LocalPath().endswith('blat.cc')) | 427 self.failUnless(affected_files[0].LocalPath().endswith('blat.cc')) |
444 affected_files_and_dirs = change.AffectedFiles(include_dirs=True) | 428 affected_files_and_dirs = change.AffectedFiles(include_dirs=True) |
445 self.failUnless(len(affected_files_and_dirs) == 2) | 429 self.failUnless(len(affected_files_and_dirs) == 2) |
446 | 430 |
447 def testTags(self): | 431 def testTags(self): |
(...skipping 21 matching lines...) Expand all Loading... |
469 input_api.change.DescriptionText())] | 453 input_api.change.DescriptionText())] |
470 if (input_api.change.FullDescriptionText() != | 454 if (input_api.change.FullDescriptionText() != |
471 'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'): | 455 'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'): |
472 return [output_api.PresubmitError('Tag parsing failed. 5 ' + | 456 return [output_api.PresubmitError('Tag parsing failed. 5 ' + |
473 input_api.change.FullDescriptionText())] | 457 input_api.change.FullDescriptionText())] |
474 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])] | 458 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])] |
475 def CheckChangeOnCommit(input_api, output_api): | 459 def CheckChangeOnCommit(input_api, output_api): |
476 raise Exception("Test error") | 460 raise Exception("Test error") |
477 """ | 461 """ |
478 ci = self.MakeChangeInfo( | 462 ci = self.MakeChangeInfo( |
479 'foo', 0, 0, "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n") | 463 'foo', 0, 0, "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n", |
480 ci.GetFileNames().AndReturn([]) | 464 None) |
481 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
482 ci.GetFiles().AndReturn([]) | |
483 self.mox.ReplayAll() | 465 self.mox.ReplayAll() |
484 | 466 |
485 output = StringIO.StringIO() | 467 output = StringIO.StringIO() |
486 input = StringIO.StringIO('y\n') | 468 input = StringIO.StringIO('y\n') |
487 self.failUnless(presubmit.DoPresubmitChecks(ci, False, True, output, | 469 self.failUnless(presubmit.DoPresubmitChecks(ci, False, True, output, |
488 input, DEFAULT_SCRIPT, False)) | 470 input, DEFAULT_SCRIPT, False)) |
489 self.assertEquals(output.getvalue(), | 471 self.assertEquals(output.getvalue(), |
490 ('Warning, no presubmit.py found.\n' | 472 ('Warning, no presubmit.py found.\n' |
491 'Running default presubmit script.\n' | 473 'Running default presubmit script.\n' |
492 '** Presubmit Messages **\n' | 474 '** Presubmit Messages **\n' |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) | 565 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) |
584 presubmit.gcl.GetSVNFileProperty(readme, 'svn:mime-type').AndReturn(None) | 566 presubmit.gcl.GetSVNFileProperty(readme, 'svn:mime-type').AndReturn(None) |
585 presubmit.gcl.GetSVNFileProperty(binary, 'svn:mime-type').AndReturn( | 567 presubmit.gcl.GetSVNFileProperty(binary, 'svn:mime-type').AndReturn( |
586 'application/octet-stream') | 568 'application/octet-stream') |
587 presubmit.gcl.GetSVNFileProperty(weird, 'svn:mime-type').AndReturn(None) | 569 presubmit.gcl.GetSVNFileProperty(weird, 'svn:mime-type').AndReturn(None) |
588 presubmit.gcl.GetSVNFileProperty(another, 'svn:mime-type').AndReturn(None) | 570 presubmit.gcl.GetSVNFileProperty(another, 'svn:mime-type').AndReturn(None) |
589 presubmit.gcl.GetSVNFileProperty(third_party, 'svn:mime-type' | 571 presubmit.gcl.GetSVNFileProperty(third_party, 'svn:mime-type' |
590 ).AndReturn(None) | 572 ).AndReturn(None) |
591 presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie') | 573 presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie') |
592 presubmit.gcl.ReadFile(another).AndReturn('whatever\ncookie2') | 574 presubmit.gcl.ReadFile(another).AndReturn('whatever\ncookie2') |
593 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines)) | 575 ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines), |
594 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | 576 files) |
595 ci.GetFiles().AndReturn(files) | |
596 self.mox.ReplayAll() | 577 self.mox.ReplayAll() |
597 | 578 |
598 change = presubmit.GclChange(ci) | 579 change = presubmit.GclChange(ci) |
599 input_api = presubmit.InputApi(change, | 580 input_api = presubmit.InputApi(change, |
600 join(self.fake_root_dir, 'foo', | 581 join(self.fake_root_dir, 'foo', |
601 'PRESUBMIT.py'), | 582 'PRESUBMIT.py'), |
602 False) | 583 False) |
603 # Doesn't filter much | 584 # Doesn't filter much |
604 got_files = input_api.AffectedFiles() | 585 got_files = input_api.AffectedFiles() |
605 self.assertEquals(len(got_files), 7) | 586 self.assertEquals(len(got_files), 7) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 | 678 |
698 def testCustomFilter(self): | 679 def testCustomFilter(self): |
699 def FilterSourceFile(affected_file): | 680 def FilterSourceFile(affected_file): |
700 return 'a' in affected_file.LocalPath() | 681 return 'a' in affected_file.LocalPath() |
701 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')] | 682 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')] |
702 for (action, item) in files: | 683 for (action, item) in files: |
703 item = presubmit.os.path.join(self.fake_root_dir, item) | 684 item = presubmit.os.path.join(self.fake_root_dir, item) |
704 presubmit.os.path.exists(item).AndReturn(True) | 685 presubmit.os.path.exists(item).AndReturn(True) |
705 presubmit.os.path.isdir(item).AndReturn(False) | 686 presubmit.os.path.isdir(item).AndReturn(False) |
706 presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) | 687 presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) |
707 ci = self.MakeChangeInfo('mychange', 0, 0, '') | 688 ci = self.MakeChangeInfo('mychange', 0, 0, '', files) |
708 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
709 ci.GetFiles().AndReturn(files) | |
710 self.mox.ReplayAll() | 689 self.mox.ReplayAll() |
711 | 690 |
712 change = presubmit.GclChange(ci) | 691 change = presubmit.GclChange(ci) |
713 input_api = presubmit.InputApi(change, | 692 input_api = presubmit.InputApi(change, |
714 presubmit.os.path.join(self.fake_root_dir, | 693 presubmit.os.path.join(self.fake_root_dir, |
715 'PRESUBMIT.py'), | 694 'PRESUBMIT.py'), |
716 False) | 695 False) |
717 got_files = input_api.AffectedSourceFiles(FilterSourceFile) | 696 got_files = input_api.AffectedSourceFiles(FilterSourceFile) |
718 self.assertEquals(len(got_files), 2) | 697 self.assertEquals(len(got_files), 2) |
719 self.assertEquals(got_files[0].LocalPath(), 'eeaee') | 698 self.assertEquals(got_files[0].LocalPath(), 'eeaee') |
720 self.assertEquals(got_files[1].LocalPath(), 'eeabee') | 699 self.assertEquals(got_files[1].LocalPath(), 'eeabee') |
721 | 700 |
722 def testLambdaFilter(self): | 701 def testLambdaFilter(self): |
723 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",) | 702 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",) |
724 black_list = [r".*?b.*?"] | 703 black_list = [r".*?b.*?"] |
725 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')] | 704 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')] |
726 for (action, item) in files: | 705 for (action, item) in files: |
727 item = presubmit.os.path.join(self.fake_root_dir, item) | 706 item = presubmit.os.path.join(self.fake_root_dir, item) |
728 presubmit.os.path.exists(item).AndReturn(True) | 707 presubmit.os.path.exists(item).AndReturn(True) |
729 presubmit.os.path.isdir(item).AndReturn(False) | 708 presubmit.os.path.isdir(item).AndReturn(False) |
730 presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) | 709 presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) |
731 ci = self.MakeChangeInfo('mychange', 0, 0, '') | 710 ci = self.MakeChangeInfo('mychange', 0, 0, '', files) |
732 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
733 ci.GetFiles().AndReturn(files) | |
734 self.mox.ReplayAll() | 711 self.mox.ReplayAll() |
735 | 712 |
736 change = presubmit.GclChange(ci) | 713 change = presubmit.GclChange(ci) |
737 input_api = presubmit.InputApi(change, './PRESUBMIT.py', False) | 714 input_api = presubmit.InputApi(change, './PRESUBMIT.py', False) |
738 # Sample usage of overiding the default white and black lists. | 715 # Sample usage of overiding the default white and black lists. |
739 got_files = input_api.AffectedSourceFiles( | 716 got_files = input_api.AffectedSourceFiles( |
740 lambda x: input_api.FilterSourceFile(x, white_list, black_list)) | 717 lambda x: input_api.FilterSourceFile(x, white_list, black_list)) |
741 self.assertEquals(len(got_files), 2) | 718 self.assertEquals(len(got_files), 2) |
742 self.assertEquals(got_files[0].LocalPath(), 'eeaee') | 719 self.assertEquals(got_files[0].LocalPath(), 'eeaee') |
743 self.assertEquals(got_files[1].LocalPath(), 'eecaee') | 720 self.assertEquals(got_files[1].LocalPath(), 'eecaee') |
744 | 721 |
745 def testGetAbsoluteLocalPath(self): | 722 def testGetAbsoluteLocalPath(self): |
746 join = presubmit.os.path.join | 723 join = presubmit.os.path.join |
747 normpath = presubmit.normpath | 724 normpath = presubmit.normpath |
748 # Regression test for bug of presubmit stuff that relies on invoking | 725 # Regression test for bug of presubmit stuff that relies on invoking |
749 # SVN (e.g. to get mime type of file) not working unless gcl invoked | 726 # SVN (e.g. to get mime type of file) not working unless gcl invoked |
750 # from the client root (e.g. if you were at 'src' and did 'cd base' before | 727 # from the client root (e.g. if you were at 'src' and did 'cd base' before |
751 # invoking 'gcl upload' it would fail because svn wouldn't find the files | 728 # invoking 'gcl upload' it would fail because svn wouldn't find the files |
752 # the presubmit script was asking about). | 729 # the presubmit script was asking about). |
753 files = [ | 730 files = [ |
754 ['A', 'isdir'], | 731 ['A', 'isdir'], |
755 ['A', join('isdir', 'blat.cc')], | 732 ['A', join('isdir', 'blat.cc')], |
756 ['M', join('elsewhere', 'ouf.cc')], | 733 ['M', join('elsewhere', 'ouf.cc')], |
757 ] | 734 ] |
758 ci = self.MakeChangeInfo('mychange', 0, 0, '') | 735 ci = self.MakeChangeInfo('mychange', 0, 0, '', files) |
759 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
760 ci.GetFiles().AndReturn(files) | |
761 self.mox.ReplayAll() | 736 self.mox.ReplayAll() |
762 | 737 |
763 # It doesn't make sense on non-Windows platform. This is somewhat hacky, | 738 # It doesn't make sense on non-Windows platform. This is somewhat hacky, |
764 # but it is needed since we can't just use os.path.join('c:', 'temp'). | 739 # but it is needed since we can't just use os.path.join('c:', 'temp'). |
765 change = presubmit.GclChange(ci) | 740 change = presubmit.GclChange(ci) |
766 affected_files = change.AffectedFiles(include_dirs=True) | 741 affected_files = change.AffectedFiles(include_dirs=True) |
767 # Local paths should remain the same | 742 # Local paths should remain the same |
768 self.assertEquals(affected_files[0].LocalPath(), normpath('isdir')) | 743 self.assertEquals(affected_files[0].LocalPath(), normpath('isdir')) |
769 self.assertEquals(affected_files[1].LocalPath(), normpath('isdir/blat.cc')) | 744 self.assertEquals(affected_files[1].LocalPath(), normpath('isdir/blat.cc')) |
770 # Absolute paths should be prefixed | 745 # Absolute paths should be prefixed |
(...skipping 13 matching lines...) Expand all Loading... |
784 self.assertEqual(len(paths_from_api), 2) | 759 self.assertEqual(len(paths_from_api), 2) |
785 for absolute_paths in [paths_from_change, paths_from_api]: | 760 for absolute_paths in [paths_from_change, paths_from_api]: |
786 self.assertEqual(absolute_paths[0], | 761 self.assertEqual(absolute_paths[0], |
787 normpath(join(self.fake_root_dir, 'isdir'))) | 762 normpath(join(self.fake_root_dir, 'isdir'))) |
788 self.assertEqual(absolute_paths[1], | 763 self.assertEqual(absolute_paths[1], |
789 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) | 764 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) |
790 | 765 |
791 def testDeprecated(self): | 766 def testDeprecated(self): |
792 presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), | 767 presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), |
793 stacklevel=2) | 768 stacklevel=2) |
794 ci = self.MakeChangeInfo('mychange', 0, 0, 'Bleh\n') | 769 ci = self.MakeChangeInfo('mychange', 0, 0, 'Bleh\n', []) |
795 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
796 ci.GetFiles().AndReturn([]) | |
797 self.mox.ReplayAll() | 770 self.mox.ReplayAll() |
798 | 771 |
799 change = presubmit.GclChange(ci) | 772 change = presubmit.GclChange(ci) |
800 api = presubmit.InputApi( | 773 api = presubmit.InputApi( |
801 change, | 774 change, |
802 presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True) | 775 presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True) |
803 api.AffectedTextFiles(include_deletes=False) | 776 api.AffectedTextFiles(include_deletes=False) |
804 | 777 |
805 def testReadFileStringDenied(self): | 778 def testReadFileStringDenied(self): |
806 ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n') | 779 ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')]) |
807 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
808 ci.GetFiles().AndReturn([('M', 'AA')]) | |
809 self.mox.ReplayAll() | 780 self.mox.ReplayAll() |
810 | 781 |
811 input_api = presubmit.InputApi( | 782 input_api = presubmit.InputApi( |
812 None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) | 783 None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) |
813 input_api.change = presubmit.GclChange(ci) | 784 input_api.change = presubmit.GclChange(ci) |
814 self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x') | 785 self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x') |
815 | 786 |
816 def testReadFileStringAccepted(self): | 787 def testReadFileStringAccepted(self): |
817 ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n') | 788 ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')]) |
818 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
819 path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo') | 789 path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo') |
820 ci.GetFiles().AndReturn([('M', 'AA')]) | |
821 presubmit.gcl.ReadFile(path, 'x').AndReturn(None) | 790 presubmit.gcl.ReadFile(path, 'x').AndReturn(None) |
822 self.mox.ReplayAll() | 791 self.mox.ReplayAll() |
823 | 792 |
824 input_api = presubmit.InputApi( | 793 input_api = presubmit.InputApi( |
825 None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) | 794 None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) |
826 input_api.change = presubmit.GclChange(ci) | 795 input_api.change = presubmit.GclChange(ci) |
827 input_api.ReadFile(path, 'x') | 796 input_api.ReadFile(path, 'x') |
828 | 797 |
829 def testReadFileAffectedFileDenied(self): | 798 def testReadFileAffectedFileDenied(self): |
830 ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n') | 799 ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')]) |
831 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
832 ci.GetFiles().AndReturn([('M', 'AA')]) | |
833 file = presubmit.AffectedFile('boo', 'M', 'Unrelated') | 800 file = presubmit.AffectedFile('boo', 'M', 'Unrelated') |
834 self.mox.ReplayAll() | 801 self.mox.ReplayAll() |
835 | 802 |
836 input_api = presubmit.InputApi( | 803 input_api = presubmit.InputApi( |
837 None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) | 804 None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) |
838 input_api.change = presubmit.GclChange(ci) | 805 input_api.change = presubmit.GclChange(ci) |
839 self.assertRaises(IOError, input_api.ReadFile, file, 'x') | 806 self.assertRaises(IOError, input_api.ReadFile, file, 'x') |
840 | 807 |
841 def testReadFileAffectedFileAccepted(self): | 808 def testReadFileAffectedFileAccepted(self): |
842 ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n') | 809 ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')]) |
843 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
844 ci.GetFiles().AndReturn([('M', 'AA')]) | |
845 file = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir) | 810 file = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir) |
846 presubmit.gcl.ReadFile(file.AbsoluteLocalPath(), 'x').AndReturn(None) | 811 presubmit.gcl.ReadFile(file.AbsoluteLocalPath(), 'x').AndReturn(None) |
847 self.mox.ReplayAll() | 812 self.mox.ReplayAll() |
848 | 813 |
849 input_api = presubmit.InputApi( | 814 input_api = presubmit.InputApi( |
850 None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) | 815 None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) |
851 input_api.change = presubmit.GclChange(ci) | 816 input_api.change = presubmit.GclChange(ci) |
852 input_api.ReadFile(file, 'x') | 817 input_api.ReadFile(file, 'x') |
853 | 818 |
854 | 819 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 | 953 |
989 class GclChangeUnittest(PresubmitTestsBase): | 954 class GclChangeUnittest(PresubmitTestsBase): |
990 def testMembersChanged(self): | 955 def testMembersChanged(self): |
991 members = [ | 956 members = [ |
992 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', | 957 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', |
993 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', | 958 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', |
994 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', | 959 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', |
995 'issue', 'patchset', 'tags', | 960 'issue', 'patchset', 'tags', |
996 ] | 961 ] |
997 # If this test fails, you should add the relevant test. | 962 # If this test fails, you should add the relevant test. |
998 ci = self.MakeChangeInfo('', 0, 0, '') | 963 ci = self.MakeChangeInfo('', 0, 0, '', []) |
999 ci.GetLocalRoot().AndReturn(self.fake_root_dir) | |
1000 ci.GetFiles().AndReturn([]) | |
1001 self.mox.ReplayAll() | 964 self.mox.ReplayAll() |
1002 | 965 |
1003 self.compareMembers(presubmit.GclChange(ci), members) | 966 self.compareMembers(presubmit.GclChange(ci), members) |
1004 | 967 |
1005 | 968 |
1006 class CannedChecksUnittest(PresubmitTestsBase): | 969 class CannedChecksUnittest(PresubmitTestsBase): |
1007 """Tests presubmit_canned_checks.py.""" | 970 """Tests presubmit_canned_checks.py.""" |
1008 | 971 |
1009 def setUp(self): | 972 def setUp(self): |
1010 PresubmitTestsBase.setUp(self) | 973 PresubmitTestsBase.setUp(self) |
(...skipping 22 matching lines...) Expand all Loading... |
1033 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', | 996 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', |
1034 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', | 997 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', |
1035 ] | 998 ] |
1036 # If this test fails, you should add the relevant test. | 999 # If this test fails, you should add the relevant test. |
1037 self.compareMembers(presubmit_canned_checks, members) | 1000 self.compareMembers(presubmit_canned_checks, members) |
1038 | 1001 |
1039 def DescriptionTest(self, check, description1, description2, error_type, | 1002 def DescriptionTest(self, check, description1, description2, error_type, |
1040 committing): | 1003 committing): |
1041 input_api1 = self.MockInputApi() | 1004 input_api1 = self.MockInputApi() |
1042 input_api1.is_committing = committing | 1005 input_api1.is_committing = committing |
1043 ci1 = self.MakeChangeInfo('foo', 0, 0, description1) | 1006 ci1 = self.MakeChangeInfo('foo', 0, 0, description1, []) |
1044 ci1.GetLocalRoot().AndReturn(self.fake_root_dir) | |
1045 ci1.GetFiles().AndReturn([]) | |
1046 input_api2 = self.MockInputApi() | 1007 input_api2 = self.MockInputApi() |
1047 input_api2.is_committing = committing | 1008 input_api2.is_committing = committing |
1048 ci2 = self.MakeChangeInfo('foo', 0, 0, description2) | 1009 ci2 = self.MakeChangeInfo('foo', 0, 0, description2, []) |
1049 ci2.GetLocalRoot().AndReturn(self.fake_root_dir) | |
1050 ci2.GetFiles().AndReturn([]) | |
1051 self.mox.ReplayAll() | 1010 self.mox.ReplayAll() |
1052 | 1011 |
1053 input_api1.change = presubmit.GclChange(ci1) | 1012 input_api1.change = presubmit.GclChange(ci1) |
1054 input_api2.change = presubmit.GclChange(ci2) | 1013 input_api2.change = presubmit.GclChange(ci2) |
1055 results1 = check(input_api1, presubmit.OutputApi) | 1014 results1 = check(input_api1, presubmit.OutputApi) |
1056 self.assertEquals(results1, []) | 1015 self.assertEquals(results1, []) |
1057 results2 = check(input_api2, presubmit.OutputApi) | 1016 results2 = check(input_api2, presubmit.OutputApi) |
1058 self.assertEquals(len(results2), 1) | 1017 self.assertEquals(len(results2), 1) |
1059 self.assertEquals(results2[0].__class__, error_type) | 1018 self.assertEquals(results2[0].__class__, error_type) |
1060 | 1019 |
1061 def ContentTest(self, check, content1, content2, error_type): | 1020 def ContentTest(self, check, content1, content2, error_type): |
1062 input_api1 = self.MockInputApi() | 1021 input_api1 = self.MockInputApi() |
1063 ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n') | 1022 ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n', []) |
1064 ci1.GetLocalRoot().AndReturn(self.fake_root_dir) | |
1065 ci1.GetFiles().AndReturn([]) | |
1066 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 1023 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
1067 affected_file.LocalPath().AndReturn('foo.cc') | 1024 affected_file.LocalPath().AndReturn('foo.cc') |
1068 output1 = [ | 1025 output1 = [ |
1069 (affected_file, 42, 'yo, ' + content1), | 1026 (affected_file, 42, 'yo, ' + content1), |
1070 (affected_file, 43, 'yer'), | 1027 (affected_file, 43, 'yer'), |
1071 (affected_file, 23, 'ya'), | 1028 (affected_file, 23, 'ya'), |
1072 ] | 1029 ] |
1073 input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1) | 1030 input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1) |
1074 input_api2 = self.MockInputApi() | 1031 input_api2 = self.MockInputApi() |
1075 ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n') | 1032 ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n', None) |
1076 ci2.GetLocalRoot().AndReturn(self.fake_root_dir) | |
1077 ci2.GetFiles().AndReturn([]) | |
1078 output2 = [ | 1033 output2 = [ |
1079 (affected_file, 42, 'yo, ' + content2), | 1034 (affected_file, 42, 'yo, ' + content2), |
1080 (affected_file, 43, 'yer'), | 1035 (affected_file, 43, 'yer'), |
1081 (affected_file, 23, 'ya'), | 1036 (affected_file, 23, 'ya'), |
1082 ] | 1037 ] |
1083 input_api2.RightHandSideLines(mox.IgnoreArg()).AndReturn(output2) | 1038 input_api2.RightHandSideLines(mox.IgnoreArg()).AndReturn(output2) |
1084 self.mox.ReplayAll() | 1039 self.mox.ReplayAll() |
1085 | 1040 |
1086 input_api1.change = presubmit.GclChange(ci1) | 1041 input_api1.change = presubmit.GclChange(ci1) |
1087 input_api2.change = presubmit.GclChange(ci2) | 1042 input_api2.change = presubmit.GclChange(ci2) |
1088 results1 = check(input_api1, presubmit.OutputApi, None) | 1043 results1 = check(input_api1, presubmit.OutputApi, None) |
1089 self.assertEquals(results1, []) | 1044 self.assertEquals(results1, []) |
1090 results2 = check(input_api2, presubmit.OutputApi, None) | 1045 results2 = check(input_api2, presubmit.OutputApi, None) |
1091 self.assertEquals(len(results2), 1) | 1046 self.assertEquals(len(results2), 1) |
1092 self.assertEquals(results2[0].__class__, error_type) | 1047 self.assertEquals(results2[0].__class__, error_type) |
1093 | 1048 |
1094 def ReadFileTest(self, check, content1, content2, error_type): | 1049 def ReadFileTest(self, check, content1, content2, error_type): |
1095 input_api1 = self.MockInputApi() | 1050 input_api1 = self.MockInputApi() |
1096 self.mox.StubOutWithMock(input_api1, 'ReadFile') | 1051 self.mox.StubOutWithMock(input_api1, 'ReadFile') |
1097 ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n') | 1052 ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n', None) |
1098 ci1.GetLocalRoot().AndReturn(self.fake_root_dir) | |
1099 ci1.GetFiles().AndReturn([]) | |
1100 affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile) | 1053 affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile) |
1101 input_api1.AffectedSourceFiles(None).AndReturn([affected_file1]) | 1054 input_api1.AffectedSourceFiles(None).AndReturn([affected_file1]) |
1102 input_api1.ReadFile(affected_file1, 'rb').AndReturn(content1) | 1055 input_api1.ReadFile(affected_file1, 'rb').AndReturn(content1) |
1103 input_api2 = self.MockInputApi() | 1056 input_api2 = self.MockInputApi() |
1104 self.mox.StubOutWithMock(input_api2, 'ReadFile') | 1057 self.mox.StubOutWithMock(input_api2, 'ReadFile') |
1105 ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n') | 1058 ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n', []) |
1106 ci2.GetLocalRoot().AndReturn(self.fake_root_dir) | |
1107 ci2.GetFiles().AndReturn([]) | |
1108 affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile) | 1059 affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile) |
1109 input_api2.AffectedSourceFiles(None).AndReturn([affected_file2]) | 1060 input_api2.AffectedSourceFiles(None).AndReturn([affected_file2]) |
1110 input_api2.ReadFile(affected_file2, 'rb').AndReturn(content2) | 1061 input_api2.ReadFile(affected_file2, 'rb').AndReturn(content2) |
1111 affected_file2.LocalPath().AndReturn('bar.cc') | 1062 affected_file2.LocalPath().AndReturn('bar.cc') |
1112 self.mox.ReplayAll() | 1063 self.mox.ReplayAll() |
1113 | 1064 |
1114 input_api1.change = presubmit.GclChange(ci1) | 1065 input_api1.change = presubmit.GclChange(ci1) |
1115 input_api2.change = presubmit.GclChange(ci2) | 1066 input_api2.change = presubmit.GclChange(ci2) |
1116 results = check(input_api1, presubmit.OutputApi) | 1067 results = check(input_api1, presubmit.OutputApi) |
1117 self.assertEquals(results, []) | 1068 self.assertEquals(results, []) |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1411 test_result.errors = 0 | 1362 test_result.errors = 0 |
1412 self.mox.ReplayAll() | 1363 self.mox.ReplayAll() |
1413 | 1364 |
1414 results = presubmit_canned_checks.RunPythonUnitTests( | 1365 results = presubmit_canned_checks.RunPythonUnitTests( |
1415 input_api, presubmit.OutputApi, ['test_module']) | 1366 input_api, presubmit.OutputApi, ['test_module']) |
1416 self.assertEquals(len(results), 0) | 1367 self.assertEquals(len(results), 0) |
1417 | 1368 |
1418 | 1369 |
1419 if __name__ == '__main__': | 1370 if __name__ == '__main__': |
1420 unittest.main() | 1371 unittest.main() |
OLD | NEW |