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

Side by Side Diff: tests/presubmit_unittest.py

Issue 6646009: update git-cl for OWNERS file support via .git/hooks/pre-cl-* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: clean up after running owners-related git-cl tests Created 9 years, 9 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
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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,W0212,W0403 9 # pylint: disable=E1101,E1103,W0212,W0403
10 10
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 'this is a change', 335 'this is a change',
336 'STORY=http://tracker/123') 336 'STORY=http://tracker/123')
337 files = [ 337 files = [
338 ['A', 'foo\\blat.cc'], 338 ['A', 'foo\\blat.cc'],
339 ] 339 ]
340 fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') 340 fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
341 self.mox.ReplayAll() 341 self.mox.ReplayAll()
342 342
343 change = presubmit.Change('mychange', '\n'.join(description_lines), 343 change = presubmit.Change('mychange', '\n'.join(description_lines),
344 self.fake_root_dir, files, 0, 0) 344 self.fake_root_dir, files, 0, 0)
345 executer = presubmit.PresubmitExecuter(change, False) 345 executer = presubmit.PresubmitExecuter(change, False, False, None)
346 self.failIf(executer.ExecPresubmitScript('', fake_presubmit)) 346 self.failIf(executer.ExecPresubmitScript('', fake_presubmit))
347 # No error if no on-upload entry point 347 # No error if no on-upload entry point
348 self.failIf(executer.ExecPresubmitScript( 348 self.failIf(executer.ExecPresubmitScript(
349 ('def CheckChangeOnCommit(input_api, output_api):\n' 349 ('def CheckChangeOnCommit(input_api, output_api):\n'
350 ' return (output_api.PresubmitError("!!"))\n'), 350 ' return (output_api.PresubmitError("!!"))\n'),
351 fake_presubmit 351 fake_presubmit
352 )) 352 ))
353 353
354 executer = presubmit.PresubmitExecuter(change, True) 354 executer = presubmit.PresubmitExecuter(change, True, False, None)
355 # No error if no on-commit entry point 355 # No error if no on-commit entry point
356 self.failIf(executer.ExecPresubmitScript( 356 self.failIf(executer.ExecPresubmitScript(
357 ('def CheckChangeOnUpload(input_api, output_api):\n' 357 ('def CheckChangeOnUpload(input_api, output_api):\n'
358 ' return (output_api.PresubmitError("!!"))\n'), 358 ' return (output_api.PresubmitError("!!"))\n'),
359 fake_presubmit 359 fake_presubmit
360 )) 360 ))
361 361
362 self.failIf(executer.ExecPresubmitScript( 362 self.failIf(executer.ExecPresubmitScript(
363 ('def CheckChangeOnUpload(input_api, output_api):\n' 363 ('def CheckChangeOnUpload(input_api, output_api):\n'
364 ' if not input_api.change.STORY:\n' 364 ' if not input_api.change.STORY:\n'
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 def testMembersChanged(self): 693 def testMembersChanged(self):
694 self.mox.ReplayAll() 694 self.mox.ReplayAll()
695 members = [ 695 members = [
696 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', 696 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles',
697 'AffectedTextFiles', 697 'AffectedTextFiles',
698 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', 698 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST',
699 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', 699 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths',
700 'LocalToDepotPath', 700 'LocalToDepotPath',
701 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths', 701 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths',
702 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ', 702 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ',
703 'host_url', 'is_committing', 'is_tbr', 'json', 'marshal', 'os_path', 703 'host_url', 'is_committing', 'json', 'marshal', 'os_path',
704 'owners_db', 'pickle', 'platform', 'python_executable', 're', 704 'owners_db', 'pickle', 'platform', 'python_executable', 're',
705 'subprocess', 'tempfile', 'traceback', 'unittest', 'urllib2', 'version', 705 'subprocess', 'tbr', 'tempfile', 'traceback', 'unittest', 'urllib2',
706 'version',
706 ] 707 ]
707 # If this test fails, you should add the relevant test. 708 # If this test fails, you should add the relevant test.
708 self.compareMembers(presubmit.InputApi(self.fake_change, './.', False), 709 self.compareMembers(presubmit.InputApi(self.fake_change, './.', False,
710 False, None),
709 members) 711 members)
710 712
711 def testDepotToLocalPath(self): 713 def testDepotToLocalPath(self):
712 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn( 714 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn(
713 {'Path': 'prout'}) 715 {'Path': 'prout'})
714 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({}) 716 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({})
715 self.mox.ReplayAll() 717 self.mox.ReplayAll()
716 718
717 path = presubmit.InputApi(self.fake_change, './p', False).DepotToLocalPath( 719 path = presubmit.InputApi(self.fake_change, './p', False, False,
718 'svn://foo/smurf') 720 None).DepotToLocalPath('svn://foo/smurf')
719 self.failUnless(path == 'prout') 721 self.failUnless(path == 'prout')
720 path = presubmit.InputApi(self.fake_change, './p', False).DepotToLocalPath( 722 path = presubmit.InputApi(self.fake_change, './p', False, False,
721 'svn:/foo/notfound/burp') 723 None).DepotToLocalPath('svn:/foo/notfound/burp')
722 self.failUnless(path == None) 724 self.failUnless(path == None)
723 725
724 def testLocalToDepotPath(self): 726 def testLocalToDepotPath(self):
725 presubmit.scm.SVN.CaptureInfo('smurf').AndReturn({'URL': 'svn://foo'}) 727 presubmit.scm.SVN.CaptureInfo('smurf').AndReturn({'URL': 'svn://foo'})
726 presubmit.scm.SVN.CaptureInfo('notfound-food').AndReturn({}) 728 presubmit.scm.SVN.CaptureInfo('notfound-food').AndReturn({})
727 self.mox.ReplayAll() 729 self.mox.ReplayAll()
728 path = presubmit.InputApi(self.fake_change, './p', False).LocalToDepotPath( 730 path = presubmit.InputApi(self.fake_change, './p', False, False,
729 'smurf') 731 None).LocalToDepotPath('smurf')
730 self.assertEqual(path, 'svn://foo') 732 self.assertEqual(path, 'svn://foo')
731 path = presubmit.InputApi(self.fake_change, './p', False).LocalToDepotPath( 733 path = presubmit.InputApi(self.fake_change, './p', False, False,
732 'notfound-food') 734 None).LocalToDepotPath('notfound-food')
733 self.failUnless(path == None) 735 self.failUnless(path == None)
734 736
735 def testInputApiConstruction(self): 737 def testInputApiConstruction(self):
736 self.mox.ReplayAll() 738 self.mox.ReplayAll()
737 api = presubmit.InputApi(self.fake_change, 739 api = presubmit.InputApi(self.fake_change,
738 presubmit_path='foo/path/PRESUBMIT.py', 740 presubmit_path='foo/path/PRESUBMIT.py',
739 is_committing=False) 741 is_committing=False, tbr=False, host_url=None)
740 self.assertEquals(api.PresubmitLocalPath(), 'foo/path') 742 self.assertEquals(api.PresubmitLocalPath(), 'foo/path')
741 self.assertEquals(api.change, self.fake_change) 743 self.assertEquals(api.change, self.fake_change)
744 self.assertEquals(api.host_url, 'http://codereview.chromium.org')
742 745
743 def testInputApiPresubmitScriptFiltering(self): 746 def testInputApiPresubmitScriptFiltering(self):
744 join = presubmit.os.path.join 747 join = presubmit.os.path.join
745 description_lines = ('Hello there', 748 description_lines = ('Hello there',
746 'this is a change', 749 'this is a change',
747 'BUG=123', 750 'BUG=123',
748 ' STORY =http://foo/ \t', 751 ' STORY =http://foo/ \t',
749 'and some more regular text') 752 'and some more regular text')
750 files = [ 753 files = [
751 ['A', join('foo', 'blat.cc')], 754 ['A', join('foo', 'blat.cc')],
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 presubmit.scm.SVN.GenerateDiff([blat]).AndReturn(self.presubmit_diffs) 790 presubmit.scm.SVN.GenerateDiff([blat]).AndReturn(self.presubmit_diffs)
788 presubmit.scm.SVN.GenerateDiff([another]).AndReturn(self.presubmit_diffs) 791 presubmit.scm.SVN.GenerateDiff([another]).AndReturn(self.presubmit_diffs)
789 792
790 self.mox.ReplayAll() 793 self.mox.ReplayAll()
791 794
792 change = presubmit.SvnChange('mychange', '\n'.join(description_lines), 795 change = presubmit.SvnChange('mychange', '\n'.join(description_lines),
793 self.fake_root_dir, files, 0, 0) 796 self.fake_root_dir, files, 0, 0)
794 input_api = presubmit.InputApi(change, 797 input_api = presubmit.InputApi(change,
795 join(self.fake_root_dir, 'foo', 798 join(self.fake_root_dir, 'foo',
796 'PRESUBMIT.py'), 799 'PRESUBMIT.py'),
797 False) 800 False, False, None)
798 # Doesn't filter much 801 # Doesn't filter much
799 got_files = input_api.AffectedFiles() 802 got_files = input_api.AffectedFiles()
800 self.assertEquals(len(got_files), 7) 803 self.assertEquals(len(got_files), 7)
801 self.assertEquals(got_files[0].LocalPath(), presubmit.normpath(files[0][1])) 804 self.assertEquals(got_files[0].LocalPath(), presubmit.normpath(files[0][1]))
802 self.assertEquals(got_files[1].LocalPath(), presubmit.normpath(files[1][1])) 805 self.assertEquals(got_files[1].LocalPath(), presubmit.normpath(files[1][1]))
803 self.assertEquals(got_files[2].LocalPath(), presubmit.normpath(files[2][1])) 806 self.assertEquals(got_files[2].LocalPath(), presubmit.normpath(files[2][1]))
804 self.assertEquals(got_files[3].LocalPath(), presubmit.normpath(files[3][1])) 807 self.assertEquals(got_files[3].LocalPath(), presubmit.normpath(files[3][1]))
805 self.assertEquals(got_files[4].LocalPath(), presubmit.normpath(files[4][1])) 808 self.assertEquals(got_files[4].LocalPath(), presubmit.normpath(files[4][1]))
806 self.assertEquals(got_files[5].LocalPath(), presubmit.normpath(files[5][1])) 809 self.assertEquals(got_files[5].LocalPath(), presubmit.normpath(files[5][1]))
807 self.assertEquals(got_files[6].LocalPath(), presubmit.normpath(files[6][1])) 810 self.assertEquals(got_files[6].LocalPath(), presubmit.normpath(files[6][1]))
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 f('a/.git'), 875 f('a/.git'),
873 f('b.c/.git'), 876 f('b.c/.git'),
874 f('a/.git/bleh.py'), 877 f('a/.git/bleh.py'),
875 f('.git/bleh.py'), 878 f('.git/bleh.py'),
876 ], 879 ],
877 [ 880 [
878 # Expected. 881 # Expected.
879 ], 882 ],
880 ), 883 ),
881 ] 884 ]
882 input_api = presubmit.InputApi(self.fake_change, './PRESUBMIT.py', False) 885 input_api = presubmit.InputApi(self.fake_change, './PRESUBMIT.py', False,
886 False, None)
883 self.mox.ReplayAll() 887 self.mox.ReplayAll()
884 888
885 self.assertEqual(len(input_api.DEFAULT_WHITE_LIST), 22) 889 self.assertEqual(len(input_api.DEFAULT_WHITE_LIST), 22)
886 self.assertEqual(len(input_api.DEFAULT_BLACK_LIST), 9) 890 self.assertEqual(len(input_api.DEFAULT_BLACK_LIST), 9)
887 for item in files: 891 for item in files:
888 results = filter(input_api.FilterSourceFile, item[0]) 892 results = filter(input_api.FilterSourceFile, item[0])
889 for i in range(len(results)): 893 for i in range(len(results)):
890 self.assertEquals(results[i].LocalPath(), 894 self.assertEquals(results[i].LocalPath(),
891 presubmit.normpath(item[1][i])) 895 presubmit.normpath(item[1][i]))
892 # Same number of expected results. 896 # Same number of expected results.
(...skipping 10 matching lines...) Expand all
903 presubmit.os.path.exists(item).AndReturn(True) 907 presubmit.os.path.exists(item).AndReturn(True)
904 presubmit.os.path.isdir(item).AndReturn(False) 908 presubmit.os.path.isdir(item).AndReturn(False)
905 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) 909 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None)
906 self.mox.ReplayAll() 910 self.mox.ReplayAll()
907 911
908 change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0, 912 change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0,
909 0) 913 0)
910 input_api = presubmit.InputApi(change, 914 input_api = presubmit.InputApi(change,
911 presubmit.os.path.join(self.fake_root_dir, 915 presubmit.os.path.join(self.fake_root_dir,
912 'PRESUBMIT.py'), 916 'PRESUBMIT.py'),
913 False) 917 False, False, None)
914 got_files = input_api.AffectedSourceFiles(FilterSourceFile) 918 got_files = input_api.AffectedSourceFiles(FilterSourceFile)
915 self.assertEquals(len(got_files), 2) 919 self.assertEquals(len(got_files), 2)
916 self.assertEquals(got_files[0].LocalPath(), 'eeaee') 920 self.assertEquals(got_files[0].LocalPath(), 'eeaee')
917 self.assertEquals(got_files[1].LocalPath(), 'eeabee') 921 self.assertEquals(got_files[1].LocalPath(), 'eeabee')
918 922
919 def testLambdaFilter(self): 923 def testLambdaFilter(self):
920 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",) 924 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",)
921 black_list = [r".*?b.*?"] 925 black_list = [r".*?b.*?"]
922 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')] 926 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')]
923 for _, item in files: 927 for _, item in files:
924 item = presubmit.os.path.join(self.fake_root_dir, item) 928 item = presubmit.os.path.join(self.fake_root_dir, item)
925 presubmit.os.path.exists(item).AndReturn(True) 929 presubmit.os.path.exists(item).AndReturn(True)
926 presubmit.os.path.isdir(item).AndReturn(False) 930 presubmit.os.path.isdir(item).AndReturn(False)
927 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) 931 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None)
928 self.mox.ReplayAll() 932 self.mox.ReplayAll()
929 933
930 change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0, 934 change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0,
931 0) 935 0)
932 input_api = presubmit.InputApi(change, './PRESUBMIT.py', False) 936 input_api = presubmit.InputApi(change, './PRESUBMIT.py', False,
937 False, None)
933 # Sample usage of overiding the default white and black lists. 938 # Sample usage of overiding the default white and black lists.
934 got_files = input_api.AffectedSourceFiles( 939 got_files = input_api.AffectedSourceFiles(
935 lambda x: input_api.FilterSourceFile(x, white_list, black_list)) 940 lambda x: input_api.FilterSourceFile(x, white_list, black_list))
936 self.assertEquals(len(got_files), 2) 941 self.assertEquals(len(got_files), 2)
937 self.assertEquals(got_files[0].LocalPath(), 'eeaee') 942 self.assertEquals(got_files[0].LocalPath(), 'eeaee')
938 self.assertEquals(got_files[1].LocalPath(), 'eecaee') 943 self.assertEquals(got_files[1].LocalPath(), 'eecaee')
939 944
940 def testGetAbsoluteLocalPath(self): 945 def testGetAbsoluteLocalPath(self):
941 join = presubmit.os.path.join 946 join = presubmit.os.path.join
942 normpath = presubmit.normpath 947 normpath = presubmit.normpath
(...skipping 19 matching lines...) Expand all
962 normpath(join(self.fake_root_dir, 'isdir'))) 967 normpath(join(self.fake_root_dir, 'isdir')))
963 self.assertEquals(affected_files[1].AbsoluteLocalPath(), 968 self.assertEquals(affected_files[1].AbsoluteLocalPath(),
964 normpath(join(self.fake_root_dir, 'isdir/blat.cc'))) 969 normpath(join(self.fake_root_dir, 'isdir/blat.cc')))
965 970
966 # New helper functions need to work 971 # New helper functions need to work
967 paths_from_change = change.AbsoluteLocalPaths(include_dirs=True) 972 paths_from_change = change.AbsoluteLocalPaths(include_dirs=True)
968 self.assertEqual(len(paths_from_change), 3) 973 self.assertEqual(len(paths_from_change), 3)
969 presubmit_path = join(self.fake_root_dir, 'isdir', 'PRESUBMIT.py') 974 presubmit_path = join(self.fake_root_dir, 'isdir', 'PRESUBMIT.py')
970 api = presubmit.InputApi(change=change, 975 api = presubmit.InputApi(change=change,
971 presubmit_path=presubmit_path, 976 presubmit_path=presubmit_path,
972 is_committing=True) 977 is_committing=True, tbr=False, host_url=None)
973 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True) 978 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True)
974 self.assertEqual(len(paths_from_api), 2) 979 self.assertEqual(len(paths_from_api), 2)
975 for absolute_paths in [paths_from_change, paths_from_api]: 980 for absolute_paths in [paths_from_change, paths_from_api]:
976 self.assertEqual(absolute_paths[0], 981 self.assertEqual(absolute_paths[0],
977 normpath(join(self.fake_root_dir, 'isdir'))) 982 normpath(join(self.fake_root_dir, 'isdir')))
978 self.assertEqual(absolute_paths[1], 983 self.assertEqual(absolute_paths[1],
979 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) 984 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc')))
980 985
981 def testDeprecated(self): 986 def testDeprecated(self):
982 presubmit.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), stacklevel=2) 987 presubmit.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), stacklevel=2)
983 self.mox.ReplayAll() 988 self.mox.ReplayAll()
984 989
985 change = presubmit.Change('mychange', '', self.fake_root_dir, [], 0, 0) 990 change = presubmit.Change('mychange', '', self.fake_root_dir, [], 0, 0)
986 api = presubmit.InputApi( 991 api = presubmit.InputApi(
987 change, 992 change,
988 presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True) 993 presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True,
994 False, None)
989 api.AffectedTextFiles(include_deletes=False) 995 api.AffectedTextFiles(include_deletes=False)
990 996
991 def testReadFileStringDenied(self): 997 def testReadFileStringDenied(self):
992 self.mox.ReplayAll() 998 self.mox.ReplayAll()
993 999
994 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], 1000 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
995 0, 0) 1001 0, 0)
996 input_api = presubmit.InputApi( 1002 input_api = presubmit.InputApi(
997 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) 1003 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False,
1004 False, None)
998 self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x') 1005 self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x')
999 1006
1000 def testReadFileStringAccepted(self): 1007 def testReadFileStringAccepted(self):
1001 path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo') 1008 path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo')
1002 presubmit.gclient_utils.FileRead(path, 'x').AndReturn(None) 1009 presubmit.gclient_utils.FileRead(path, 'x').AndReturn(None)
1003 self.mox.ReplayAll() 1010 self.mox.ReplayAll()
1004 1011
1005 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], 1012 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
1006 0, 0) 1013 0, 0)
1007 input_api = presubmit.InputApi( 1014 input_api = presubmit.InputApi(
1008 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) 1015 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False,
1016 False, None)
1009 input_api.ReadFile(path, 'x') 1017 input_api.ReadFile(path, 'x')
1010 1018
1011 def testReadFileAffectedFileDenied(self): 1019 def testReadFileAffectedFileDenied(self):
1012 fileobj = presubmit.AffectedFile('boo', 'M', 'Unrelated') 1020 fileobj = presubmit.AffectedFile('boo', 'M', 'Unrelated')
1013 self.mox.ReplayAll() 1021 self.mox.ReplayAll()
1014 1022
1015 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], 1023 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
1016 0, 0) 1024 0, 0)
1017 input_api = presubmit.InputApi( 1025 input_api = presubmit.InputApi(
1018 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) 1026 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False,
1027 False, None)
1019 self.assertRaises(IOError, input_api.ReadFile, fileobj, 'x') 1028 self.assertRaises(IOError, input_api.ReadFile, fileobj, 'x')
1020 1029
1021 def testReadFileAffectedFileAccepted(self): 1030 def testReadFileAffectedFileAccepted(self):
1022 fileobj = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir) 1031 fileobj = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir)
1023 presubmit.gclient_utils.FileRead(fileobj.AbsoluteLocalPath(), 'x' 1032 presubmit.gclient_utils.FileRead(fileobj.AbsoluteLocalPath(), 'x'
1024 ).AndReturn(None) 1033 ).AndReturn(None)
1025 self.mox.ReplayAll() 1034 self.mox.ReplayAll()
1026 1035
1027 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], 1036 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
1028 0, 0) 1037 0, 0)
1029 input_api = presubmit.InputApi( 1038 input_api = presubmit.InputApi(
1030 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) 1039 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False,
1040 False, None)
1031 input_api.ReadFile(fileobj, 'x') 1041 input_api.ReadFile(fileobj, 'x')
1032 1042
1033 1043
1034 class OuputApiUnittest(PresubmitTestsBase): 1044 class OuputApiUnittest(PresubmitTestsBase):
1035 """Tests presubmit.OutputApi.""" 1045 """Tests presubmit.OutputApi."""
1036 def testMembersChanged(self): 1046 def testMembersChanged(self):
1037 self.mox.ReplayAll() 1047 self.mox.ReplayAll()
1038 members = [ 1048 members = [
1039 'MailTextResult', 'PresubmitAddText', 'PresubmitError', 1049 'MailTextResult', 'PresubmitAddText', 'PresubmitError',
1040 'PresubmitNotifyResult', 'PresubmitPromptWarning', 'PresubmitResult', 1050 'PresubmitNotifyResult', 'PresubmitPromptWarning', 'PresubmitResult',
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 input_api.os_path = presubmit.os.path 1219 input_api.os_path = presubmit.os.path
1210 input_api.re = presubmit.re 1220 input_api.re = presubmit.re
1211 input_api.traceback = presubmit.traceback 1221 input_api.traceback = presubmit.traceback
1212 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) 1222 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2)
1213 input_api.unittest = unittest 1223 input_api.unittest = unittest
1214 input_api.subprocess = self.mox.CreateMock(presubmit.subprocess) 1224 input_api.subprocess = self.mox.CreateMock(presubmit.subprocess)
1215 1225
1216 input_api.change = change 1226 input_api.change = change
1217 input_api.host_url = 'http://localhost' 1227 input_api.host_url = 'http://localhost'
1218 input_api.is_committing = committing 1228 input_api.is_committing = committing
1219 input_api.ts_tbr = False 1229 input_api.tbr = False
1220 input_api.python_executable = 'pyyyyython' 1230 input_api.python_executable = 'pyyyyython'
1221 return input_api 1231 return input_api
1222 1232
1223 def testMembersChanged(self): 1233 def testMembersChanged(self):
1224 self.mox.ReplayAll() 1234 self.mox.ReplayAll()
1225 members = [ 1235 members = [
1226 'CheckChangeHasBugField', 'CheckChangeHasDescription', 1236 'CheckChangeHasBugField', 'CheckChangeHasDescription',
1227 'CheckChangeHasNoStrayWhitespace', 1237 'CheckChangeHasNoStrayWhitespace',
1228 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR', 1238 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR',
1229 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs', 1239 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs',
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 1939
1930 def testCannedCheckOwners_TBR(self): 1940 def testCannedCheckOwners_TBR(self):
1931 self.OwnersTest(is_committing=True, is_tbr=True, 1941 self.OwnersTest(is_committing=True, is_tbr=True,
1932 approvers=set(), 1942 approvers=set(),
1933 uncovered_files=set(), 1943 uncovered_files=set(),
1934 expected_results=['--tbr was specified, skipping OWNERS check\n']) 1944 expected_results=['--tbr was specified, skipping OWNERS check\n'])
1935 1945
1936 if __name__ == '__main__': 1946 if __name__ == '__main__':
1937 import unittest 1947 import unittest
1938 unittest.main() 1948 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698