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

Side by Side Diff: tests/presubmit_unittest.py

Issue 8771042: Enforces using cwd in all svn calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Address comments Created 9 years 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 | « tests/gclient_scm_test.py ('k') | tests/scm_unittest.py » ('j') | 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/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: disable=E1101,E1103 8 # pylint: disable=E1101,E1103
9 9
10 import logging 10 import logging
11 import os 11 import os
12 import StringIO 12 import StringIO
13 import sys 13 import sys
14 import time 14 import time
15 15
16 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 16 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
17 17
18 from testing_support.super_mox import mox, SuperMoxTestBase 18 from testing_support.super_mox import mox, SuperMoxTestBase
19 19
20 import owners 20 import owners
21 import presubmit_support as presubmit 21 import presubmit_support as presubmit
22 import rietveld 22 import rietveld
23 23
24 # Shortcut. 24 # Shortcut.
25 presubmit_canned_checks = presubmit.presubmit_canned_checks 25 presubmit_canned_checks = presubmit.presubmit_canned_checks
26 26
27 27
28 # Access to a protected member XXX of a client class
29 # pylint: disable=W0212
30
31
28 class PresubmitTestsBase(SuperMoxTestBase): 32 class PresubmitTestsBase(SuperMoxTestBase):
29 """Setups and tear downs the mocks but doesn't test anything as-is.""" 33 """Setups and tear downs the mocks but doesn't test anything as-is."""
30 presubmit_text = """ 34 presubmit_text = """
31 def CheckChangeOnUpload(input_api, output_api): 35 def CheckChangeOnUpload(input_api, output_api):
32 if not input_api.change.NOSUCHKEY: 36 if not input_api.change.NOSUCHKEY:
33 return [output_api.PresubmitError("!!")] 37 return [output_api.PresubmitError("!!")]
34 elif not input_api.change.REALLYNOSUCHKEY: 38 elif not input_api.change.REALLYNOSUCHKEY:
35 return [output_api.PresubmitPromptWarning("??")] 39 return [output_api.PresubmitPromptWarning("??")]
36 elif not input_api.change.REALLYABSOLUTELYNOSUCHKEY: 40 elif not input_api.change.REALLYABSOLUTELYNOSUCHKEY:
37 return [output_api.PresubmitPromptWarning("??"), 41 return [output_api.PresubmitPromptWarning("??"),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 this is line number 45 109 this is line number 45
106 + 110 +
107 this is line number 46 111 this is line number 46
108 this is line number 47 112 this is line number 47
109 -this is line number 48 113 -this is line number 48
110 +this is line number 48.1 114 +this is line number 48.1
111 this is line number 49 115 this is line number 49
112 """ 116 """
113 117
114 def setUp(self): 118 def setUp(self):
119 SuperMoxTestBase.setUp(self)
115 class FakeChange(object): 120 class FakeChange(object):
116 root = '/' 121 def __init__(self, obj):
122 self._root = obj.fake_root_dir
123 def RepositoryRoot(self):
124 return self._root
117 125
118 def RepositoryRoot(self):
119 return self.root
120
121 SuperMoxTestBase.setUp(self)
122 self.fake_change = FakeChange()
123 self.mox.StubOutWithMock(presubmit, 'random') 126 self.mox.StubOutWithMock(presubmit, 'random')
124 self.mox.StubOutWithMock(presubmit, 'warn') 127 self.mox.StubOutWithMock(presubmit, 'warn')
125 presubmit._ASKED_FOR_FEEDBACK = False 128 presubmit._ASKED_FOR_FEEDBACK = False
126 self.fake_root_dir = self.RootDir() 129 self.fake_root_dir = self.RootDir()
130 self.fake_change = FakeChange(self)
131
127 # Special mocks. 132 # Special mocks.
128 def MockAbsPath(f): 133 def MockAbsPath(f):
129 return f 134 return f
130 def MockChdir(f): 135 def MockChdir(f):
131 return None 136 return None
132 # SuperMoxTestBase already mock these but simplify our life. 137 # SuperMoxTestBase already mock these but simplify our life.
133 presubmit.os.path.abspath = MockAbsPath 138 presubmit.os.path.abspath = MockAbsPath
134 presubmit.os.getcwd = self.RootDir 139 presubmit.os.getcwd = self.RootDir
135 presubmit.os.chdir = MockChdir 140 presubmit.os.chdir = MockChdir
136 self.mox.StubOutWithMock(presubmit.scm, 'determine_scm') 141 self.mox.StubOutWithMock(presubmit.scm, 'determine_scm')
137 self.mox.StubOutWithMock(presubmit.scm.SVN, 'CaptureInfo') 142 self.mox.StubOutWithMock(presubmit.scm.SVN, '_CaptureInfo')
138 self.mox.StubOutWithMock(presubmit.scm.SVN, 'GetFileProperty') 143 self.mox.StubOutWithMock(presubmit.scm.SVN, 'GetFileProperty')
139 self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileRead') 144 self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileRead')
140 self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileWrite') 145 self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileWrite')
141 self.mox.StubOutWithMock(presubmit.scm.SVN, 'GenerateDiff') 146 self.mox.StubOutWithMock(presubmit.scm.SVN, 'GenerateDiff')
142 147
143 148
144 class PresubmitUnittest(PresubmitTestsBase): 149 class PresubmitUnittest(PresubmitTestsBase):
145 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" 150 """General presubmit_support.py tests (excluding InputApi and OutputApi)."""
146 151
147 _INHERIT_SETTINGS = 'inherit-review-settings-ok' 152 _INHERIT_SETTINGS = 'inherit-review-settings-ok'
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 'BUG=123', 251 'BUG=123',
247 ' STORY =http://foo/ \t', 252 ' STORY =http://foo/ \t',
248 'and some more regular text \t') 253 'and some more regular text \t')
249 files = [ 254 files = [
250 ['A', 'foo/blat.cc'], 255 ['A', 'foo/blat.cc'],
251 ['M', 'binary.dll'], # a binary file 256 ['M', 'binary.dll'], # a binary file
252 ['A', 'isdir'], # a directory 257 ['A', 'isdir'], # a directory
253 ['?', 'flop/notfound.txt'], # not found in SVN, still exists locally 258 ['?', 'flop/notfound.txt'], # not found in SVN, still exists locally
254 ['D', 'boo/flap.h'], 259 ['D', 'boo/flap.h'],
255 ] 260 ]
256 blat = presubmit.os.path.join(self.fake_root_dir, 'foo', 'blat.cc') 261 blat = presubmit.os.path.join('foo', 'blat.cc')
257 notfound = presubmit.os.path.join( 262 notfound = presubmit.os.path.join('flop', 'notfound.txt')
258 self.fake_root_dir, 'flop', 'notfound.txt') 263 flap = presubmit.os.path.join('boo', 'flap.h')
259 flap = presubmit.os.path.join(self.fake_root_dir, 'boo', 'flap.h') 264 binary = 'binary.dll'
260 binary = presubmit.os.path.join(self.fake_root_dir, 'binary.dll') 265 isdir = 'isdir'
261 isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir') 266 f_blat = presubmit.os.path.join(self.fake_root_dir, blat)
262 presubmit.os.path.exists(blat).AndReturn(True) 267 f_notfound = presubmit.os.path.join(self.fake_root_dir, notfound)
263 presubmit.os.path.isdir(blat).AndReturn(False) 268 f_flap = presubmit.os.path.join(self.fake_root_dir, flap)
264 presubmit.os.path.exists(binary).AndReturn(True) 269 f_binary = presubmit.os.path.join(self.fake_root_dir, binary)
265 presubmit.os.path.isdir(binary).AndReturn(False) 270 f_isdir = presubmit.os.path.join(self.fake_root_dir, isdir)
266 presubmit.os.path.exists(isdir).AndReturn(True) 271 presubmit.os.path.exists(f_blat).AndReturn(True)
267 presubmit.os.path.isdir(isdir).AndReturn(True) 272 presubmit.os.path.isdir(f_blat).AndReturn(False)
268 presubmit.os.path.exists(notfound).AndReturn(True) 273 presubmit.os.path.exists(f_binary).AndReturn(True)
269 presubmit.os.path.isdir(notfound).AndReturn(False) 274 presubmit.os.path.isdir(f_binary).AndReturn(False)
270 presubmit.os.path.exists(flap).AndReturn(False) 275 presubmit.os.path.exists(f_isdir).AndReturn(True)
271 presubmit.scm.SVN.CaptureInfo(flap 276 presubmit.os.path.isdir(f_isdir).AndReturn(True)
277 presubmit.os.path.exists(f_notfound).AndReturn(True)
278 presubmit.os.path.isdir(f_notfound).AndReturn(False)
279 presubmit.os.path.exists(f_flap).AndReturn(False)
280 presubmit.scm.SVN._CaptureInfo([flap], self.fake_root_dir
272 ).AndReturn({'Node Kind': 'file'}) 281 ).AndReturn({'Node Kind': 'file'})
273 presubmit.scm.SVN.GetFileProperty(blat, 'svn:mime-type').AndReturn(None)
274 presubmit.scm.SVN.GetFileProperty( 282 presubmit.scm.SVN.GetFileProperty(
275 binary, 'svn:mime-type').AndReturn('application/octet-stream') 283 blat, 'svn:mime-type', self.fake_root_dir).AndReturn(None)
276 presubmit.scm.SVN.GetFileProperty( 284 presubmit.scm.SVN.GetFileProperty(
277 notfound, 'svn:mime-type').AndReturn('') 285 binary, 'svn:mime-type', self.fake_root_dir
278 presubmit.scm.SVN.CaptureInfo(blat).AndReturn( 286 ).AndReturn('application/octet-stream')
287 presubmit.scm.SVN.GetFileProperty(
288 notfound, 'svn:mime-type', self.fake_root_dir).AndReturn('')
289 presubmit.scm.SVN._CaptureInfo([blat], self.fake_root_dir).AndReturn(
279 {'URL': 'svn:/foo/foo/blat.cc'}) 290 {'URL': 'svn:/foo/foo/blat.cc'})
280 presubmit.scm.SVN.CaptureInfo(binary).AndReturn( 291 presubmit.scm.SVN._CaptureInfo([binary], self.fake_root_dir).AndReturn(
281 {'URL': 'svn:/foo/binary.dll'}) 292 {'URL': 'svn:/foo/binary.dll'})
282 presubmit.scm.SVN.CaptureInfo(notfound).AndReturn({}) 293 presubmit.scm.SVN._CaptureInfo([notfound], self.fake_root_dir).AndReturn({})
283 presubmit.scm.SVN.CaptureInfo(flap).AndReturn( 294 presubmit.scm.SVN._CaptureInfo([flap], self.fake_root_dir).AndReturn(
284 {'URL': 'svn:/foo/boo/flap.h'}) 295 {'URL': 'svn:/foo/boo/flap.h'})
285 presubmit.scm.SVN.GenerateDiff([blat]).AndReturn(self.presubmit_diffs) 296 presubmit.scm.SVN.GenerateDiff([blat], self.fake_root_dir, False, None
286 presubmit.scm.SVN.GenerateDiff([notfound]).AndReturn(self.presubmit_diffs) 297 ).AndReturn(self.presubmit_diffs)
298 presubmit.scm.SVN.GenerateDiff([notfound], self.fake_root_dir, False, None
299 ).AndReturn(self.presubmit_diffs)
287 300
288 self.mox.ReplayAll() 301 self.mox.ReplayAll()
289 302
290 change = presubmit.SvnChange( 303 change = presubmit.SvnChange(
291 'mychange', 304 'mychange',
292 '\n'.join(description_lines), 305 '\n'.join(description_lines),
293 self.fake_root_dir, 306 self.fake_root_dir,
294 files, 307 files,
295 0, 308 0,
296 0, 309 0,
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 'os_path', 'owners_db', 'pickle', 'platform', 'python_executable', 're', 852 'os_path', 'owners_db', 'pickle', 'platform', 'python_executable', 're',
840 'rietveld', 'subprocess', 'tbr', 'tempfile', 'time', 'traceback', 853 'rietveld', 'subprocess', 'tbr', 'tempfile', 'time', 'traceback',
841 'unittest', 'urllib2', 'version', 'verbose', 854 'unittest', 'urllib2', 'version', 'verbose',
842 ] 855 ]
843 # If this test fails, you should add the relevant test. 856 # If this test fails, you should add the relevant test.
844 self.compareMembers( 857 self.compareMembers(
845 presubmit.InputApi(self.fake_change, './.', False, None, False), 858 presubmit.InputApi(self.fake_change, './.', False, None, False),
846 members) 859 members)
847 860
848 def testDepotToLocalPath(self): 861 def testDepotToLocalPath(self):
849 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn( 862 presubmit.scm.SVN._CaptureInfo(['svn://foo/smurf'], self.fake_root_dir
850 {'Path': 'prout'}) 863 ).AndReturn({'Path': 'prout'})
851 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({}) 864 presubmit.scm.SVN._CaptureInfo(
865 ['svn:/foo/notfound/burp'], self.fake_root_dir
866 ).AndReturn({})
852 self.mox.ReplayAll() 867 self.mox.ReplayAll()
853 868
854 path = presubmit.InputApi( 869 path = presubmit.InputApi(
855 self.fake_change, './p', False, None, False).DepotToLocalPath( 870 self.fake_change, './p', False, None, False).DepotToLocalPath(
856 'svn://foo/smurf') 871 'svn://foo/smurf')
857 self.failUnless(path == 'prout') 872 self.failUnless(path == 'prout')
858 path = presubmit.InputApi( 873 path = presubmit.InputApi(
859 self.fake_change, './p', False, None, False).DepotToLocalPath( 874 self.fake_change, './p', False, None, False).DepotToLocalPath(
860 'svn:/foo/notfound/burp') 875 'svn:/foo/notfound/burp')
861 self.failUnless(path == None) 876 self.failUnless(path == None)
862 877
863 def testLocalToDepotPath(self): 878 def testLocalToDepotPath(self):
864 presubmit.scm.SVN.CaptureInfo('smurf').AndReturn({'URL': 'svn://foo'}) 879 presubmit.scm.SVN._CaptureInfo(['smurf'], self.fake_root_dir
865 presubmit.scm.SVN.CaptureInfo('notfound-food').AndReturn({}) 880 ).AndReturn({'URL': 'svn://foo'})
881 presubmit.scm.SVN._CaptureInfo(['notfound-food'], self.fake_root_dir
882 ).AndReturn({})
866 self.mox.ReplayAll() 883 self.mox.ReplayAll()
867 path = presubmit.InputApi( 884 path = presubmit.InputApi(
868 self.fake_change, './p', False, None, False).LocalToDepotPath( 885 self.fake_change, './p', False, None, False).LocalToDepotPath(
869 'smurf') 886 'smurf')
870 self.assertEqual(path, 'svn://foo') 887 self.assertEqual(path, 'svn://foo')
871 path = presubmit.InputApi( 888 path = presubmit.InputApi(
872 self.fake_change, './p', False, None, False).LocalToDepotPath( 889 self.fake_change, './p', False, None, False).LocalToDepotPath(
873 'notfound-food') 890 'notfound-food')
874 self.assertEquals(path, None) 891 self.assertEquals(path, None)
875 892
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 beingdeleted = presubmit.normpath(join(self.fake_root_dir, files[6][1])) 927 beingdeleted = presubmit.normpath(join(self.fake_root_dir, files[6][1]))
911 notfound = presubmit.normpath(join(self.fake_root_dir, files[7][1])) 928 notfound = presubmit.normpath(join(self.fake_root_dir, files[7][1]))
912 flap = presubmit.normpath(join(self.fake_root_dir, files[8][1])) 929 flap = presubmit.normpath(join(self.fake_root_dir, files[8][1]))
913 for i in (blat, readme, binary, weird, another, third_party): 930 for i in (blat, readme, binary, weird, another, third_party):
914 presubmit.os.path.exists(i).AndReturn(True) 931 presubmit.os.path.exists(i).AndReturn(True)
915 presubmit.os.path.isdir(i).AndReturn(False) 932 presubmit.os.path.isdir(i).AndReturn(False)
916 presubmit.os.path.exists(beingdeleted).AndReturn(False) 933 presubmit.os.path.exists(beingdeleted).AndReturn(False)
917 presubmit.os.path.exists(notfound).AndReturn(False) 934 presubmit.os.path.exists(notfound).AndReturn(False)
918 presubmit.os.path.exists(flap).AndReturn(True) 935 presubmit.os.path.exists(flap).AndReturn(True)
919 presubmit.os.path.isdir(flap).AndReturn(False) 936 presubmit.os.path.isdir(flap).AndReturn(False)
920 presubmit.scm.SVN.CaptureInfo(beingdeleted).AndReturn({}) 937 presubmit.scm.SVN._CaptureInfo(
921 presubmit.scm.SVN.CaptureInfo(notfound).AndReturn({}) 938 [files[6][1]], self.fake_root_dir).AndReturn({})
922 presubmit.scm.SVN.GetFileProperty(blat, 'svn:mime-type').AndReturn(None) 939 presubmit.scm.SVN._CaptureInfo(
923 presubmit.scm.SVN.GetFileProperty(readme, 'svn:mime-type').AndReturn(None) 940 [files[7][1]], self.fake_root_dir).AndReturn({})
924 presubmit.scm.SVN.GetFileProperty(binary, 'svn:mime-type').AndReturn( 941 presubmit.scm.SVN.GetFileProperty(
925 'application/octet-stream') 942 files[0][1], 'svn:mime-type', self.fake_root_dir
926 presubmit.scm.SVN.GetFileProperty(weird, 'svn:mime-type').AndReturn(None)
927 presubmit.scm.SVN.GetFileProperty(another, 'svn:mime-type').AndReturn(None)
928 presubmit.scm.SVN.GetFileProperty(third_party, 'svn:mime-type'
929 ).AndReturn(None) 943 ).AndReturn(None)
930 presubmit.scm.SVN.GenerateDiff([blat]).AndReturn(self.presubmit_diffs) 944 presubmit.scm.SVN.GetFileProperty(
931 presubmit.scm.SVN.GenerateDiff([another]).AndReturn(self.presubmit_diffs) 945 files[1][1], 'svn:mime-type', self.fake_root_dir
946 ).AndReturn(None)
947 presubmit.scm.SVN.GetFileProperty(
948 files[2][1], 'svn:mime-type', self.fake_root_dir
949 ).AndReturn('application/octet-stream')
950 presubmit.scm.SVN.GetFileProperty(
951 files[3][1], 'svn:mime-type', self.fake_root_dir
952 ).AndReturn(None)
953 presubmit.scm.SVN.GetFileProperty(
954 files[4][1], 'svn:mime-type', self.fake_root_dir
955 ).AndReturn(None)
956 presubmit.scm.SVN.GetFileProperty(
957 files[5][1], 'svn:mime-type', self.fake_root_dir
958 ).AndReturn(None)
959 presubmit.scm.SVN.GenerateDiff(
960 [files[0][1]], self.fake_root_dir, False, None
961 ).AndReturn(self.presubmit_diffs)
962 presubmit.scm.SVN.GenerateDiff(
963 [files[4][1]], self.fake_root_dir, False, None
964 ).AndReturn(self.presubmit_diffs)
932 965
933 self.mox.ReplayAll() 966 self.mox.ReplayAll()
934 967
935 change = presubmit.SvnChange( 968 change = presubmit.SvnChange(
936 'mychange', 969 'mychange',
937 '\n'.join(description_lines), 970 '\n'.join(description_lines),
938 self.fake_root_dir, 971 self.fake_root_dir,
939 files, 972 files,
940 0, 973 0,
941 0, 974 0,
(...skipping 21 matching lines...) Expand all
963 presubmit.normpath(files[0][1])) 996 presubmit.normpath(files[0][1]))
964 self.assertEqual(rhs_lines[3][0].LocalPath(), 997 self.assertEqual(rhs_lines[3][0].LocalPath(),
965 presubmit.normpath(files[0][1])) 998 presubmit.normpath(files[0][1]))
966 self.assertEqual(rhs_lines[7][0].LocalPath(), 999 self.assertEqual(rhs_lines[7][0].LocalPath(),
967 presubmit.normpath(files[4][1])) 1000 presubmit.normpath(files[4][1]))
968 self.assertEqual(rhs_lines[13][0].LocalPath(), 1001 self.assertEqual(rhs_lines[13][0].LocalPath(),
969 presubmit.normpath(files[4][1])) 1002 presubmit.normpath(files[4][1]))
970 1003
971 def testDefaultWhiteListBlackListFilters(self): 1004 def testDefaultWhiteListBlackListFilters(self):
972 def f(x): 1005 def f(x):
973 return presubmit.AffectedFile(x, 'M') 1006 return presubmit.AffectedFile(x, 'M', self.fake_root_dir)
974 files = [ 1007 files = [
975 ( 1008 (
976 [ 1009 [
977 # To be tested. 1010 # To be tested.
978 f('a/experimental/b'), 1011 f('a/experimental/b'),
979 f('experimental/b'), 1012 f('experimental/b'),
980 f('a/experimental'), 1013 f('a/experimental'),
981 f('a/experimental.cc'), 1014 f('a/experimental.cc'),
982 f('a/experimental.S'), 1015 f('a/experimental.S'),
983 ], 1016 ],
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 # Same number of expected results. 1077 # Same number of expected results.
1045 self.assertEquals(sorted([f.LocalPath().replace(presubmit.os.sep, '/') 1078 self.assertEquals(sorted([f.LocalPath().replace(presubmit.os.sep, '/')
1046 for f in results]), 1079 for f in results]),
1047 sorted(item[1])) 1080 sorted(item[1]))
1048 1081
1049 def testCustomFilter(self): 1082 def testCustomFilter(self):
1050 def FilterSourceFile(affected_file): 1083 def FilterSourceFile(affected_file):
1051 return 'a' in affected_file.LocalPath() 1084 return 'a' in affected_file.LocalPath()
1052 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')] 1085 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')]
1053 for _, item in files: 1086 for _, item in files:
1054 item = presubmit.os.path.join(self.fake_root_dir, item) 1087 full_item = presubmit.os.path.join(self.fake_root_dir, item)
1055 presubmit.os.path.exists(item).AndReturn(True) 1088 presubmit.os.path.exists(full_item).AndReturn(True)
1056 presubmit.os.path.isdir(item).AndReturn(False) 1089 presubmit.os.path.isdir(full_item).AndReturn(False)
1057 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) 1090 presubmit.scm.SVN.GetFileProperty(
1091 item, 'svn:mime-type', self.fake_root_dir).AndReturn(None)
1058 self.mox.ReplayAll() 1092 self.mox.ReplayAll()
1059 1093
1060 change = presubmit.SvnChange( 1094 change = presubmit.SvnChange(
1061 'mychange', '', self.fake_root_dir, files, 0, 0, None) 1095 'mychange', '', self.fake_root_dir, files, 0, 0, None)
1062 input_api = presubmit.InputApi( 1096 input_api = presubmit.InputApi(
1063 change, 1097 change,
1064 presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py'), 1098 presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py'),
1065 False, None, False) 1099 False, None, False)
1066 got_files = input_api.AffectedSourceFiles(FilterSourceFile) 1100 got_files = input_api.AffectedSourceFiles(FilterSourceFile)
1067 self.assertEquals(len(got_files), 2) 1101 self.assertEquals(len(got_files), 2)
1068 self.assertEquals(got_files[0].LocalPath(), 'eeaee') 1102 self.assertEquals(got_files[0].LocalPath(), 'eeaee')
1069 self.assertEquals(got_files[1].LocalPath(), 'eeabee') 1103 self.assertEquals(got_files[1].LocalPath(), 'eeabee')
1070 1104
1071 def testLambdaFilter(self): 1105 def testLambdaFilter(self):
1072 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",) 1106 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",)
1073 black_list = [r".*?b.*?"] 1107 black_list = [r".*?b.*?"]
1074 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')] 1108 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')]
1075 for _, item in files: 1109 for _, item in files:
1076 item = presubmit.os.path.join(self.fake_root_dir, item) 1110 full_item = presubmit.os.path.join(self.fake_root_dir, item)
1077 presubmit.os.path.exists(item).AndReturn(True) 1111 presubmit.os.path.exists(full_item).AndReturn(True)
1078 presubmit.os.path.isdir(item).AndReturn(False) 1112 presubmit.os.path.isdir(full_item).AndReturn(False)
1079 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) 1113 presubmit.scm.SVN.GetFileProperty(
1114 item, 'svn:mime-type', self.fake_root_dir).AndReturn(None)
1080 self.mox.ReplayAll() 1115 self.mox.ReplayAll()
1081 1116
1082 change = presubmit.SvnChange( 1117 change = presubmit.SvnChange(
1083 'mychange', '', self.fake_root_dir, files, 0, 0, None) 1118 'mychange', '', self.fake_root_dir, files, 0, 0, None)
1084 input_api = presubmit.InputApi( 1119 input_api = presubmit.InputApi(
1085 change, './PRESUBMIT.py', False, None, False) 1120 change, './PRESUBMIT.py', False, None, False)
1086 # Sample usage of overiding the default white and black lists. 1121 # Sample usage of overiding the default white and black lists.
1087 got_files = input_api.AffectedSourceFiles( 1122 got_files = input_api.AffectedSourceFiles(
1088 lambda x: input_api.FilterSourceFile(x, white_list, black_list)) 1123 lambda x: input_api.FilterSourceFile(x, white_list, black_list))
1089 self.assertEquals(len(got_files), 2) 1124 self.assertEquals(len(got_files), 2)
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 1296
1262 class AffectedFileUnittest(PresubmitTestsBase): 1297 class AffectedFileUnittest(PresubmitTestsBase):
1263 def testMembersChanged(self): 1298 def testMembersChanged(self):
1264 self.mox.ReplayAll() 1299 self.mox.ReplayAll()
1265 members = [ 1300 members = [
1266 'AbsoluteLocalPath', 'Action', 'ChangedContents', 'GenerateScmDiff', 1301 'AbsoluteLocalPath', 'Action', 'ChangedContents', 'GenerateScmDiff',
1267 'IsDirectory', 'IsTextFile', 'LocalPath', 'NewContents', 'OldContents', 1302 'IsDirectory', 'IsTextFile', 'LocalPath', 'NewContents', 'OldContents',
1268 'OldFileTempPath', 'Property', 'ServerPath', 1303 'OldFileTempPath', 'Property', 'ServerPath',
1269 ] 1304 ]
1270 # If this test fails, you should add the relevant test. 1305 # If this test fails, you should add the relevant test.
1271 self.compareMembers(presubmit.AffectedFile('a', 'b'), members) 1306 self.compareMembers(
1272 self.compareMembers(presubmit.SvnAffectedFile('a', 'b'), members) 1307 presubmit.AffectedFile('a', 'b', self.fake_root_dir), members)
1308 self.compareMembers(
1309 presubmit.SvnAffectedFile('a', 'b', self.fake_root_dir), members)
1273 1310
1274 def testAffectedFile(self): 1311 def testAffectedFile(self):
1275 path = presubmit.os.path.join('foo', 'blat.cc') 1312 path = presubmit.os.path.join('foo', 'blat.cc')
1276 presubmit.os.path.exists(path).AndReturn(True) 1313 f_path = presubmit.os.path.join(self.fake_root_dir, path)
1277 presubmit.os.path.isdir(path).AndReturn(False) 1314 presubmit.os.path.exists(f_path).AndReturn(True)
1278 presubmit.gclient_utils.FileRead(path, 'rU').AndReturn('whatever\ncookie') 1315 presubmit.os.path.isdir(f_path).AndReturn(False)
1279 presubmit.scm.SVN.CaptureInfo(path).AndReturn( 1316 presubmit.gclient_utils.FileRead(f_path, 'rU').AndReturn('whatever\ncookie')
1317 presubmit.scm.SVN._CaptureInfo([path], self.fake_root_dir).AndReturn(
1280 {'URL': 'svn:/foo/foo/blat.cc'}) 1318 {'URL': 'svn:/foo/foo/blat.cc'})
1281 self.mox.ReplayAll() 1319 self.mox.ReplayAll()
1282 af = presubmit.SvnAffectedFile('foo/blat.cc', 'M') 1320 af = presubmit.SvnAffectedFile('foo/blat.cc', 'M', self.fake_root_dir)
1283 self.assertEquals('svn:/foo/foo/blat.cc', af.ServerPath()) 1321 self.assertEquals('svn:/foo/foo/blat.cc', af.ServerPath())
1284 self.assertEquals(presubmit.normpath('foo/blat.cc'), af.LocalPath()) 1322 self.assertEquals(presubmit.normpath('foo/blat.cc'), af.LocalPath())
1285 self.assertEquals('M', af.Action()) 1323 self.assertEquals('M', af.Action())
1286 self.assertEquals(['whatever', 'cookie'], af.NewContents()) 1324 self.assertEquals(['whatever', 'cookie'], af.NewContents())
1287 1325
1288 def testAffectedFileNotExists(self): 1326 def testAffectedFileNotExists(self):
1289 presubmit.os.path.exists('notfound.cc').AndReturn(False) 1327 notfound = 'notfound.cc'
1290 presubmit.gclient_utils.FileRead('notfound.cc', 'rU').AndRaise(IOError) 1328 f_notfound = presubmit.os.path.join(self.fake_root_dir, notfound)
1329 presubmit.os.path.exists(f_notfound).AndReturn(False)
1330 presubmit.gclient_utils.FileRead(f_notfound, 'rU').AndRaise(IOError)
1291 self.mox.ReplayAll() 1331 self.mox.ReplayAll()
1292 af = presubmit.AffectedFile('notfound.cc', 'A') 1332 af = presubmit.AffectedFile(notfound, 'A', self.fake_root_dir)
1293 self.assertEquals('', af.ServerPath()) 1333 self.assertEquals('', af.ServerPath())
1294 self.assertEquals([], af.NewContents()) 1334 self.assertEquals([], af.NewContents())
1295 1335
1296 def testProperty(self): 1336 def testProperty(self):
1297 presubmit.scm.SVN.GetFileProperty('foo.cc', 'svn:secret-property' 1337 presubmit.scm.SVN.GetFileProperty(
1338 'foo.cc', 'svn:secret-property', self.fake_root_dir
1298 ).AndReturn('secret-property-value') 1339 ).AndReturn('secret-property-value')
1299 self.mox.ReplayAll() 1340 self.mox.ReplayAll()
1300 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') 1341 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A', self.fake_root_dir)
1301 # Verify cache coherency. 1342 # Verify cache coherency.
1302 self.assertEquals('secret-property-value', 1343 self.assertEquals('secret-property-value',
1303 affected_file.Property('svn:secret-property')) 1344 affected_file.Property('svn:secret-property'))
1304 self.assertEquals('secret-property-value', 1345 self.assertEquals('secret-property-value',
1305 affected_file.Property('svn:secret-property')) 1346 affected_file.Property('svn:secret-property'))
1306 1347
1307 def testIsDirectoryNotExists(self): 1348 def testIsDirectoryNotExists(self):
1308 presubmit.os.path.exists('foo.cc').AndReturn(False) 1349 filename = 'foo.cc'
1309 presubmit.scm.SVN.CaptureInfo('foo.cc').AndReturn({}) 1350 f_filename = presubmit.os.path.join(self.fake_root_dir, filename)
1351 presubmit.os.path.exists(f_filename).AndReturn(False)
1352 presubmit.scm.SVN._CaptureInfo([filename], self.fake_root_dir).AndReturn({})
1310 self.mox.ReplayAll() 1353 self.mox.ReplayAll()
1311 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') 1354 affected_file = presubmit.SvnAffectedFile(filename, 'A', self.fake_root_dir)
1312 # Verify cache coherency. 1355 # Verify cache coherency.
1313 self.failIf(affected_file.IsDirectory()) 1356 self.failIf(affected_file.IsDirectory())
1314 self.failIf(affected_file.IsDirectory()) 1357 self.failIf(affected_file.IsDirectory())
1315 1358
1316 def testIsDirectory(self): 1359 def testIsDirectory(self):
1317 presubmit.os.path.exists('foo.cc').AndReturn(True) 1360 filename = 'foo.cc'
1318 presubmit.os.path.isdir('foo.cc').AndReturn(True) 1361 f_filename = presubmit.os.path.join(self.fake_root_dir, filename)
1362 presubmit.os.path.exists(f_filename).AndReturn(True)
1363 presubmit.os.path.isdir(f_filename).AndReturn(True)
1319 self.mox.ReplayAll() 1364 self.mox.ReplayAll()
1320 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') 1365 affected_file = presubmit.SvnAffectedFile(filename, 'A', self.fake_root_dir)
1321 # Verify cache coherency. 1366 # Verify cache coherency.
1322 self.failUnless(affected_file.IsDirectory()) 1367 self.failUnless(affected_file.IsDirectory())
1323 self.failUnless(affected_file.IsDirectory()) 1368 self.failUnless(affected_file.IsDirectory())
1324 1369
1325 def testIsTextFile(self): 1370 def testIsTextFile(self):
1326 files = [presubmit.SvnAffectedFile('foo/blat.txt', 'M'), 1371 files = [
1327 presubmit.SvnAffectedFile('foo/binary.blob', 'M'), 1372 presubmit.SvnAffectedFile('foo/blat.txt', 'M', self.fake_root_dir),
1328 presubmit.SvnAffectedFile('blat/flop.txt', 'D')] 1373 presubmit.SvnAffectedFile('foo/binary.blob', 'M', self.fake_root_dir),
1374 presubmit.SvnAffectedFile('blat/flop.txt', 'D', self.fake_root_dir)
1375 ]
1329 blat = presubmit.os.path.join('foo', 'blat.txt') 1376 blat = presubmit.os.path.join('foo', 'blat.txt')
1330 blob = presubmit.os.path.join('foo', 'binary.blob') 1377 blob = presubmit.os.path.join('foo', 'binary.blob')
1331 presubmit.os.path.exists(blat).AndReturn(True) 1378 f_blat = presubmit.os.path.join(self.fake_root_dir, blat)
1332 presubmit.os.path.isdir(blat).AndReturn(False) 1379 f_blob = presubmit.os.path.join(self.fake_root_dir, blob)
1333 presubmit.os.path.exists(blob).AndReturn(True) 1380 presubmit.os.path.exists(f_blat).AndReturn(True)
1334 presubmit.os.path.isdir(blob).AndReturn(False) 1381 presubmit.os.path.isdir(f_blat).AndReturn(False)
1335 presubmit.scm.SVN.GetFileProperty(blat, 'svn:mime-type').AndReturn(None) 1382 presubmit.os.path.exists(f_blob).AndReturn(True)
1336 presubmit.scm.SVN.GetFileProperty(blob, 'svn:mime-type' 1383 presubmit.os.path.isdir(f_blob).AndReturn(False)
1384 presubmit.scm.SVN.GetFileProperty(blat, 'svn:mime-type', self.fake_root_dir
1385 ).AndReturn(None)
1386 presubmit.scm.SVN.GetFileProperty(blob, 'svn:mime-type', self.fake_root_dir
1337 ).AndReturn('application/octet-stream') 1387 ).AndReturn('application/octet-stream')
1338 self.mox.ReplayAll() 1388 self.mox.ReplayAll()
1339 1389
1340 output = filter(lambda x: x.IsTextFile(), files) 1390 output = filter(lambda x: x.IsTextFile(), files)
1341 self.assertEquals(1, len(output)) 1391 self.assertEquals(1, len(output))
1342 self.assertEquals(files[0], output[0]) 1392 self.assertEquals(files[0], output[0])
1343 1393
1344 1394
1345 class ChangeUnittest(PresubmitTestsBase): 1395 class ChangeUnittest(PresubmitTestsBase):
1346 def testMembersChanged(self): 1396 def testMembersChanged(self):
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 results2 = check(input_api2, presubmit.OutputApi) 1573 results2 = check(input_api2, presubmit.OutputApi)
1524 self.assertEquals(len(results2), 1) 1574 self.assertEquals(len(results2), 1)
1525 self.assertEquals(results2[0].__class__, error_type) 1575 self.assertEquals(results2[0].__class__, error_type)
1526 1576
1527 def SvnPropertyTest(self, check, property_name, value1, value2, committing, 1577 def SvnPropertyTest(self, check, property_name, value1, value2, committing,
1528 error_type, use_source_file): 1578 error_type, use_source_file):
1529 change1 = presubmit.SvnChange( 1579 change1 = presubmit.SvnChange(
1530 'mychange', '', self.fake_root_dir, [], 0, 0, None) 1580 'mychange', '', self.fake_root_dir, [], 0, 0, None)
1531 input_api1 = self.MockInputApi(change1, committing) 1581 input_api1 = self.MockInputApi(change1, committing)
1532 files1 = [ 1582 files1 = [
1533 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), 1583 presubmit.SvnAffectedFile('foo/bar.cc', 'A', self.fake_root_dir),
1534 presubmit.SvnAffectedFile('foo.cc', 'M'), 1584 presubmit.SvnAffectedFile('foo.cc', 'M', self.fake_root_dir),
1535 ] 1585 ]
1536 if use_source_file: 1586 if use_source_file:
1537 input_api1.AffectedSourceFiles(None).AndReturn(files1) 1587 input_api1.AffectedSourceFiles(None).AndReturn(files1)
1538 else: 1588 else:
1539 input_api1.AffectedFiles(include_deleted=False).AndReturn(files1) 1589 input_api1.AffectedFiles(include_deleted=False).AndReturn(files1)
1540 presubmit.scm.SVN.GetFileProperty(presubmit.normpath('foo/bar.cc'), 1590 presubmit.scm.SVN.GetFileProperty(
1541 property_name).AndReturn(value1) 1591 presubmit.normpath('foo/bar.cc'), property_name, self.fake_root_dir
1542 presubmit.scm.SVN.GetFileProperty(presubmit.normpath('foo.cc'), 1592 ).AndReturn(value1)
1543 property_name).AndReturn(value1) 1593 presubmit.scm.SVN.GetFileProperty(
1594 presubmit.normpath('foo.cc'), property_name, self.fake_root_dir
1595 ).AndReturn(value1)
1544 change2 = presubmit.SvnChange( 1596 change2 = presubmit.SvnChange(
1545 'mychange', '', self.fake_root_dir, [], 0, 0, None) 1597 'mychange', '', self.fake_root_dir, [], 0, 0, None)
1546 input_api2 = self.MockInputApi(change2, committing) 1598 input_api2 = self.MockInputApi(change2, committing)
1547 files2 = [ 1599 files2 = [
1548 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), 1600 presubmit.SvnAffectedFile('foo/bar.cc', 'A', self.fake_root_dir),
1549 presubmit.SvnAffectedFile('foo.cc', 'M'), 1601 presubmit.SvnAffectedFile('foo.cc', 'M', self.fake_root_dir),
1550 ] 1602 ]
1551 if use_source_file: 1603 if use_source_file:
1552 input_api2.AffectedSourceFiles(None).AndReturn(files2) 1604 input_api2.AffectedSourceFiles(None).AndReturn(files2)
1553 else: 1605 else:
1554 input_api2.AffectedFiles(include_deleted=False).AndReturn(files2) 1606 input_api2.AffectedFiles(include_deleted=False).AndReturn(files2)
1555 1607
1556 presubmit.scm.SVN.GetFileProperty(presubmit.normpath('foo/bar.cc'), 1608 presubmit.scm.SVN.GetFileProperty(
1557 property_name).AndReturn(value2) 1609 presubmit.normpath('foo/bar.cc'), property_name, self.fake_root_dir
1558 presubmit.scm.SVN.GetFileProperty(presubmit.normpath('foo.cc'), 1610 ).AndReturn(value2)
1559 property_name).AndReturn(value2) 1611 presubmit.scm.SVN.GetFileProperty(
1612 presubmit.normpath('foo.cc'), property_name, self.fake_root_dir
1613 ).AndReturn(value2)
1560 self.mox.ReplayAll() 1614 self.mox.ReplayAll()
1561 1615
1562 results1 = check(input_api1, presubmit.OutputApi, None) 1616 results1 = check(input_api1, presubmit.OutputApi, None)
1563 self.assertEquals(results1, []) 1617 self.assertEquals(results1, [])
1564 results2 = check(input_api2, presubmit.OutputApi, None) 1618 results2 = check(input_api2, presubmit.OutputApi, None)
1565 self.assertEquals(len(results2), 1) 1619 self.assertEquals(len(results2), 1)
1566 self.assertEquals(results2[0].__class__, error_type) 1620 self.assertEquals(results2[0].__class__, error_type)
1567 1621
1568 def testCannedCheckChangeHasBugField(self): 1622 def testCannedCheckChangeHasBugField(self):
1569 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, 1623 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 # Override the mock of these functions. 1732 # Override the mock of these functions.
1679 input_api1.FilterSourceFile = lambda x: x 1733 input_api1.FilterSourceFile = lambda x: x
1680 input_api1.AffectedFiles = test 1734 input_api1.AffectedFiles = test
1681 self.mox.ReplayAll() 1735 self.mox.ReplayAll()
1682 1736
1683 results1 = presubmit_canned_checks.CheckChangeHasNoTabs(input_api1, 1737 results1 = presubmit_canned_checks.CheckChangeHasNoTabs(input_api1,
1684 presubmit.OutputApi, None) 1738 presubmit.OutputApi, None)
1685 self.assertEquals(len(results1), 1) 1739 self.assertEquals(len(results1), 1)
1686 self.assertEquals(results1[0].__class__, 1740 self.assertEquals(results1[0].__class__,
1687 presubmit.OutputApi.PresubmitPromptWarning) 1741 presubmit.OutputApi.PresubmitPromptWarning)
1688 # pylint: disable=W0212
1689 self.assertEquals(results1[0]._long_text, 1742 self.assertEquals(results1[0]._long_text,
1690 'makefile.foo, line 46') 1743 'makefile.foo, line 46')
1691 1744
1692 def testCannedCheckLongLines(self): 1745 def testCannedCheckLongLines(self):
1693 check = lambda x, y, z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) 1746 check = lambda x, y, z: presubmit_canned_checks.CheckLongLines(x, y, 10, z)
1694 self.ContentTest(check, '0123456789', '01234567890', 1747 self.ContentTest(check, '0123456789', '01234567890',
1695 presubmit.OutputApi.PresubmitPromptWarning) 1748 presubmit.OutputApi.PresubmitPromptWarning)
1696 1749
1697 def testCannedCheckLongLinesLF(self): 1750 def testCannedCheckLongLinesLF(self):
1698 check = lambda x, y, z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) 1751 check = lambda x, y, z: presubmit_canned_checks.CheckLongLines(x, y, 10, z)
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 check = presubmit_canned_checks.CheckSvnModifiedDirectories 1882 check = presubmit_canned_checks.CheckSvnModifiedDirectories
1830 results = check(input_api, presubmit.OutputApi, None) 1883 results = check(input_api, presubmit.OutputApi, None)
1831 self.assertEquals(len(results), 1) 1884 self.assertEquals(len(results), 1)
1832 self.assertEquals(results[0].__class__, 1885 self.assertEquals(results[0].__class__,
1833 presubmit.OutputApi.PresubmitPromptWarning) 1886 presubmit.OutputApi.PresubmitPromptWarning)
1834 1887
1835 def testCheckSvnForCommonMimeTypes(self): 1888 def testCheckSvnForCommonMimeTypes(self):
1836 self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty') 1889 self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty')
1837 input_api = self.MockInputApi(None, False) 1890 input_api = self.MockInputApi(None, False)
1838 output_api = presubmit.OutputApi() 1891 output_api = presubmit.OutputApi()
1839 A = lambda x: presubmit.AffectedFile(x, 'M') 1892 A = lambda x: presubmit.AffectedFile(x, 'M', self.fake_root_dir)
1840 files = [ 1893 files = [
1841 A('a.pdf'), A('b.bmp'), A('c.gif'), A('d.png'), A('e.jpg'), A('f.jpe'), 1894 A('a.pdf'), A('b.bmp'), A('c.gif'), A('d.png'), A('e.jpg'), A('f.jpe'),
1842 A('random'), A('g.jpeg'), A('h.ico'), 1895 A('random'), A('g.jpeg'), A('h.ico'),
1843 ] 1896 ]
1844 input_api.AffectedFiles(include_deletes=False).AndReturn(files) 1897 input_api.AffectedFiles(include_deletes=False).AndReturn(files)
1845 presubmit_canned_checks.CheckSvnProperty( 1898 presubmit_canned_checks.CheckSvnProperty(
1846 input_api, output_api, 'svn:mime-type', 'application/pdf', [files[0]] 1899 input_api, output_api, 'svn:mime-type', 'application/pdf', [files[0]]
1847 ).AndReturn([1]) 1900 ).AndReturn([1])
1848 presubmit_canned_checks.CheckSvnProperty( 1901 presubmit_canned_checks.CheckSvnProperty(
1849 input_api, output_api, 'svn:mime-type', 'image/bmp', [files[1]] 1902 input_api, output_api, 'svn:mime-type', 'image/bmp', [files[1]]
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None, 2021 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None,
1969 stderr=input_api.subprocess.STDOUT).AndRaise( 2022 stderr=input_api.subprocess.STDOUT).AndRaise(
1970 input_api.subprocess.CalledProcessError()) 2023 input_api.subprocess.CalledProcessError())
1971 self.mox.ReplayAll() 2024 self.mox.ReplayAll()
1972 2025
1973 results = presubmit_canned_checks.RunPythonUnitTests( 2026 results = presubmit_canned_checks.RunPythonUnitTests(
1974 input_api, presubmit.OutputApi, ['test_module']) 2027 input_api, presubmit.OutputApi, ['test_module'])
1975 self.assertEquals(len(results), 1) 2028 self.assertEquals(len(results), 1)
1976 self.assertEquals(results[0].__class__, 2029 self.assertEquals(results[0].__class__,
1977 presubmit.OutputApi.PresubmitNotifyResult) 2030 presubmit.OutputApi.PresubmitNotifyResult)
1978 # pylint: disable=W0212
1979 self.assertEquals('test_module failed!\nfoo', results[0]._message) 2031 self.assertEquals('test_module failed!\nfoo', results[0]._message)
1980 2032
1981 def testRunPythonUnitTestsFailureCommitting(self): 2033 def testRunPythonUnitTestsFailureCommitting(self):
1982 input_api = self.MockInputApi(None, True) 2034 input_api = self.MockInputApi(None, True)
1983 input_api.subprocess.check_output( 2035 input_api.subprocess.check_output(
1984 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None, 2036 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None,
1985 stderr=input_api.subprocess.STDOUT).AndRaise( 2037 stderr=input_api.subprocess.STDOUT).AndRaise(
1986 input_api.subprocess.CalledProcessError()) 2038 input_api.subprocess.CalledProcessError())
1987 self.mox.ReplayAll() 2039 self.mox.ReplayAll()
1988 2040
1989 results = presubmit_canned_checks.RunPythonUnitTests( 2041 results = presubmit_canned_checks.RunPythonUnitTests(
1990 input_api, presubmit.OutputApi, ['test_module']) 2042 input_api, presubmit.OutputApi, ['test_module'])
1991 self.assertEquals(len(results), 1) 2043 self.assertEquals(len(results), 1)
1992 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) 2044 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError)
1993 # pylint: disable=W0212
1994 self.assertEquals('test_module failed!\nfoo', results[0]._message) 2045 self.assertEquals('test_module failed!\nfoo', results[0]._message)
1995 2046
1996 def testRunPythonUnitTestsSuccess(self): 2047 def testRunPythonUnitTestsSuccess(self):
1997 input_api = self.MockInputApi(None, False) 2048 input_api = self.MockInputApi(None, False)
1998 input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO) 2049 input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO)
1999 input_api.unittest = self.mox.CreateMock(unittest) 2050 input_api.unittest = self.mox.CreateMock(unittest)
2000 input_api.subprocess.check_output( 2051 input_api.subprocess.check_output(
2001 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None, 2052 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None,
2002 stderr=input_api.subprocess.STDOUT) 2053 stderr=input_api.subprocess.STDOUT)
2003 self.mox.ReplayAll() 2054 self.mox.ReplayAll()
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 self.mox.ReplayAll() 2275 self.mox.ReplayAll()
2225 results = presubmit_canned_checks.PanProjectChecks( 2276 results = presubmit_canned_checks.PanProjectChecks(
2226 input_api, 2277 input_api,
2227 presubmit.OutputApi, 2278 presubmit.OutputApi,
2228 excluded_paths=None, 2279 excluded_paths=None,
2229 text_files=None, 2280 text_files=None,
2230 license_header=None, 2281 license_header=None,
2231 project_name=None, 2282 project_name=None,
2232 owners_check=True) 2283 owners_check=True)
2233 self.assertEqual(1, len(results)) 2284 self.assertEqual(1, len(results))
2234 # pylint: disable=W0212
2235 self.assertEqual( 2285 self.assertEqual(
2236 'Found line ending with white spaces in:', results[0]._message) 2286 'Found line ending with white spaces in:', results[0]._message)
2237 self.checkstdout('') 2287 self.checkstdout('')
2238 2288
2239 2289
2240 if __name__ == '__main__': 2290 if __name__ == '__main__':
2241 import unittest 2291 import unittest
2242 unittest.main() 2292 unittest.main()
OLDNEW
« no previous file with comments | « tests/gclient_scm_test.py ('k') | tests/scm_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698