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

Side by Side Diff: tests/presubmit_unittest.py

Issue 7253015: Remove manual --tbr support and convert it into automatic TBR= detection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: removed tests/tbr.sh Created 9 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 # pylint is too confused. 8 # pylint is too confused.
9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 9 # pylint: disable=E1101,E1103,R0201,W0212,W0403
10 10
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 self.mox.ReplayAll() 361 self.mox.ReplayAll()
362 362
363 change = presubmit.Change( 363 change = presubmit.Change(
364 'mychange', 364 'mychange',
365 '\n'.join(description_lines), 365 '\n'.join(description_lines),
366 self.fake_root_dir, 366 self.fake_root_dir,
367 files, 367 files,
368 0, 368 0,
369 0, 369 0,
370 None) 370 None)
371 executer = presubmit.PresubmitExecuter(change, False, False, None, False) 371 executer = presubmit.PresubmitExecuter(change, False, None, False)
372 self.failIf(executer.ExecPresubmitScript('', fake_presubmit)) 372 self.failIf(executer.ExecPresubmitScript('', fake_presubmit))
373 # No error if no on-upload entry point 373 # No error if no on-upload entry point
374 self.failIf(executer.ExecPresubmitScript( 374 self.failIf(executer.ExecPresubmitScript(
375 ('def CheckChangeOnCommit(input_api, output_api):\n' 375 ('def CheckChangeOnCommit(input_api, output_api):\n'
376 ' return (output_api.PresubmitError("!!"))\n'), 376 ' return (output_api.PresubmitError("!!"))\n'),
377 fake_presubmit 377 fake_presubmit
378 )) 378 ))
379 379
380 executer = presubmit.PresubmitExecuter(change, True, False, None, False) 380 executer = presubmit.PresubmitExecuter(change, True, None, False)
381 # No error if no on-commit entry point 381 # No error if no on-commit entry point
382 self.failIf(executer.ExecPresubmitScript( 382 self.failIf(executer.ExecPresubmitScript(
383 ('def CheckChangeOnUpload(input_api, output_api):\n' 383 ('def CheckChangeOnUpload(input_api, output_api):\n'
384 ' return (output_api.PresubmitError("!!"))\n'), 384 ' return (output_api.PresubmitError("!!"))\n'),
385 fake_presubmit 385 fake_presubmit
386 )) 386 ))
387 387
388 self.failIf(executer.ExecPresubmitScript( 388 self.failIf(executer.ExecPresubmitScript(
389 ('def CheckChangeOnUpload(input_api, output_api):\n' 389 ('def CheckChangeOnUpload(input_api, output_api):\n'
390 ' if not input_api.change.STORY:\n' 390 ' if not input_api.change.STORY:\n'
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 input_buf = StringIO.StringIO('y\n') 440 input_buf = StringIO.StringIO('y\n')
441 change = presubmit.Change( 441 change = presubmit.Change(
442 'mychange', 442 'mychange',
443 '\n'.join(description_lines), 443 '\n'.join(description_lines),
444 self.fake_root_dir, 444 self.fake_root_dir,
445 files, 445 files,
446 0, 446 0,
447 0, 447 0,
448 None) 448 None)
449 output = presubmit.DoPresubmitChecks( 449 output = presubmit.DoPresubmitChecks(
450 change, False, True, None, input_buf, None, False, False, None) 450 change, False, True, None, input_buf, None, False, None)
451 self.failIf(output.should_continue()) 451 self.failIf(output.should_continue())
452 self.assertEqual(output.getvalue().count('!!'), 2) 452 self.assertEqual(output.getvalue().count('!!'), 2)
453 self.assertEqual(output.getvalue().count( 453 self.assertEqual(output.getvalue().count(
454 'Running presubmit upload checks ...\n'), 1) 454 'Running presubmit upload checks ...\n'), 1)
455 455
456 def testDoPresubmitChecksPromptsAfterWarnings(self): 456 def testDoPresubmitChecksPromptsAfterWarnings(self):
457 join = presubmit.os.path.join 457 join = presubmit.os.path.join
458 description_lines = ('Hello there', 458 description_lines = ('Hello there',
459 'this is a change', 459 'this is a change',
460 'NOSUCHKEY=http://tracker/123') 460 'NOSUCHKEY=http://tracker/123')
(...skipping 19 matching lines...) Expand all
480 input_buf = StringIO.StringIO('n\n') # say no to the warning 480 input_buf = StringIO.StringIO('n\n') # say no to the warning
481 change = presubmit.Change( 481 change = presubmit.Change(
482 'mychange', 482 'mychange',
483 '\n'.join(description_lines), 483 '\n'.join(description_lines),
484 self.fake_root_dir, 484 self.fake_root_dir,
485 files, 485 files,
486 0, 486 0,
487 0, 487 0,
488 None) 488 None)
489 output = presubmit.DoPresubmitChecks( 489 output = presubmit.DoPresubmitChecks(
490 change, False, True, None, input_buf, None, True, False, None) 490 change, False, True, None, input_buf, None, True, None)
491 self.failIf(output.should_continue()) 491 self.failIf(output.should_continue())
492 self.assertEqual(output.getvalue().count('??'), 2) 492 self.assertEqual(output.getvalue().count('??'), 2)
493 493
494 input_buf = StringIO.StringIO('y\n') # say yes to the warning 494 input_buf = StringIO.StringIO('y\n') # say yes to the warning
495 output = presubmit.DoPresubmitChecks( 495 output = presubmit.DoPresubmitChecks(
496 change, False, True, None, input_buf, None, True, False, None) 496 change, False, True, None, input_buf, None, True, None)
497 self.failUnless(output.should_continue()) 497 self.failUnless(output.should_continue())
498 self.assertEquals(output.getvalue().count('??'), 2) 498 self.assertEquals(output.getvalue().count('??'), 2)
499 self.assertEqual(output.getvalue().count( 499 self.assertEqual(output.getvalue().count(
500 'Running presubmit upload checks ...\n'), 1) 500 'Running presubmit upload checks ...\n'), 1)
501 501
502 def testDoPresubmitChecksNoWarningPromptIfErrors(self): 502 def testDoPresubmitChecksNoWarningPromptIfErrors(self):
503 join = presubmit.os.path.join 503 join = presubmit.os.path.join
504 description_lines = ('Hello there', 504 description_lines = ('Hello there',
505 'this is a change', 505 'this is a change',
506 'NOSUCHKEY=http://tracker/123', 506 'NOSUCHKEY=http://tracker/123',
(...skipping 18 matching lines...) Expand all
525 525
526 change = presubmit.Change( 526 change = presubmit.Change(
527 'mychange', 527 'mychange',
528 '\n'.join(description_lines), 528 '\n'.join(description_lines),
529 self.fake_root_dir, 529 self.fake_root_dir,
530 files, 530 files,
531 0, 531 0,
532 0, 532 0,
533 None) 533 None)
534 output = presubmit.DoPresubmitChecks(change, False, True, None, None, 534 output = presubmit.DoPresubmitChecks(change, False, True, None, None,
535 None, False, False, None) 535 None, False, None)
536 self.assertEqual(output.getvalue().count('??'), 2) 536 self.assertEqual(output.getvalue().count('??'), 2)
537 self.assertEqual(output.getvalue().count('XX!!XX'), 2) 537 self.assertEqual(output.getvalue().count('XX!!XX'), 2)
538 self.assertEqual(output.getvalue().count('(y/N)'), 0) 538 self.assertEqual(output.getvalue().count('(y/N)'), 0)
539 self.assertEqual(output.getvalue().count( 539 self.assertEqual(output.getvalue().count(
540 'Running presubmit upload checks ...\n'), 1) 540 'Running presubmit upload checks ...\n'), 1)
541 541
542 def testDoDefaultPresubmitChecksAndFeedback(self): 542 def testDoDefaultPresubmitChecksAndFeedback(self):
543 join = presubmit.os.path.join 543 join = presubmit.os.path.join
544 description_lines = ('Hello there', 544 description_lines = ('Hello there',
545 'this is a change', 545 'this is a change',
(...skipping 22 matching lines...) Expand all
568 # Always fail. 568 # Always fail.
569 change = presubmit.Change( 569 change = presubmit.Change(
570 'mychange', 570 'mychange',
571 '\n'.join(description_lines), 571 '\n'.join(description_lines),
572 self.fake_root_dir, 572 self.fake_root_dir,
573 files, 573 files,
574 0, 574 0,
575 0, 575 0,
576 None) 576 None)
577 output = presubmit.DoPresubmitChecks( 577 output = presubmit.DoPresubmitChecks(
578 change, False, True, None, input_buf, DEFAULT_SCRIPT, False, False, 578 change, False, True, None, input_buf, DEFAULT_SCRIPT, False, None)
579 None)
580 self.failIf(output.should_continue()) 579 self.failIf(output.should_continue())
581 text = ('Running presubmit upload checks ...\n' 580 text = ('Running presubmit upload checks ...\n'
582 'Warning, no presubmit.py found.\n' 581 'Warning, no presubmit.py found.\n'
583 'Running default presubmit script.\n' 582 'Running default presubmit script.\n'
584 '\n' 583 '\n'
585 '** Presubmit ERRORS **\n!!\n\n' 584 '** Presubmit ERRORS **\n!!\n\n'
586 'Was the presubmit check useful? Please send feedback & hate mail ' 585 'Was the presubmit check useful? Please send feedback & hate mail '
587 'to maruel@chromium.org!\n') 586 'to maruel@chromium.org!\n')
588 self.assertEquals(output.getvalue(), text) 587 self.assertEquals(output.getvalue(), text)
589 588
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 input_buf = StringIO.StringIO('y\n') 648 input_buf = StringIO.StringIO('y\n')
650 change = presubmit.Change( 649 change = presubmit.Change(
651 'foo', 650 'foo',
652 'Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n', 651 'Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n',
653 self.fake_root_dir, 652 self.fake_root_dir,
654 None, 653 None,
655 0, 654 0,
656 0, 655 0,
657 None) 656 None)
658 self.failUnless(presubmit.DoPresubmitChecks( 657 self.failUnless(presubmit.DoPresubmitChecks(
659 change, False, True, output, input_buf, DEFAULT_SCRIPT, False, False, 658 change, False, True, output, input_buf, DEFAULT_SCRIPT, False, None))
660 None))
661 self.assertEquals(output.getvalue(), 659 self.assertEquals(output.getvalue(),
662 ('Running presubmit upload checks ...\n' 660 ('Running presubmit upload checks ...\n'
663 'Warning, no presubmit.py found.\n' 661 'Warning, no presubmit.py found.\n'
664 'Running default presubmit script.\n' 662 'Running default presubmit script.\n'
665 '\n' 663 '\n'
666 '** Presubmit Messages **\n' 664 '** Presubmit Messages **\n'
667 'http://tracker.com/42\n' 665 'http://tracker.com/42\n'
668 '\n' 666 '\n'
669 'Presubmit checks passed.\n')) 667 'Presubmit checks passed.\n'))
670 668
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 self.mox.StubOutWithMock(presubmit, 'ParseFiles') 746 self.mox.StubOutWithMock(presubmit, 'ParseFiles')
749 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) 747 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None)
750 presubmit.ParseFiles(['random_file.txt'], None 748 presubmit.ParseFiles(['random_file.txt'], None
751 ).AndReturn(['random_file.txt']) 749 ).AndReturn(['random_file.txt'])
752 output = self.mox.CreateMock(presubmit.PresubmitOutput) 750 output = self.mox.CreateMock(presubmit.PresubmitOutput)
753 output.should_continue().AndReturn(False) 751 output.should_continue().AndReturn(False)
754 752
755 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, 753 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False,
756 mox.IgnoreArg(), 754 mox.IgnoreArg(),
757 mox.IgnoreArg(), 755 mox.IgnoreArg(),
758 None, False, False, None).AndReturn(output) 756 None, False, None).AndReturn(output)
759 self.mox.ReplayAll() 757 self.mox.ReplayAll()
760 758
761 self.assertEquals( 759 self.assertEquals(
762 True, 760 True,
763 presubmit.Main(['--root', self.fake_root_dir, 'random_file.txt'])) 761 presubmit.Main(['--root', self.fake_root_dir, 'random_file.txt']))
764 762
765 def testMainUnversionedFail(self): 763 def testMainUnversionedFail(self):
766 # OptParser calls presubmit.os.path.exists and is a pain when mocked. 764 # OptParser calls presubmit.os.path.exists and is a pain when mocked.
767 self.UnMock(presubmit.os.path, 'exists') 765 self.UnMock(presubmit.os.path, 'exists')
768 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') 766 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks')
(...skipping 28 matching lines...) Expand all
797 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths', 795 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths',
798 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ', 796 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ',
799 'host_url', 'is_committing', 'json', 'logging', 'marshal', 'os_listdir', 797 'host_url', 'is_committing', 'json', 'logging', 'marshal', 'os_listdir',
800 'os_walk', 798 'os_walk',
801 'os_path', 'owners_db', 'pickle', 'platform', 'python_executable', 're', 799 'os_path', 'owners_db', 'pickle', 'platform', 'python_executable', 're',
802 'rietveld', 'subprocess', 'tbr', 'tempfile', 'time', 'traceback', 800 'rietveld', 'subprocess', 'tbr', 'tempfile', 'time', 'traceback',
803 'unittest', 'urllib2', 'version', 'verbose', 801 'unittest', 'urllib2', 'version', 'verbose',
804 ] 802 ]
805 # If this test fails, you should add the relevant test. 803 # If this test fails, you should add the relevant test.
806 self.compareMembers( 804 self.compareMembers(
807 presubmit.InputApi(self.fake_change, './.', False, False, None, False), 805 presubmit.InputApi(self.fake_change, './.', False, None, False),
808 members) 806 members)
809 807
810 def testDepotToLocalPath(self): 808 def testDepotToLocalPath(self):
811 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn( 809 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn(
812 {'Path': 'prout'}) 810 {'Path': 'prout'})
813 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({}) 811 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({})
814 self.mox.ReplayAll() 812 self.mox.ReplayAll()
815 813
816 path = presubmit.InputApi( 814 path = presubmit.InputApi(
817 self.fake_change, './p', False, False, None, False).DepotToLocalPath( 815 self.fake_change, './p', False, None, False).DepotToLocalPath(
818 'svn://foo/smurf') 816 'svn://foo/smurf')
819 self.failUnless(path == 'prout') 817 self.failUnless(path == 'prout')
820 path = presubmit.InputApi( 818 path = presubmit.InputApi(
821 self.fake_change, './p', False, False, None, False).DepotToLocalPath( 819 self.fake_change, './p', False, None, False).DepotToLocalPath(
822 'svn:/foo/notfound/burp') 820 'svn:/foo/notfound/burp')
823 self.failUnless(path == None) 821 self.failUnless(path == None)
824 822
825 def testLocalToDepotPath(self): 823 def testLocalToDepotPath(self):
826 presubmit.scm.SVN.CaptureInfo('smurf').AndReturn({'URL': 'svn://foo'}) 824 presubmit.scm.SVN.CaptureInfo('smurf').AndReturn({'URL': 'svn://foo'})
827 presubmit.scm.SVN.CaptureInfo('notfound-food').AndReturn({}) 825 presubmit.scm.SVN.CaptureInfo('notfound-food').AndReturn({})
828 self.mox.ReplayAll() 826 self.mox.ReplayAll()
829 path = presubmit.InputApi( 827 path = presubmit.InputApi(
830 self.fake_change, './p', False, False, None, False).LocalToDepotPath( 828 self.fake_change, './p', False, None, False).LocalToDepotPath(
831 'smurf') 829 'smurf')
832 self.assertEqual(path, 'svn://foo') 830 self.assertEqual(path, 'svn://foo')
833 path = presubmit.InputApi( 831 path = presubmit.InputApi(
834 self.fake_change, './p', False, False, None, False).LocalToDepotPath( 832 self.fake_change, './p', False, None, False).LocalToDepotPath(
835 'notfound-food') 833 'notfound-food')
836 self.assertEquals(path, None) 834 self.assertEquals(path, None)
837 835
838 def testInputApiConstruction(self): 836 def testInputApiConstruction(self):
839 self.mox.ReplayAll() 837 self.mox.ReplayAll()
840 api = presubmit.InputApi( 838 api = presubmit.InputApi(
841 self.fake_change, 839 self.fake_change,
842 presubmit_path='foo/path/PRESUBMIT.py', 840 presubmit_path='foo/path/PRESUBMIT.py',
843 is_committing=False, tbr=False, rietveld_obj=None, verbose=False) 841 is_committing=False, rietveld_obj=None, verbose=False)
844 self.assertEquals(api.PresubmitLocalPath(), 'foo/path') 842 self.assertEquals(api.PresubmitLocalPath(), 'foo/path')
845 self.assertEquals(api.change, self.fake_change) 843 self.assertEquals(api.change, self.fake_change)
846 self.assertEquals(api.host_url, 'http://codereview.chromium.org') 844 self.assertEquals(api.host_url, 'http://codereview.chromium.org')
847 845
848 def testInputApiPresubmitScriptFiltering(self): 846 def testInputApiPresubmitScriptFiltering(self):
849 join = presubmit.os.path.join 847 join = presubmit.os.path.join
850 description_lines = ('Hello there', 848 description_lines = ('Hello there',
851 'this is a change', 849 'this is a change',
852 'BUG=123', 850 'BUG=123',
853 ' STORY =http://foo/ \t', 851 ' STORY =http://foo/ \t',
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 'mychange', 896 'mychange',
899 '\n'.join(description_lines), 897 '\n'.join(description_lines),
900 self.fake_root_dir, 898 self.fake_root_dir,
901 files, 899 files,
902 0, 900 0,
903 0, 901 0,
904 None) 902 None)
905 input_api = presubmit.InputApi( 903 input_api = presubmit.InputApi(
906 change, 904 change,
907 join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), 905 join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'),
908 False, False, None, False) 906 False, None, False)
909 # Doesn't filter much 907 # Doesn't filter much
910 got_files = input_api.AffectedFiles() 908 got_files = input_api.AffectedFiles()
911 self.assertEquals(len(got_files), 7) 909 self.assertEquals(len(got_files), 7)
912 self.assertEquals(got_files[0].LocalPath(), presubmit.normpath(files[0][1])) 910 self.assertEquals(got_files[0].LocalPath(), presubmit.normpath(files[0][1]))
913 self.assertEquals(got_files[1].LocalPath(), presubmit.normpath(files[1][1])) 911 self.assertEquals(got_files[1].LocalPath(), presubmit.normpath(files[1][1]))
914 self.assertEquals(got_files[2].LocalPath(), presubmit.normpath(files[2][1])) 912 self.assertEquals(got_files[2].LocalPath(), presubmit.normpath(files[2][1]))
915 self.assertEquals(got_files[3].LocalPath(), presubmit.normpath(files[3][1])) 913 self.assertEquals(got_files[3].LocalPath(), presubmit.normpath(files[3][1]))
916 self.assertEquals(got_files[4].LocalPath(), presubmit.normpath(files[4][1])) 914 self.assertEquals(got_files[4].LocalPath(), presubmit.normpath(files[4][1]))
917 self.assertEquals(got_files[5].LocalPath(), presubmit.normpath(files[5][1])) 915 self.assertEquals(got_files[5].LocalPath(), presubmit.normpath(files[5][1]))
918 self.assertEquals(got_files[6].LocalPath(), presubmit.normpath(files[6][1])) 916 self.assertEquals(got_files[6].LocalPath(), presubmit.normpath(files[6][1]))
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 f('b.c/.git'), 982 f('b.c/.git'),
985 f('a/.git/bleh.py'), 983 f('a/.git/bleh.py'),
986 f('.git/bleh.py'), 984 f('.git/bleh.py'),
987 ], 985 ],
988 [ 986 [
989 # Expected. 987 # Expected.
990 ], 988 ],
991 ), 989 ),
992 ] 990 ]
993 input_api = presubmit.InputApi( 991 input_api = presubmit.InputApi(
994 self.fake_change, './PRESUBMIT.py', False, 992 self.fake_change, './PRESUBMIT.py', False, None, False)
995 False, None, False)
996 self.mox.ReplayAll() 993 self.mox.ReplayAll()
997 994
998 self.assertEqual(len(input_api.DEFAULT_WHITE_LIST), 21) 995 self.assertEqual(len(input_api.DEFAULT_WHITE_LIST), 21)
999 self.assertEqual(len(input_api.DEFAULT_BLACK_LIST), 9) 996 self.assertEqual(len(input_api.DEFAULT_BLACK_LIST), 9)
1000 for item in files: 997 for item in files:
1001 results = filter(input_api.FilterSourceFile, item[0]) 998 results = filter(input_api.FilterSourceFile, item[0])
1002 for i in range(len(results)): 999 for i in range(len(results)):
1003 self.assertEquals(results[i].LocalPath(), 1000 self.assertEquals(results[i].LocalPath(),
1004 presubmit.normpath(item[1][i])) 1001 presubmit.normpath(item[1][i]))
1005 # Same number of expected results. 1002 # Same number of expected results.
(...skipping 10 matching lines...) Expand all
1016 presubmit.os.path.exists(item).AndReturn(True) 1013 presubmit.os.path.exists(item).AndReturn(True)
1017 presubmit.os.path.isdir(item).AndReturn(False) 1014 presubmit.os.path.isdir(item).AndReturn(False)
1018 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) 1015 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None)
1019 self.mox.ReplayAll() 1016 self.mox.ReplayAll()
1020 1017
1021 change = presubmit.SvnChange( 1018 change = presubmit.SvnChange(
1022 'mychange', '', self.fake_root_dir, files, 0, 0, None) 1019 'mychange', '', self.fake_root_dir, files, 0, 0, None)
1023 input_api = presubmit.InputApi( 1020 input_api = presubmit.InputApi(
1024 change, 1021 change,
1025 presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py'), 1022 presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py'),
1026 False, False, None, False) 1023 False, None, False)
1027 got_files = input_api.AffectedSourceFiles(FilterSourceFile) 1024 got_files = input_api.AffectedSourceFiles(FilterSourceFile)
1028 self.assertEquals(len(got_files), 2) 1025 self.assertEquals(len(got_files), 2)
1029 self.assertEquals(got_files[0].LocalPath(), 'eeaee') 1026 self.assertEquals(got_files[0].LocalPath(), 'eeaee')
1030 self.assertEquals(got_files[1].LocalPath(), 'eeabee') 1027 self.assertEquals(got_files[1].LocalPath(), 'eeabee')
1031 1028
1032 def testLambdaFilter(self): 1029 def testLambdaFilter(self):
1033 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",) 1030 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",)
1034 black_list = [r".*?b.*?"] 1031 black_list = [r".*?b.*?"]
1035 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')] 1032 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')]
1036 for _, item in files: 1033 for _, item in files:
1037 item = presubmit.os.path.join(self.fake_root_dir, item) 1034 item = presubmit.os.path.join(self.fake_root_dir, item)
1038 presubmit.os.path.exists(item).AndReturn(True) 1035 presubmit.os.path.exists(item).AndReturn(True)
1039 presubmit.os.path.isdir(item).AndReturn(False) 1036 presubmit.os.path.isdir(item).AndReturn(False)
1040 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) 1037 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None)
1041 self.mox.ReplayAll() 1038 self.mox.ReplayAll()
1042 1039
1043 change = presubmit.SvnChange( 1040 change = presubmit.SvnChange(
1044 'mychange', '', self.fake_root_dir, files, 0, 0, None) 1041 'mychange', '', self.fake_root_dir, files, 0, 0, None)
1045 input_api = presubmit.InputApi( 1042 input_api = presubmit.InputApi(
1046 change, './PRESUBMIT.py', False, False, None, False) 1043 change, './PRESUBMIT.py', False, None, False)
1047 # Sample usage of overiding the default white and black lists. 1044 # Sample usage of overiding the default white and black lists.
1048 got_files = input_api.AffectedSourceFiles( 1045 got_files = input_api.AffectedSourceFiles(
1049 lambda x: input_api.FilterSourceFile(x, white_list, black_list)) 1046 lambda x: input_api.FilterSourceFile(x, white_list, black_list))
1050 self.assertEquals(len(got_files), 2) 1047 self.assertEquals(len(got_files), 2)
1051 self.assertEquals(got_files[0].LocalPath(), 'eeaee') 1048 self.assertEquals(got_files[0].LocalPath(), 'eeaee')
1052 self.assertEquals(got_files[1].LocalPath(), 'eecaee') 1049 self.assertEquals(got_files[1].LocalPath(), 'eecaee')
1053 1050
1054 def testGetAbsoluteLocalPath(self): 1051 def testGetAbsoluteLocalPath(self):
1055 join = presubmit.os.path.join 1052 join = presubmit.os.path.join
1056 normpath = presubmit.normpath 1053 normpath = presubmit.normpath
(...skipping 20 matching lines...) Expand all
1077 normpath(join(self.fake_root_dir, 'isdir'))) 1074 normpath(join(self.fake_root_dir, 'isdir')))
1078 self.assertEquals(affected_files[1].AbsoluteLocalPath(), 1075 self.assertEquals(affected_files[1].AbsoluteLocalPath(),
1079 normpath(join(self.fake_root_dir, 'isdir/blat.cc'))) 1076 normpath(join(self.fake_root_dir, 'isdir/blat.cc')))
1080 1077
1081 # New helper functions need to work 1078 # New helper functions need to work
1082 paths_from_change = change.AbsoluteLocalPaths(include_dirs=True) 1079 paths_from_change = change.AbsoluteLocalPaths(include_dirs=True)
1083 self.assertEqual(len(paths_from_change), 3) 1080 self.assertEqual(len(paths_from_change), 3)
1084 presubmit_path = join(self.fake_root_dir, 'isdir', 'PRESUBMIT.py') 1081 presubmit_path = join(self.fake_root_dir, 'isdir', 'PRESUBMIT.py')
1085 api = presubmit.InputApi( 1082 api = presubmit.InputApi(
1086 change=change, presubmit_path=presubmit_path, 1083 change=change, presubmit_path=presubmit_path,
1087 is_committing=True, tbr=False, rietveld_obj=None, verbose=False) 1084 is_committing=True, rietveld_obj=None, verbose=False)
1088 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True) 1085 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True)
1089 self.assertEqual(len(paths_from_api), 2) 1086 self.assertEqual(len(paths_from_api), 2)
1090 for absolute_paths in [paths_from_change, paths_from_api]: 1087 for absolute_paths in [paths_from_change, paths_from_api]:
1091 self.assertEqual(absolute_paths[0], 1088 self.assertEqual(absolute_paths[0],
1092 normpath(join(self.fake_root_dir, 'isdir'))) 1089 normpath(join(self.fake_root_dir, 'isdir')))
1093 self.assertEqual(absolute_paths[1], 1090 self.assertEqual(absolute_paths[1],
1094 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) 1091 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc')))
1095 1092
1096 def testDeprecated(self): 1093 def testDeprecated(self):
1097 presubmit.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), stacklevel=2) 1094 presubmit.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), stacklevel=2)
1098 self.mox.ReplayAll() 1095 self.mox.ReplayAll()
1099 1096
1100 change = presubmit.Change( 1097 change = presubmit.Change(
1101 'mychange', '', self.fake_root_dir, [], 0, 0, None) 1098 'mychange', '', self.fake_root_dir, [], 0, 0, None)
1102 api = presubmit.InputApi( 1099 api = presubmit.InputApi(
1103 change, 1100 change,
1104 presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True, 1101 presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True,
1105 False, None, False) 1102 None, False)
1106 api.AffectedTextFiles(include_deletes=False) 1103 api.AffectedTextFiles(include_deletes=False)
1107 1104
1108 def testReadFileStringDenied(self): 1105 def testReadFileStringDenied(self):
1109 self.mox.ReplayAll() 1106 self.mox.ReplayAll()
1110 1107
1111 change = presubmit.Change( 1108 change = presubmit.Change(
1112 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) 1109 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None)
1113 input_api = presubmit.InputApi( 1110 input_api = presubmit.InputApi(
1114 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, 1111 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False,
1115 False, None, False) 1112 None, False)
1116 self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x') 1113 self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x')
1117 1114
1118 def testReadFileStringAccepted(self): 1115 def testReadFileStringAccepted(self):
1119 path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo') 1116 path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo')
1120 presubmit.gclient_utils.FileRead(path, 'x').AndReturn(None) 1117 presubmit.gclient_utils.FileRead(path, 'x').AndReturn(None)
1121 self.mox.ReplayAll() 1118 self.mox.ReplayAll()
1122 1119
1123 change = presubmit.Change( 1120 change = presubmit.Change(
1124 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) 1121 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None)
1125 input_api = presubmit.InputApi( 1122 input_api = presubmit.InputApi(
1126 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, 1123 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False,
1127 False, None, False) 1124 None, False)
1128 input_api.ReadFile(path, 'x') 1125 input_api.ReadFile(path, 'x')
1129 1126
1130 def testReadFileAffectedFileDenied(self): 1127 def testReadFileAffectedFileDenied(self):
1131 fileobj = presubmit.AffectedFile('boo', 'M', 'Unrelated') 1128 fileobj = presubmit.AffectedFile('boo', 'M', 'Unrelated')
1132 self.mox.ReplayAll() 1129 self.mox.ReplayAll()
1133 1130
1134 change = presubmit.Change( 1131 change = presubmit.Change(
1135 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) 1132 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None)
1136 input_api = presubmit.InputApi( 1133 input_api = presubmit.InputApi(
1137 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, 1134 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False,
1138 False, None, False) 1135 None, False)
1139 self.assertRaises(IOError, input_api.ReadFile, fileobj, 'x') 1136 self.assertRaises(IOError, input_api.ReadFile, fileobj, 'x')
1140 1137
1141 def testReadFileAffectedFileAccepted(self): 1138 def testReadFileAffectedFileAccepted(self):
1142 fileobj = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir) 1139 fileobj = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir)
1143 presubmit.gclient_utils.FileRead(fileobj.AbsoluteLocalPath(), 'x' 1140 presubmit.gclient_utils.FileRead(fileobj.AbsoluteLocalPath(), 'x'
1144 ).AndReturn(None) 1141 ).AndReturn(None)
1145 self.mox.ReplayAll() 1142 self.mox.ReplayAll()
1146 1143
1147 change = presubmit.Change( 1144 change = presubmit.Change(
1148 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) 1145 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None)
1149 input_api = presubmit.InputApi( 1146 input_api = presubmit.InputApi(
1150 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, 1147 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False,
1151 False, None, False) 1148 None, False)
1152 input_api.ReadFile(fileobj, 'x') 1149 input_api.ReadFile(fileobj, 'x')
1153 1150
1154 1151
1155 class OuputApiUnittest(PresubmitTestsBase): 1152 class OuputApiUnittest(PresubmitTestsBase):
1156 """Tests presubmit.OutputApi.""" 1153 """Tests presubmit.OutputApi."""
1157 def testMembersChanged(self): 1154 def testMembersChanged(self):
1158 self.mox.ReplayAll() 1155 self.mox.ReplayAll()
1159 members = [ 1156 members = [
1160 'MailTextResult', 'PresubmitAddReviewers', 'PresubmitError', 1157 'MailTextResult', 'PresubmitAddReviewers', 'PresubmitError',
1161 'PresubmitNotifyResult', 'PresubmitPromptWarning', 'PresubmitResult', 1158 'PresubmitNotifyResult', 'PresubmitPromptWarning', 'PresubmitResult',
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 'CheckBuildbotPendingBuilds', 1369 'CheckBuildbotPendingBuilds',
1373 'CheckChangeHasBugField', 'CheckChangeHasDescription', 1370 'CheckChangeHasBugField', 'CheckChangeHasDescription',
1374 'CheckChangeHasNoStrayWhitespace', 1371 'CheckChangeHasNoStrayWhitespace',
1375 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR', 1372 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR',
1376 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs', 1373 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs',
1377 'CheckChangeTodoHasOwner', 1374 'CheckChangeTodoHasOwner',
1378 'CheckChangeHasQaField', 'CheckChangeHasTestedField', 1375 'CheckChangeHasQaField', 'CheckChangeHasTestedField',
1379 'CheckChangeHasTestField', 1376 'CheckChangeHasTestField',
1380 'CheckChangeLintsClean', 1377 'CheckChangeLintsClean',
1381 'CheckChangeSvnEolStyle', 1378 'CheckChangeSvnEolStyle',
1379 'CheckChangeWasUploaded',
1382 'CheckDoNotSubmit', 1380 'CheckDoNotSubmit',
1383 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', 1381 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles',
1384 'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks', 1382 'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks',
1385 'CheckLicense', 1383 'CheckLicense',
1386 'CheckOwners', 1384 'CheckOwners',
1387 'CheckRietveldTryJobExecution', 1385 'CheckRietveldTryJobExecution',
1388 'CheckSvnModifiedDirectories', 1386 'CheckSvnModifiedDirectories',
1389 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', 1387 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty',
1390 'RunPythonUnitTests', 'RunPylint', 1388 'RunPythonUnitTests', 'RunPylint',
1391 'RunUnitTests', 'RunUnitTestsInDirectory', 1389 'RunUnitTests', 'RunUnitTestsInDirectory',
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 owners_check=True) 2225 owners_check=True)
2228 self.assertEqual(1, len(results)) 2226 self.assertEqual(1, len(results))
2229 self.assertEqual( 2227 self.assertEqual(
2230 'Found line ending with white spaces in:', results[0]._message) 2228 'Found line ending with white spaces in:', results[0]._message)
2231 self.checkstdout('') 2229 self.checkstdout('')
2232 2230
2233 2231
2234 if __name__ == '__main__': 2232 if __name__ == '__main__':
2235 import unittest 2233 import unittest
2236 unittest.main() 2234 unittest.main()
OLDNEW
« presubmit_canned_checks.py ('K') | « tests/post-dcommit-hook-test.sh ('k') | tests/tbr.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698