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 random | 9 import random |
10 import string | 10 import string |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 {'URL': 'svn:/foo/foo/blat.cc'}) | 190 {'URL': 'svn:/foo/foo/blat.cc'}) |
191 presubmit.gclient.CaptureSVNInfo('binary.dll').AndReturn( | 191 presubmit.gclient.CaptureSVNInfo('binary.dll').AndReturn( |
192 {'URL': 'svn:/foo/binary.dll'}) | 192 {'URL': 'svn:/foo/binary.dll'}) |
193 presubmit.gclient.CaptureSVNInfo(notfound).AndReturn({}) | 193 presubmit.gclient.CaptureSVNInfo(notfound).AndReturn({}) |
194 presubmit.gclient.CaptureSVNInfo(flap).AndReturn( | 194 presubmit.gclient.CaptureSVNInfo(flap).AndReturn( |
195 {'URL': 'svn:/foo/boo/flap.h'}) | 195 {'URL': 'svn:/foo/boo/flap.h'}) |
196 presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?') | 196 presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?') |
197 presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?') | 197 presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?') |
198 self.mox.ReplayAll() | 198 self.mox.ReplayAll() |
199 | 199 |
200 ci = presubmit.gcl.ChangeInfo(name='mychange', | 200 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
201 description='\n'.join(description_lines), | 201 description='\n'.join(description_lines), |
202 files=files) | 202 files=files) |
203 change = presubmit.GclChange(ci) | 203 change = presubmit.GclChange(ci) |
204 | 204 |
205 self.failUnless(change.Change() == 'mychange') | 205 self.failUnless(change.Change() == 'mychange') |
206 self.failUnless(change.DescriptionText() == | 206 self.failUnless(change.DescriptionText() == |
207 'Hello there\nthis is a change\nand some more regular text') | 207 'Hello there\nthis is a change\nand some more regular text') |
208 self.failUnless(change.FullDescriptionText() == | 208 self.failUnless(change.FullDescriptionText() == |
209 '\n'.join(description_lines)) | 209 '\n'.join(description_lines)) |
210 | 210 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 def testExecPresubmitScript(self): | 258 def testExecPresubmitScript(self): |
259 description_lines = ('Hello there', | 259 description_lines = ('Hello there', |
260 'this is a change', | 260 'this is a change', |
261 'STORY=http://tracker/123') | 261 'STORY=http://tracker/123') |
262 files = [ | 262 files = [ |
263 ['A', 'foo\\blat.cc'], | 263 ['A', 'foo\\blat.cc'], |
264 ] | 264 ] |
265 fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') | 265 fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') |
266 self.mox.ReplayAll() | 266 self.mox.ReplayAll() |
267 | 267 |
268 ci = presubmit.gcl.ChangeInfo(name='mychange', | 268 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
269 description='\n'.join(description_lines), | 269 description='\n'.join(description_lines), |
270 files=files) | 270 files=files) |
271 | 271 |
272 executer = presubmit.PresubmitExecuter(ci, False) | 272 executer = presubmit.PresubmitExecuter(ci, False) |
273 self.failIf(executer.ExecPresubmitScript('', fake_presubmit)) | 273 self.failIf(executer.ExecPresubmitScript('', fake_presubmit)) |
274 # No error if no on-upload entry point | 274 # No error if no on-upload entry point |
275 self.failIf(executer.ExecPresubmitScript( | 275 self.failIf(executer.ExecPresubmitScript( |
276 ('def CheckChangeOnCommit(input_api, output_api):\n' | 276 ('def CheckChangeOnCommit(input_api, output_api):\n' |
277 ' return (output_api.PresubmitError("!!"))\n'), | 277 ' return (output_api.PresubmitError("!!"))\n'), |
278 fake_presubmit | 278 fake_presubmit |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') | 327 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') |
328 root_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 328 root_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
329 presubmit.os.path.isfile(root_path).AndReturn(True) | 329 presubmit.os.path.isfile(root_path).AndReturn(True) |
330 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) | 330 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) |
331 presubmit.gcl.ReadFile(root_path, | 331 presubmit.gcl.ReadFile(root_path, |
332 'rU').AndReturn(self.presubmit_text) | 332 'rU').AndReturn(self.presubmit_text) |
333 presubmit.gcl.ReadFile(haspresubmit_path, | 333 presubmit.gcl.ReadFile(haspresubmit_path, |
334 'rU').AndReturn(self.presubmit_text) | 334 'rU').AndReturn(self.presubmit_text) |
335 self.mox.ReplayAll() | 335 self.mox.ReplayAll() |
336 | 336 |
337 ci = presubmit.gcl.ChangeInfo(name='mychange', | 337 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
338 description='\n'.join(description_lines), | 338 description='\n'.join(description_lines), |
339 files=files) | 339 files=files) |
340 | 340 |
341 output = StringIO.StringIO() | 341 output = StringIO.StringIO() |
342 input = StringIO.StringIO('y\n') | 342 input = StringIO.StringIO('y\n') |
343 | 343 |
344 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, | 344 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, |
345 None)) | 345 None)) |
346 self.assertEqual(output.getvalue().count('!!'), 2) | 346 self.assertEqual(output.getvalue().count('!!'), 2) |
347 | 347 |
348 def testDoPresubmitChecksPromptsAfterWarnings(self): | 348 def testDoPresubmitChecksPromptsAfterWarnings(self): |
349 join = presubmit.os.path.join | 349 join = presubmit.os.path.join |
350 description_lines = ('Hello there', | 350 description_lines = ('Hello there', |
351 'this is a change', | 351 'this is a change', |
352 'NOSUCHKEY=http://tracker/123') | 352 'NOSUCHKEY=http://tracker/123') |
353 files = [ | 353 files = [ |
354 ['A', join('haspresubmit', 'blat.cc')], | 354 ['A', join('haspresubmit', 'blat.cc')], |
355 ] | 355 ] |
356 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 356 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
357 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') | 357 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') |
358 for i in range(2): | 358 for i in range(2): |
359 presubmit.os.path.isfile(presubmit_path).AndReturn(True) | 359 presubmit.os.path.isfile(presubmit_path).AndReturn(True) |
360 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) | 360 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) |
361 presubmit.gcl.ReadFile(presubmit_path, 'rU' | 361 presubmit.gcl.ReadFile(presubmit_path, 'rU' |
362 ).AndReturn(self.presubmit_text) | 362 ).AndReturn(self.presubmit_text) |
363 presubmit.gcl.ReadFile(haspresubmit_path, 'rU' | 363 presubmit.gcl.ReadFile(haspresubmit_path, 'rU' |
364 ).AndReturn(self.presubmit_text) | 364 ).AndReturn(self.presubmit_text) |
365 self.mox.ReplayAll() | 365 self.mox.ReplayAll() |
366 | 366 |
367 ci = presubmit.gcl.ChangeInfo(name='mychange', | 367 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
368 description='\n'.join(description_lines), | 368 description='\n'.join(description_lines), |
369 files=files) | 369 files=files) |
370 | 370 |
371 output = StringIO.StringIO() | 371 output = StringIO.StringIO() |
372 input = StringIO.StringIO('n\n') # say no to the warning | 372 input = StringIO.StringIO('n\n') # say no to the warning |
373 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, | 373 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, |
374 None)) | 374 None)) |
375 self.assertEqual(output.getvalue().count('??'), 2) | 375 self.assertEqual(output.getvalue().count('??'), 2) |
376 | 376 |
377 output = StringIO.StringIO() | 377 output = StringIO.StringIO() |
(...skipping 18 matching lines...) Expand all Loading... |
396 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 396 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
397 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', | 397 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', |
398 'PRESUBMIT.py') | 398 'PRESUBMIT.py') |
399 presubmit.os.path.isfile(presubmit_path).AndReturn(True) | 399 presubmit.os.path.isfile(presubmit_path).AndReturn(True) |
400 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) | 400 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) |
401 presubmit.gcl.ReadFile(presubmit_path, 'rU').AndReturn(self.presubmit_text) | 401 presubmit.gcl.ReadFile(presubmit_path, 'rU').AndReturn(self.presubmit_text) |
402 presubmit.gcl.ReadFile(haspresubmit_path, 'rU' | 402 presubmit.gcl.ReadFile(haspresubmit_path, 'rU' |
403 ).AndReturn(self.presubmit_text) | 403 ).AndReturn(self.presubmit_text) |
404 self.mox.ReplayAll() | 404 self.mox.ReplayAll() |
405 | 405 |
406 ci = presubmit.gcl.ChangeInfo(name='mychange', | 406 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
407 description='\n'.join(description_lines), | 407 description='\n'.join(description_lines), |
408 files=files) | 408 files=files) |
409 output = StringIO.StringIO() | 409 output = StringIO.StringIO() |
410 input = StringIO.StringIO() # should be unused | 410 input = StringIO.StringIO() # should be unused |
411 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, | 411 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, |
412 None)) | 412 None)) |
413 self.assertEqual(output.getvalue().count('??'), 2) | 413 self.assertEqual(output.getvalue().count('??'), 2) |
414 self.assertEqual(output.getvalue().count('XX!!XX'), 2) | 414 self.assertEqual(output.getvalue().count('XX!!XX'), 2) |
415 self.assertEqual(output.getvalue().count('(y/N)'), 0) | 415 self.assertEqual(output.getvalue().count('(y/N)'), 0) |
416 | 416 |
(...skipping 11 matching lines...) Expand all Loading... |
428 def CheckChangeOnCommit(input_api, output_api): | 428 def CheckChangeOnCommit(input_api, output_api): |
429 raise Exception("Test error") | 429 raise Exception("Test error") |
430 """ | 430 """ |
431 presubmit.os.path.isfile(join(self.fake_root_dir, 'PRESUBMIT.py') | 431 presubmit.os.path.isfile(join(self.fake_root_dir, 'PRESUBMIT.py') |
432 ).AndReturn(False) | 432 ).AndReturn(False) |
433 presubmit.os.path.isfile(join(self.fake_root_dir, | 433 presubmit.os.path.isfile(join(self.fake_root_dir, |
434 'haspresubmit', | 434 'haspresubmit', |
435 'PRESUBMIT.py')).AndReturn(False) | 435 'PRESUBMIT.py')).AndReturn(False) |
436 self.mox.ReplayAll() | 436 self.mox.ReplayAll() |
437 | 437 |
438 ci = presubmit.gcl.ChangeInfo(name='mychange', | 438 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
439 description='\n'.join(description_lines), | 439 description='\n'.join(description_lines), |
440 files=files) | 440 files=files) |
441 | 441 |
442 | 442 |
443 output = StringIO.StringIO() | 443 output = StringIO.StringIO() |
444 input = StringIO.StringIO('y\n') | 444 input = StringIO.StringIO('y\n') |
445 # Always fail. | 445 # Always fail. |
446 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, | 446 self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, |
447 DEFAULT_SCRIPT)) | 447 DEFAULT_SCRIPT)) |
448 self.assertEquals(output.getvalue().count('!!'), 1) | 448 self.assertEquals(output.getvalue().count('!!'), 1) |
449 | 449 |
450 def testDirectoryHandling(self): | 450 def testDirectoryHandling(self): |
451 files = [ | 451 files = [ |
452 ['A', 'isdir'], | 452 ['A', 'isdir'], |
453 ['A', 'isdir\\blat.cc'], | 453 ['A', 'isdir\\blat.cc'], |
454 ] | 454 ] |
455 presubmit.os.path.exists('isdir').AndReturn(True) | 455 presubmit.os.path.exists('isdir').AndReturn(True) |
456 presubmit.os.path.isdir('isdir').AndReturn(True) | 456 presubmit.os.path.isdir('isdir').AndReturn(True) |
457 presubmit.os.path.exists(presubmit.os.path.join('isdir', 'blat.cc') | 457 presubmit.os.path.exists(presubmit.os.path.join('isdir', 'blat.cc') |
458 ).AndReturn(True) | 458 ).AndReturn(True) |
459 presubmit.os.path.isdir(presubmit.os.path.join('isdir', 'blat.cc') | 459 presubmit.os.path.isdir(presubmit.os.path.join('isdir', 'blat.cc') |
460 ).AndReturn(False) | 460 ).AndReturn(False) |
461 self.mox.ReplayAll() | 461 self.mox.ReplayAll() |
462 ci = presubmit.gcl.ChangeInfo(name='mychange', | 462 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
463 description='foo', | 463 description='foo', files=files) |
464 files=files) | |
465 change = presubmit.GclChange(ci) | 464 change = presubmit.GclChange(ci) |
466 | 465 |
467 affected_files = change.AffectedFiles(include_dirs=False) | 466 affected_files = change.AffectedFiles(include_dirs=False) |
468 self.failUnless(len(affected_files) == 1) | 467 self.failUnless(len(affected_files) == 1) |
469 self.failUnless(affected_files[0].LocalPath().endswith('blat.cc')) | 468 self.failUnless(affected_files[0].LocalPath().endswith('blat.cc')) |
470 affected_files_and_dirs = change.AffectedFiles(include_dirs=True) | 469 affected_files_and_dirs = change.AffectedFiles(include_dirs=True) |
471 self.failUnless(len(affected_files_and_dirs) == 2) | 470 self.failUnless(len(affected_files_and_dirs) == 2) |
472 | 471 |
473 def testTags(self): | 472 def testTags(self): |
474 DEFAULT_SCRIPT = """ | 473 DEFAULT_SCRIPT = """ |
(...skipping 12 matching lines...) Expand all Loading... |
487 return [output_api.PresubmitError('Tag parsing failed. 5 ' + | 486 return [output_api.PresubmitError('Tag parsing failed. 5 ' + |
488 input_api.change.FullDescriptionText())] | 487 input_api.change.FullDescriptionText())] |
489 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])] | 488 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])] |
490 def CheckChangeOnCommit(input_api, output_api): | 489 def CheckChangeOnCommit(input_api, output_api): |
491 raise Exception("Test error") | 490 raise Exception("Test error") |
492 """ | 491 """ |
493 self.mox.ReplayAll() | 492 self.mox.ReplayAll() |
494 | 493 |
495 change = presubmit.gcl.ChangeInfo( | 494 change = presubmit.gcl.ChangeInfo( |
496 name='foo', | 495 name='foo', |
497 description="Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n") | 496 issue=0, |
| 497 patchset=0, |
| 498 description="Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n", |
| 499 files=None) |
498 output = StringIO.StringIO() | 500 output = StringIO.StringIO() |
499 input = StringIO.StringIO('y\n') | 501 input = StringIO.StringIO('y\n') |
500 self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output, | 502 self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output, |
501 input, DEFAULT_SCRIPT)) | 503 input, DEFAULT_SCRIPT)) |
502 self.assertEquals(output.getvalue(), | 504 self.assertEquals(output.getvalue(), |
503 ('Warning, no presubmit.py found.\n' | 505 ('Warning, no presubmit.py found.\n' |
504 'Running default presubmit script.\n\n' | 506 'Running default presubmit script.\n\n' |
505 '** Presubmit Messages **\n\n' | 507 '** Presubmit Messages **\n\n' |
506 'http://tracker.com/42\n\n')) | 508 'http://tracker.com/42\n\n')) |
507 | 509 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 presubmit.os.path.exists(flap).AndReturn(True) | 582 presubmit.os.path.exists(flap).AndReturn(True) |
581 presubmit.os.path.isdir(flap).AndReturn(False) | 583 presubmit.os.path.isdir(flap).AndReturn(False) |
582 presubmit.gclient.CaptureSVNInfo(beingdeleted).AndReturn({}) | 584 presubmit.gclient.CaptureSVNInfo(beingdeleted).AndReturn({}) |
583 presubmit.gclient.CaptureSVNInfo(notfound).AndReturn({}) | 585 presubmit.gclient.CaptureSVNInfo(notfound).AndReturn({}) |
584 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) | 586 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) |
585 presubmit.gcl.GetSVNFileProperty(binary, 'svn:mime-type').AndReturn( | 587 presubmit.gcl.GetSVNFileProperty(binary, 'svn:mime-type').AndReturn( |
586 'application/octet-stream') | 588 'application/octet-stream') |
587 presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie') | 589 presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie') |
588 self.mox.ReplayAll() | 590 self.mox.ReplayAll() |
589 | 591 |
590 ci = presubmit.gcl.ChangeInfo(name='mychange', | 592 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
591 description='\n'.join(description_lines), | 593 description='\n'.join(description_lines), |
592 files=files) | 594 files=files) |
593 change = presubmit.GclChange(ci) | 595 change = presubmit.GclChange(ci) |
594 api = presubmit.InputApi(change, 'foo/PRESUBMIT.py') | 596 api = presubmit.InputApi(change, 'foo/PRESUBMIT.py') |
595 affected_files = api.AffectedFiles() | 597 affected_files = api.AffectedFiles() |
596 self.assertEquals(len(affected_files), 3) | 598 self.assertEquals(len(affected_files), 3) |
597 self.assertEquals(affected_files[0].LocalPath(), | 599 self.assertEquals(affected_files[0].LocalPath(), |
598 presubmit.normpath('foo/blat.cc')) | 600 presubmit.normpath('foo/blat.cc')) |
599 self.assertEquals(affected_files[1].LocalPath(), | 601 self.assertEquals(affected_files[1].LocalPath(), |
600 presubmit.normpath('foo/blat/binary.dll')) | 602 presubmit.normpath('foo/blat/binary.dll')) |
(...skipping 14 matching lines...) Expand all Loading... |
615 # from the client root (e.g. if you were at 'src' and did 'cd base' before | 617 # from the client root (e.g. if you were at 'src' and did 'cd base' before |
616 # invoking 'gcl upload' it would fail because svn wouldn't find the files | 618 # invoking 'gcl upload' it would fail because svn wouldn't find the files |
617 # the presubmit script was asking about). | 619 # the presubmit script was asking about). |
618 files = [ | 620 files = [ |
619 ['A', 'isdir'], | 621 ['A', 'isdir'], |
620 ['A', join('isdir', 'blat.cc')], | 622 ['A', join('isdir', 'blat.cc')], |
621 ['M', join('elsewhere', 'ouf.cc')], | 623 ['M', join('elsewhere', 'ouf.cc')], |
622 ] | 624 ] |
623 self.mox.ReplayAll() | 625 self.mox.ReplayAll() |
624 | 626 |
625 ci = presubmit.gcl.ChangeInfo(name='mychange', description='', files=files) | 627 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
| 628 description='', files=files) |
626 # It doesn't make sense on non-Windows platform. This is somewhat hacky, | 629 # It doesn't make sense on non-Windows platform. This is somewhat hacky, |
627 # but it is needed since we can't just use os.path.join('c:', 'temp'). | 630 # but it is needed since we can't just use os.path.join('c:', 'temp'). |
628 change = presubmit.GclChange(ci, self.fake_root_dir) | 631 change = presubmit.GclChange(ci, self.fake_root_dir) |
629 affected_files = change.AffectedFiles(include_dirs=True) | 632 affected_files = change.AffectedFiles(include_dirs=True) |
630 # Local paths should remain the same | 633 # Local paths should remain the same |
631 self.assertEquals(affected_files[0].LocalPath(), normpath('isdir')) | 634 self.assertEquals(affected_files[0].LocalPath(), normpath('isdir')) |
632 self.assertEquals(affected_files[1].LocalPath(), normpath('isdir/blat.cc')) | 635 self.assertEquals(affected_files[1].LocalPath(), normpath('isdir/blat.cc')) |
633 # Absolute paths should be prefixed | 636 # Absolute paths should be prefixed |
634 self.assertEquals(affected_files[0].AbsoluteLocalPath(), | 637 self.assertEquals(affected_files[0].AbsoluteLocalPath(), |
635 normpath(join(self.fake_root_dir, 'isdir'))) | 638 normpath(join(self.fake_root_dir, 'isdir'))) |
(...skipping 11 matching lines...) Expand all Loading... |
647 self.assertEqual(absolute_paths[0], | 650 self.assertEqual(absolute_paths[0], |
648 normpath(join(self.fake_root_dir, 'isdir'))) | 651 normpath(join(self.fake_root_dir, 'isdir'))) |
649 self.assertEqual(absolute_paths[1], | 652 self.assertEqual(absolute_paths[1], |
650 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) | 653 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) |
651 | 654 |
652 def testDeprecated(self): | 655 def testDeprecated(self): |
653 presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), | 656 presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), |
654 stacklevel=2) | 657 stacklevel=2) |
655 self.mox.ReplayAll() | 658 self.mox.ReplayAll() |
656 change = presubmit.GclChange( | 659 change = presubmit.GclChange( |
657 presubmit.gcl.ChangeInfo(name='mychange', description='Bleh\n')) | 660 presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, |
| 661 description='Bleh\n', files=None)) |
658 api = presubmit.InputApi(change, 'foo/PRESUBMIT.py') | 662 api = presubmit.InputApi(change, 'foo/PRESUBMIT.py') |
659 api.AffectedTextFiles(include_deletes=False) | 663 api.AffectedTextFiles(include_deletes=False) |
660 | 664 |
661 | 665 |
662 class OuputApiUnittest(PresubmitTestsBase): | 666 class OuputApiUnittest(PresubmitTestsBase): |
663 """Tests presubmit.OutputApi.""" | 667 """Tests presubmit.OutputApi.""" |
664 def testMembersChanged(self): | 668 def testMembersChanged(self): |
665 self.mox.ReplayAll() | 669 self.mox.ReplayAll() |
666 members = [ | 670 members = [ |
667 'MailTextResult', 'PresubmitError', 'PresubmitNotifyResult', | 671 'MailTextResult', 'PresubmitError', 'PresubmitNotifyResult', |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) | 789 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) |
786 presubmit.gcl.GetSVNFileProperty(blob, 'svn:mime-type' | 790 presubmit.gcl.GetSVNFileProperty(blob, 'svn:mime-type' |
787 ).AndReturn('application/octet-stream') | 791 ).AndReturn('application/octet-stream') |
788 self.mox.ReplayAll() | 792 self.mox.ReplayAll() |
789 | 793 |
790 output = filter(lambda x: x.IsTextFile(), list) | 794 output = filter(lambda x: x.IsTextFile(), list) |
791 self.failUnless(len(output) == 1) | 795 self.failUnless(len(output) == 1) |
792 self.failUnless(list[0] == output[0]) | 796 self.failUnless(list[0] == output[0]) |
793 | 797 |
794 | 798 |
| 799 class GclChangeUnittest(PresubmitTestsBase): |
| 800 def testMembersChanged(self): |
| 801 self.mox.ReplayAll() |
| 802 members = [ |
| 803 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 'Change', |
| 804 'DescriptionText', 'FullDescriptionText', 'LocalPaths', |
| 805 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', |
| 806 'issue', 'patchset', 'tags', |
| 807 ] |
| 808 # If this test fails, you should add the relevant test. |
| 809 ci = presubmit.gcl.ChangeInfo('', 0, 0, '', None) |
| 810 self.compareMembers(presubmit.GclChange(ci, self.fake_root_dir), members) |
| 811 |
| 812 |
795 class CannedChecksUnittest(PresubmitTestsBase): | 813 class CannedChecksUnittest(PresubmitTestsBase): |
796 """Tests presubmit_canned_checks.py.""" | 814 """Tests presubmit_canned_checks.py.""" |
797 | 815 |
798 def setUp(self): | 816 def setUp(self): |
799 PresubmitTestsBase.setUp(self) | 817 PresubmitTestsBase.setUp(self) |
800 self.mox.StubOutWithMock(presubmit_canned_checks, | 818 self.mox.StubOutWithMock(presubmit_canned_checks, |
801 '_RunPythonUnitTests_LoadTests') | 819 '_RunPythonUnitTests_LoadTests') |
802 | 820 |
803 def MockInputApi(self): | 821 def MockInputApi(self): |
804 input_api = self.mox.CreateMock(presubmit.InputApi) | 822 input_api = self.mox.CreateMock(presubmit.InputApi) |
805 input_api.re = presubmit.re | 823 input_api.re = presubmit.re |
806 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) | 824 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) |
807 input_api.unittest = unittest | 825 input_api.unittest = unittest |
808 return input_api | 826 return input_api |
809 | 827 |
810 def MakeBasicChange(self, name, description): | 828 def MakeBasicChange(self, name, description): |
811 ci = presubmit.gcl.ChangeInfo(name=name, description=description) | 829 ci = presubmit.gcl.ChangeInfo(name, 0, 0, description, None) |
812 return presubmit.GclChange(ci, self.fake_root_dir) | 830 return presubmit.GclChange(ci, self.fake_root_dir) |
813 | 831 |
814 def testMembersChanged(self): | 832 def testMembersChanged(self): |
815 self.mox.ReplayAll() | 833 self.mox.ReplayAll() |
816 members = [ | 834 members = [ |
817 'CheckChangeHasBugField', 'CheckChangeHasNoTabs', | 835 'CheckChangeHasBugField', 'CheckChangeHasNoTabs', |
818 'CheckChangeHasQaField', 'CheckChangeHasTestedField', | 836 'CheckChangeHasQaField', 'CheckChangeHasTestedField', |
819 'CheckChangeHasTestField', 'CheckDoNotSubmit', | 837 'CheckChangeHasTestField', 'CheckDoNotSubmit', |
820 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', | 838 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', |
821 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', | 839 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 test_result.errors = 0 | 1012 test_result.errors = 0 |
995 self.mox.ReplayAll() | 1013 self.mox.ReplayAll() |
996 | 1014 |
997 results = presubmit_canned_checks.RunPythonUnitTests( | 1015 results = presubmit_canned_checks.RunPythonUnitTests( |
998 input_api, presubmit.OutputApi, ['test_module']) | 1016 input_api, presubmit.OutputApi, ['test_module']) |
999 self.assertEquals(len(results), 0) | 1017 self.assertEquals(len(results), 0) |
1000 | 1018 |
1001 | 1019 |
1002 if __name__ == '__main__': | 1020 if __name__ == '__main__': |
1003 unittest.main() | 1021 unittest.main() |
OLD | NEW |