| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
| 7 | 7 |
| 8 import StringIO | 8 import StringIO |
| 9 | 9 |
| 10 # Local imports |
| 10 import presubmit_support as presubmit | 11 import presubmit_support as presubmit |
| 11 # Shortcut. | 12 import presubmit_canned_checks |
| 12 from presubmit_support import presubmit_canned_checks | |
| 13 from super_mox import mox, SuperMoxTestBase | 13 from super_mox import mox, SuperMoxTestBase |
| 14 | 14 |
| 15 | 15 |
| 16 class PresubmitTestsBase(SuperMoxTestBase): | 16 class PresubmitTestsBase(SuperMoxTestBase): |
| 17 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 17 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
| 18 presubmit_text = """ | 18 presubmit_text = """ |
| 19 def CheckChangeOnUpload(input_api, output_api): | 19 def CheckChangeOnUpload(input_api, output_api): |
| 20 if not input_api.change.NOSUCHKEY: | 20 if not input_api.change.NOSUCHKEY: |
| 21 return [output_api.PresubmitError("!!")] | 21 return [output_api.PresubmitError("!!")] |
| 22 elif not input_api.change.REALLYNOSUCHKEY: | 22 elif not input_api.change.REALLYNOSUCHKEY: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 self.fake_root_dir = self.RootDir() | 40 self.fake_root_dir = self.RootDir() |
| 41 # Special mocks. | 41 # Special mocks. |
| 42 def MockAbsPath(f): | 42 def MockAbsPath(f): |
| 43 return f | 43 return f |
| 44 def MockChdir(f): | 44 def MockChdir(f): |
| 45 return None | 45 return None |
| 46 # SuperMoxTestBase already mock these but simplify our life. | 46 # SuperMoxTestBase already mock these but simplify our life. |
| 47 presubmit.os.path.abspath = MockAbsPath | 47 presubmit.os.path.abspath = MockAbsPath |
| 48 presubmit.os.getcwd = self.RootDir | 48 presubmit.os.getcwd = self.RootDir |
| 49 presubmit.os.chdir = MockChdir | 49 presubmit.os.chdir = MockChdir |
| 50 self.mox.StubOutWithMock(presubmit.scm.SVN, 'CaptureInfo') | 50 self.mox.StubOutWithMock(presubmit.gclient_scm, 'CaptureSVNInfo') |
| 51 self.mox.StubOutWithMock(presubmit.scm.SVN, 'GetFileProperty') | 51 self.mox.StubOutWithMock(presubmit.gcl, 'GetSVNFileProperty') |
| 52 # TODO(maruel): Err, small duplication of code here. | |
| 53 self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile') | 52 self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile') |
| 54 self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileRead') | |
| 55 | 53 |
| 56 | 54 |
| 57 class PresubmitUnittest(PresubmitTestsBase): | 55 class PresubmitUnittest(PresubmitTestsBase): |
| 58 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 56 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" |
| 59 def testMembersChanged(self): | 57 def testMembersChanged(self): |
| 60 self.mox.ReplayAll() | 58 self.mox.ReplayAll() |
| 61 members = [ | 59 members = [ |
| 62 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', | 60 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', |
| 63 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange', | 61 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange', |
| 64 'InputApi', 'ListRelevantPresubmitFiles', 'Main', | 62 'InputApi', 'ListRelevantPresubmitFiles', 'Main', |
| 65 'NotImplementedException', 'OutputApi', 'ParseFiles', | 63 'NotImplementedException', 'OutputApi', 'ParseFiles', |
| 66 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs', | 64 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs', |
| 67 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', | 65 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', |
| 68 'exceptions', 'fnmatch', 'gcl', 'gclient_utils', 'glob', | 66 'exceptions', 'fnmatch', 'gcl', 'gclient_scm', 'glob', |
| 69 'logging', 'marshal', 'normpath', 'optparse', 'os', 'pickle', | 67 'logging', 'marshal', 'normpath', 'optparse', 'os', 'pickle', |
| 70 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', 'sys', | 68 'presubmit_canned_checks', 'random', 're', 'subprocess', 'sys', |
| 71 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', | 69 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', |
| 72 'warnings', | 70 'warnings', |
| 73 ] | 71 ] |
| 74 # If this test fails, you should add the relevant test. | 72 # If this test fails, you should add the relevant test. |
| 75 self.compareMembers(presubmit, members) | 73 self.compareMembers(presubmit, members) |
| 76 | 74 |
| 77 def testListRelevantPresubmitFiles(self): | 75 def testListRelevantPresubmitFiles(self): |
| 78 join = presubmit.os.path.join | 76 join = presubmit.os.path.join |
| 79 files = [ | 77 files = [ |
| 80 'blat.cc', | 78 'blat.cc', |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir') | 133 isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir') |
| 136 presubmit.os.path.exists(blat).AndReturn(True) | 134 presubmit.os.path.exists(blat).AndReturn(True) |
| 137 presubmit.os.path.isdir(blat).AndReturn(False) | 135 presubmit.os.path.isdir(blat).AndReturn(False) |
| 138 presubmit.os.path.exists(binary).AndReturn(True) | 136 presubmit.os.path.exists(binary).AndReturn(True) |
| 139 presubmit.os.path.isdir(binary).AndReturn(False) | 137 presubmit.os.path.isdir(binary).AndReturn(False) |
| 140 presubmit.os.path.exists(isdir).AndReturn(True) | 138 presubmit.os.path.exists(isdir).AndReturn(True) |
| 141 presubmit.os.path.isdir(isdir).AndReturn(True) | 139 presubmit.os.path.isdir(isdir).AndReturn(True) |
| 142 presubmit.os.path.exists(notfound).AndReturn(True) | 140 presubmit.os.path.exists(notfound).AndReturn(True) |
| 143 presubmit.os.path.isdir(notfound).AndReturn(False) | 141 presubmit.os.path.isdir(notfound).AndReturn(False) |
| 144 presubmit.os.path.exists(flap).AndReturn(False) | 142 presubmit.os.path.exists(flap).AndReturn(False) |
| 145 presubmit.scm.SVN.CaptureInfo(flap | 143 presubmit.gclient_scm.CaptureSVNInfo(flap |
| 146 ).AndReturn({'Node Kind': 'file'}) | 144 ).AndReturn({'Node Kind': 'file'}) |
| 147 presubmit.scm.SVN.GetFileProperty(blat, 'svn:mime-type').AndReturn(None) | 145 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) |
| 148 presubmit.scm.SVN.GetFileProperty( | 146 presubmit.gcl.GetSVNFileProperty( |
| 149 binary, 'svn:mime-type').AndReturn('application/octet-stream') | 147 binary, 'svn:mime-type').AndReturn('application/octet-stream') |
| 150 presubmit.scm.SVN.GetFileProperty( | 148 presubmit.gcl.GetSVNFileProperty( |
| 151 notfound, 'svn:mime-type').AndReturn('') | 149 notfound, 'svn:mime-type').AndReturn('') |
| 152 presubmit.scm.SVN.CaptureInfo(blat).AndReturn( | 150 presubmit.gclient_scm.CaptureSVNInfo(blat).AndReturn( |
| 153 {'URL': 'svn:/foo/foo/blat.cc'}) | 151 {'URL': 'svn:/foo/foo/blat.cc'}) |
| 154 presubmit.scm.SVN.CaptureInfo(binary).AndReturn( | 152 presubmit.gclient_scm.CaptureSVNInfo(binary).AndReturn( |
| 155 {'URL': 'svn:/foo/binary.dll'}) | 153 {'URL': 'svn:/foo/binary.dll'}) |
| 156 presubmit.scm.SVN.CaptureInfo(notfound).AndReturn({}) | 154 presubmit.gclient_scm.CaptureSVNInfo(notfound).AndReturn({}) |
| 157 presubmit.scm.SVN.CaptureInfo(flap).AndReturn( | 155 presubmit.gclient_scm.CaptureSVNInfo(flap).AndReturn( |
| 158 {'URL': 'svn:/foo/boo/flap.h'}) | 156 {'URL': 'svn:/foo/boo/flap.h'}) |
| 159 presubmit.gclient_utils.FileRead(blat, 'rU').AndReturn('boo!\nahh?') | 157 presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?') |
| 160 presubmit.gclient_utils.FileRead(notfound, 'rU').AndReturn('look!\nthere?') | 158 presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?') |
| 161 self.mox.ReplayAll() | 159 self.mox.ReplayAll() |
| 162 | 160 |
| 163 change = presubmit.SvnChange('mychange', '\n'.join(description_lines), | 161 change = presubmit.SvnChange('mychange', '\n'.join(description_lines), |
| 164 self.fake_root_dir, files, 0, 0) | 162 self.fake_root_dir, files, 0, 0) |
| 165 self.failUnless(change.Name() == 'mychange') | 163 self.failUnless(change.Name() == 'mychange') |
| 166 self.failUnless(change.DescriptionText() == | 164 self.failUnless(change.DescriptionText() == |
| 167 'Hello there\nthis is a change\nand some more regular text') | 165 'Hello there\nthis is a change\nand some more regular text') |
| 168 self.failUnless(change.FullDescriptionText() == | 166 self.failUnless(change.FullDescriptionText() == |
| 169 '\n'.join(description_lines)) | 167 '\n'.join(description_lines)) |
| 170 | 168 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 description_lines = ('Hello there', | 278 description_lines = ('Hello there', |
| 281 'this is a change', | 279 'this is a change', |
| 282 'STORY=http://tracker/123') | 280 'STORY=http://tracker/123') |
| 283 files = [ | 281 files = [ |
| 284 ['A', join('haspresubmit', 'blat.cc')], | 282 ['A', join('haspresubmit', 'blat.cc')], |
| 285 ] | 283 ] |
| 286 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') | 284 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') |
| 287 root_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 285 root_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
| 288 presubmit.os.path.isfile(root_path).AndReturn(True) | 286 presubmit.os.path.isfile(root_path).AndReturn(True) |
| 289 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) | 287 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) |
| 290 presubmit.gclient_utils.FileRead(root_path, | 288 presubmit.gcl.ReadFile(root_path, |
| 291 'rU').AndReturn(self.presubmit_text) | 289 'rU').AndReturn(self.presubmit_text) |
| 292 presubmit.gclient_utils.FileRead(haspresubmit_path, | 290 presubmit.gcl.ReadFile(haspresubmit_path, |
| 293 'rU').AndReturn(self.presubmit_text) | 291 'rU').AndReturn(self.presubmit_text) |
| 294 presubmit.random.randint(0, 4).AndReturn(1) | 292 presubmit.random.randint(0, 4).AndReturn(1) |
| 295 self.mox.ReplayAll() | 293 self.mox.ReplayAll() |
| 296 | 294 |
| 297 output = StringIO.StringIO() | 295 output = StringIO.StringIO() |
| 298 input = StringIO.StringIO('y\n') | 296 input = StringIO.StringIO('y\n') |
| 299 change = presubmit.Change('mychange', '\n'.join(description_lines), | 297 change = presubmit.Change('mychange', '\n'.join(description_lines), |
| 300 self.fake_root_dir, files, 0, 0) | 298 self.fake_root_dir, files, 0, 0) |
| 301 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, | 299 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, |
| 302 None, False)) | 300 None, False)) |
| 303 self.assertEqual(output.getvalue().count('!!'), 2) | 301 self.assertEqual(output.getvalue().count('!!'), 2) |
| 304 | 302 |
| 305 def testDoPresubmitChecksPromptsAfterWarnings(self): | 303 def testDoPresubmitChecksPromptsAfterWarnings(self): |
| 306 join = presubmit.os.path.join | 304 join = presubmit.os.path.join |
| 307 description_lines = ('Hello there', | 305 description_lines = ('Hello there', |
| 308 'this is a change', | 306 'this is a change', |
| 309 'NOSUCHKEY=http://tracker/123') | 307 'NOSUCHKEY=http://tracker/123') |
| 310 files = [ | 308 files = [ |
| 311 ['A', join('haspresubmit', 'blat.cc')], | 309 ['A', join('haspresubmit', 'blat.cc')], |
| 312 ] | 310 ] |
| 313 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 311 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
| 314 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') | 312 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') |
| 315 for i in range(2): | 313 for i in range(2): |
| 316 presubmit.os.path.isfile(presubmit_path).AndReturn(True) | 314 presubmit.os.path.isfile(presubmit_path).AndReturn(True) |
| 317 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) | 315 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) |
| 318 presubmit.gclient_utils.FileRead(presubmit_path, 'rU' | 316 presubmit.gcl.ReadFile(presubmit_path, 'rU' |
| 319 ).AndReturn(self.presubmit_text) | 317 ).AndReturn(self.presubmit_text) |
| 320 presubmit.gclient_utils.FileRead(haspresubmit_path, 'rU' | 318 presubmit.gcl.ReadFile(haspresubmit_path, 'rU' |
| 321 ).AndReturn(self.presubmit_text) | 319 ).AndReturn(self.presubmit_text) |
| 322 presubmit.random.randint(0, 4).AndReturn(1) | 320 presubmit.random.randint(0, 4).AndReturn(1) |
| 323 presubmit.random.randint(0, 4).AndReturn(1) | 321 presubmit.random.randint(0, 4).AndReturn(1) |
| 324 self.mox.ReplayAll() | 322 self.mox.ReplayAll() |
| 325 | 323 |
| 326 output = StringIO.StringIO() | 324 output = StringIO.StringIO() |
| 327 input = StringIO.StringIO('n\n') # say no to the warning | 325 input = StringIO.StringIO('n\n') # say no to the warning |
| 328 change = presubmit.Change('mychange', '\n'.join(description_lines), | 326 change = presubmit.Change('mychange', '\n'.join(description_lines), |
| 329 self.fake_root_dir, files, 0, 0) | 327 self.fake_root_dir, files, 0, 0) |
| 330 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, | 328 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 344 'NOSUCHKEY=http://tracker/123', | 342 'NOSUCHKEY=http://tracker/123', |
| 345 'REALLYNOSUCHKEY=http://tracker/123') | 343 'REALLYNOSUCHKEY=http://tracker/123') |
| 346 files = [ | 344 files = [ |
| 347 ['A', join('haspresubmit', 'blat.cc')], | 345 ['A', join('haspresubmit', 'blat.cc')], |
| 348 ] | 346 ] |
| 349 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 347 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
| 350 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', | 348 haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', |
| 351 'PRESUBMIT.py') | 349 'PRESUBMIT.py') |
| 352 presubmit.os.path.isfile(presubmit_path).AndReturn(True) | 350 presubmit.os.path.isfile(presubmit_path).AndReturn(True) |
| 353 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) | 351 presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) |
| 354 presubmit.gclient_utils.FileRead(presubmit_path, 'rU' | 352 presubmit.gcl.ReadFile(presubmit_path, 'rU').AndReturn(self.presubmit_text) |
| 355 ).AndReturn(self.presubmit_text) | 353 presubmit.gcl.ReadFile(haspresubmit_path, 'rU').AndReturn( |
| 356 presubmit.gclient_utils.FileRead(haspresubmit_path, 'rU').AndReturn( | |
| 357 self.presubmit_text) | 354 self.presubmit_text) |
| 358 presubmit.random.randint(0, 4).AndReturn(1) | 355 presubmit.random.randint(0, 4).AndReturn(1) |
| 359 self.mox.ReplayAll() | 356 self.mox.ReplayAll() |
| 360 | 357 |
| 361 output = StringIO.StringIO() | 358 output = StringIO.StringIO() |
| 362 input = StringIO.StringIO() # should be unused | 359 input = StringIO.StringIO() # should be unused |
| 363 change = presubmit.Change('mychange', '\n'.join(description_lines), | 360 change = presubmit.Change('mychange', '\n'.join(description_lines), |
| 364 self.fake_root_dir, files, 0, 0) | 361 self.fake_root_dir, files, 0, 0) |
| 365 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, | 362 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, |
| 366 None, False)) | 363 None, False)) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 str(result))) | 495 str(result))) |
| 499 | 496 |
| 500 def testDoGetTrySlaves(self): | 497 def testDoGetTrySlaves(self): |
| 501 join = presubmit.os.path.join | 498 join = presubmit.os.path.join |
| 502 filename = 'foo.cc' | 499 filename = 'foo.cc' |
| 503 filename_linux = join('linux_only', 'penguin.cc') | 500 filename_linux = join('linux_only', 'penguin.cc') |
| 504 root_presubmit = join(self.fake_root_dir, 'PRESUBMIT.py') | 501 root_presubmit = join(self.fake_root_dir, 'PRESUBMIT.py') |
| 505 linux_presubmit = join(self.fake_root_dir, 'linux_only', 'PRESUBMIT.py') | 502 linux_presubmit = join(self.fake_root_dir, 'linux_only', 'PRESUBMIT.py') |
| 506 | 503 |
| 507 presubmit.os.path.isfile(root_presubmit).AndReturn(True) | 504 presubmit.os.path.isfile(root_presubmit).AndReturn(True) |
| 508 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( | 505 presubmit.gcl.ReadFile(root_presubmit, 'rU').AndReturn( |
| 509 self.presubmit_tryslave % '["win"]') | 506 self.presubmit_tryslave % '["win"]') |
| 510 | 507 |
| 511 presubmit.os.path.isfile(root_presubmit).AndReturn(True) | 508 presubmit.os.path.isfile(root_presubmit).AndReturn(True) |
| 512 presubmit.os.path.isfile(linux_presubmit).AndReturn(True) | 509 presubmit.os.path.isfile(linux_presubmit).AndReturn(True) |
| 513 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( | 510 presubmit.gcl.ReadFile(root_presubmit, 'rU').AndReturn( |
| 514 self.presubmit_tryslave % '["win"]') | 511 self.presubmit_tryslave % '["win"]') |
| 515 presubmit.gclient_utils.FileRead(linux_presubmit, 'rU').AndReturn( | 512 presubmit.gcl.ReadFile(linux_presubmit, 'rU').AndReturn( |
| 516 self.presubmit_tryslave % '["linux"]') | 513 self.presubmit_tryslave % '["linux"]') |
| 517 self.mox.ReplayAll() | 514 self.mox.ReplayAll() |
| 518 | 515 |
| 519 output = StringIO.StringIO() | 516 output = StringIO.StringIO() |
| 520 self.assertEqual(['win'], | 517 self.assertEqual(['win'], |
| 521 presubmit.DoGetTrySlaves([filename], self.fake_root_dir, | 518 presubmit.DoGetTrySlaves([filename], self.fake_root_dir, |
| 522 None, False, output)) | 519 None, False, output)) |
| 523 output = StringIO.StringIO() | 520 output = StringIO.StringIO() |
| 524 self.assertEqual(['win', 'linux'], | 521 self.assertEqual(['win', 'linux'], |
| 525 presubmit.DoGetTrySlaves([filename, filename_linux], | 522 presubmit.DoGetTrySlaves([filename, filename_linux], |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ', | 558 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ', |
| 562 'is_committing', 'marshal', 'os_path', 'pickle', 'platform', | 559 'is_committing', 'marshal', 'os_path', 'pickle', 'platform', |
| 563 'python_executable', | 560 'python_executable', |
| 564 're', 'subprocess', 'tempfile', 'traceback', 'unittest', 'urllib2', | 561 're', 'subprocess', 'tempfile', 'traceback', 'unittest', 'urllib2', |
| 565 'version', | 562 'version', |
| 566 ] | 563 ] |
| 567 # If this test fails, you should add the relevant test. | 564 # If this test fails, you should add the relevant test. |
| 568 self.compareMembers(presubmit.InputApi(None, './.', False), members) | 565 self.compareMembers(presubmit.InputApi(None, './.', False), members) |
| 569 | 566 |
| 570 def testDepotToLocalPath(self): | 567 def testDepotToLocalPath(self): |
| 571 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn( | 568 presubmit.gclient_scm.CaptureSVNInfo('svn://foo/smurf').AndReturn( |
| 572 {'Path': 'prout'}) | 569 {'Path': 'prout'}) |
| 573 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({}) | 570 presubmit.gclient_scm.CaptureSVNInfo('svn:/foo/notfound/burp').AndReturn({}) |
| 574 self.mox.ReplayAll() | 571 self.mox.ReplayAll() |
| 575 | 572 |
| 576 path = presubmit.InputApi(None, './p', False).DepotToLocalPath( | 573 path = presubmit.InputApi(None, './p', False).DepotToLocalPath( |
| 577 'svn://foo/smurf') | 574 'svn://foo/smurf') |
| 578 self.failUnless(path == 'prout') | 575 self.failUnless(path == 'prout') |
| 579 path = presubmit.InputApi(None, './p', False).DepotToLocalPath( | 576 path = presubmit.InputApi(None, './p', False).DepotToLocalPath( |
| 580 'svn:/foo/notfound/burp') | 577 'svn:/foo/notfound/burp') |
| 581 self.failUnless(path == None) | 578 self.failUnless(path == None) |
| 582 | 579 |
| 583 def testLocalToDepotPath(self): | 580 def testLocalToDepotPath(self): |
| 584 presubmit.scm.SVN.CaptureInfo('smurf').AndReturn({'URL': | 581 presubmit.gclient_scm.CaptureSVNInfo('smurf').AndReturn({'URL': |
| 585 'svn://foo'}) | 582 'svn://foo'}) |
| 586 presubmit.scm.SVN.CaptureInfo('notfound-food').AndReturn({}) | 583 presubmit.gclient_scm.CaptureSVNInfo('notfound-food').AndReturn({}) |
| 587 self.mox.ReplayAll() | 584 self.mox.ReplayAll() |
| 588 | 585 |
| 589 path = presubmit.InputApi(None, './p', False).LocalToDepotPath('smurf') | 586 path = presubmit.InputApi(None, './p', False).LocalToDepotPath('smurf') |
| 590 self.assertEqual(path, 'svn://foo') | 587 self.assertEqual(path, 'svn://foo') |
| 591 path = presubmit.InputApi(None, './p', False).LocalToDepotPath( | 588 path = presubmit.InputApi(None, './p', False).LocalToDepotPath( |
| 592 'notfound-food') | 589 'notfound-food') |
| 593 self.failUnless(path == None) | 590 self.failUnless(path == None) |
| 594 | 591 |
| 595 def testInputApiConstruction(self): | 592 def testInputApiConstruction(self): |
| 596 self.mox.ReplayAll() | 593 self.mox.ReplayAll() |
| (...skipping 30 matching lines...) Expand all Loading... |
| 627 beingdeleted = presubmit.normpath(join(self.fake_root_dir, files[6][1])) | 624 beingdeleted = presubmit.normpath(join(self.fake_root_dir, files[6][1])) |
| 628 notfound = presubmit.normpath(join(self.fake_root_dir, files[7][1])) | 625 notfound = presubmit.normpath(join(self.fake_root_dir, files[7][1])) |
| 629 flap = presubmit.normpath(join(self.fake_root_dir, files[8][1])) | 626 flap = presubmit.normpath(join(self.fake_root_dir, files[8][1])) |
| 630 for i in (blat, readme, binary, weird, another, third_party): | 627 for i in (blat, readme, binary, weird, another, third_party): |
| 631 presubmit.os.path.exists(i).AndReturn(True) | 628 presubmit.os.path.exists(i).AndReturn(True) |
| 632 presubmit.os.path.isdir(i).AndReturn(False) | 629 presubmit.os.path.isdir(i).AndReturn(False) |
| 633 presubmit.os.path.exists(beingdeleted).AndReturn(False) | 630 presubmit.os.path.exists(beingdeleted).AndReturn(False) |
| 634 presubmit.os.path.exists(notfound).AndReturn(False) | 631 presubmit.os.path.exists(notfound).AndReturn(False) |
| 635 presubmit.os.path.exists(flap).AndReturn(True) | 632 presubmit.os.path.exists(flap).AndReturn(True) |
| 636 presubmit.os.path.isdir(flap).AndReturn(False) | 633 presubmit.os.path.isdir(flap).AndReturn(False) |
| 637 presubmit.scm.SVN.CaptureInfo(beingdeleted).AndReturn({}) | 634 presubmit.gclient_scm.CaptureSVNInfo(beingdeleted).AndReturn({}) |
| 638 presubmit.scm.SVN.CaptureInfo(notfound).AndReturn({}) | 635 presubmit.gclient_scm.CaptureSVNInfo(notfound).AndReturn({}) |
| 639 presubmit.scm.SVN.GetFileProperty(blat, 'svn:mime-type').AndReturn(None) | 636 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) |
| 640 presubmit.scm.SVN.GetFileProperty(readme, 'svn:mime-type').AndReturn(None) | 637 presubmit.gcl.GetSVNFileProperty(readme, 'svn:mime-type').AndReturn(None) |
| 641 presubmit.scm.SVN.GetFileProperty(binary, 'svn:mime-type').AndReturn( | 638 presubmit.gcl.GetSVNFileProperty(binary, 'svn:mime-type').AndReturn( |
| 642 'application/octet-stream') | 639 'application/octet-stream') |
| 643 presubmit.scm.SVN.GetFileProperty(weird, 'svn:mime-type').AndReturn(None) | 640 presubmit.gcl.GetSVNFileProperty(weird, 'svn:mime-type').AndReturn(None) |
| 644 presubmit.scm.SVN.GetFileProperty(another, 'svn:mime-type').AndReturn(None) | 641 presubmit.gcl.GetSVNFileProperty(another, 'svn:mime-type').AndReturn(None) |
| 645 presubmit.scm.SVN.GetFileProperty(third_party, 'svn:mime-type' | 642 presubmit.gcl.GetSVNFileProperty(third_party, 'svn:mime-type' |
| 646 ).AndReturn(None) | 643 ).AndReturn(None) |
| 647 presubmit.gclient_utils.FileRead(blat, 'rU' | 644 presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie') |
| 648 ).AndReturn('whatever\ncookie') | 645 presubmit.gcl.ReadFile(another).AndReturn('whatever\ncookie2') |
| 649 presubmit.gclient_utils.FileRead(another, 'rU' | |
| 650 ).AndReturn('whatever\ncookie2') | |
| 651 self.mox.ReplayAll() | 646 self.mox.ReplayAll() |
| 652 | 647 |
| 653 change = presubmit.SvnChange('mychange', '\n'.join(description_lines), | 648 change = presubmit.SvnChange('mychange', '\n'.join(description_lines), |
| 654 self.fake_root_dir, files, 0, 0) | 649 self.fake_root_dir, files, 0, 0) |
| 655 input_api = presubmit.InputApi(change, | 650 input_api = presubmit.InputApi(change, |
| 656 join(self.fake_root_dir, 'foo', | 651 join(self.fake_root_dir, 'foo', |
| 657 'PRESUBMIT.py'), | 652 'PRESUBMIT.py'), |
| 658 False) | 653 False) |
| 659 # Doesn't filter much | 654 # Doesn't filter much |
| 660 got_files = input_api.AffectedFiles() | 655 got_files = input_api.AffectedFiles() |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 self.assertEquals(len(results), len(item[1])) | 747 self.assertEquals(len(results), len(item[1])) |
| 753 | 748 |
| 754 def testCustomFilter(self): | 749 def testCustomFilter(self): |
| 755 def FilterSourceFile(affected_file): | 750 def FilterSourceFile(affected_file): |
| 756 return 'a' in affected_file.LocalPath() | 751 return 'a' in affected_file.LocalPath() |
| 757 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')] | 752 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')] |
| 758 for (action, item) in files: | 753 for (action, item) in files: |
| 759 item = presubmit.os.path.join(self.fake_root_dir, item) | 754 item = presubmit.os.path.join(self.fake_root_dir, item) |
| 760 presubmit.os.path.exists(item).AndReturn(True) | 755 presubmit.os.path.exists(item).AndReturn(True) |
| 761 presubmit.os.path.isdir(item).AndReturn(False) | 756 presubmit.os.path.isdir(item).AndReturn(False) |
| 762 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) | 757 presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) |
| 763 self.mox.ReplayAll() | 758 self.mox.ReplayAll() |
| 764 | 759 |
| 765 change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0, | 760 change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0, |
| 766 0) | 761 0) |
| 767 input_api = presubmit.InputApi(change, | 762 input_api = presubmit.InputApi(change, |
| 768 presubmit.os.path.join(self.fake_root_dir, | 763 presubmit.os.path.join(self.fake_root_dir, |
| 769 'PRESUBMIT.py'), | 764 'PRESUBMIT.py'), |
| 770 False) | 765 False) |
| 771 got_files = input_api.AffectedSourceFiles(FilterSourceFile) | 766 got_files = input_api.AffectedSourceFiles(FilterSourceFile) |
| 772 self.assertEquals(len(got_files), 2) | 767 self.assertEquals(len(got_files), 2) |
| 773 self.assertEquals(got_files[0].LocalPath(), 'eeaee') | 768 self.assertEquals(got_files[0].LocalPath(), 'eeaee') |
| 774 self.assertEquals(got_files[1].LocalPath(), 'eeabee') | 769 self.assertEquals(got_files[1].LocalPath(), 'eeabee') |
| 775 | 770 |
| 776 def testLambdaFilter(self): | 771 def testLambdaFilter(self): |
| 777 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",) | 772 white_list = presubmit.InputApi.DEFAULT_BLACK_LIST + (r".*?a.*?",) |
| 778 black_list = [r".*?b.*?"] | 773 black_list = [r".*?b.*?"] |
| 779 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')] | 774 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')] |
| 780 for (action, item) in files: | 775 for (action, item) in files: |
| 781 item = presubmit.os.path.join(self.fake_root_dir, item) | 776 item = presubmit.os.path.join(self.fake_root_dir, item) |
| 782 presubmit.os.path.exists(item).AndReturn(True) | 777 presubmit.os.path.exists(item).AndReturn(True) |
| 783 presubmit.os.path.isdir(item).AndReturn(False) | 778 presubmit.os.path.isdir(item).AndReturn(False) |
| 784 presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) | 779 presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) |
| 785 self.mox.ReplayAll() | 780 self.mox.ReplayAll() |
| 786 | 781 |
| 787 change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0, | 782 change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0, |
| 788 0) | 783 0) |
| 789 input_api = presubmit.InputApi(change, './PRESUBMIT.py', False) | 784 input_api = presubmit.InputApi(change, './PRESUBMIT.py', False) |
| 790 # Sample usage of overiding the default white and black lists. | 785 # Sample usage of overiding the default white and black lists. |
| 791 got_files = input_api.AffectedSourceFiles( | 786 got_files = input_api.AffectedSourceFiles( |
| 792 lambda x: input_api.FilterSourceFile(x, white_list, black_list)) | 787 lambda x: input_api.FilterSourceFile(x, white_list, black_list)) |
| 793 self.assertEquals(len(got_files), 2) | 788 self.assertEquals(len(got_files), 2) |
| 794 self.assertEquals(got_files[0].LocalPath(), 'eeaee') | 789 self.assertEquals(got_files[0].LocalPath(), 'eeaee') |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 self.mox.ReplayAll() | 845 self.mox.ReplayAll() |
| 851 | 846 |
| 852 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], | 847 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], |
| 853 0, 0) | 848 0, 0) |
| 854 input_api = presubmit.InputApi( | 849 input_api = presubmit.InputApi( |
| 855 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) | 850 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) |
| 856 self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x') | 851 self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x') |
| 857 | 852 |
| 858 def testReadFileStringAccepted(self): | 853 def testReadFileStringAccepted(self): |
| 859 path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo') | 854 path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo') |
| 860 presubmit.gclient_utils.FileRead(path, 'x').AndReturn(None) | 855 presubmit.gcl.ReadFile(path, 'x').AndReturn(None) |
| 861 self.mox.ReplayAll() | 856 self.mox.ReplayAll() |
| 862 | 857 |
| 863 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], | 858 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], |
| 864 0, 0) | 859 0, 0) |
| 865 input_api = presubmit.InputApi( | 860 input_api = presubmit.InputApi( |
| 866 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) | 861 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) |
| 867 input_api.ReadFile(path, 'x') | 862 input_api.ReadFile(path, 'x') |
| 868 | 863 |
| 869 def testReadFileAffectedFileDenied(self): | 864 def testReadFileAffectedFileDenied(self): |
| 870 file = presubmit.AffectedFile('boo', 'M', 'Unrelated') | 865 file = presubmit.AffectedFile('boo', 'M', 'Unrelated') |
| 871 self.mox.ReplayAll() | 866 self.mox.ReplayAll() |
| 872 | 867 |
| 873 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], | 868 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], |
| 874 0, 0) | 869 0, 0) |
| 875 input_api = presubmit.InputApi( | 870 input_api = presubmit.InputApi( |
| 876 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) | 871 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) |
| 877 self.assertRaises(IOError, input_api.ReadFile, file, 'x') | 872 self.assertRaises(IOError, input_api.ReadFile, file, 'x') |
| 878 | 873 |
| 879 def testReadFileAffectedFileAccepted(self): | 874 def testReadFileAffectedFileAccepted(self): |
| 880 file = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir) | 875 file = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir) |
| 881 presubmit.gclient_utils.FileRead(file.AbsoluteLocalPath(), 'x' | 876 presubmit.gcl.ReadFile(file.AbsoluteLocalPath(), 'x').AndReturn(None) |
| 882 ).AndReturn(None) | |
| 883 self.mox.ReplayAll() | 877 self.mox.ReplayAll() |
| 884 | 878 |
| 885 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], | 879 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], |
| 886 0, 0) | 880 0, 0) |
| 887 input_api = presubmit.InputApi( | 881 input_api = presubmit.InputApi( |
| 888 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) | 882 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False) |
| 889 input_api.ReadFile(file, 'x') | 883 input_api.ReadFile(file, 'x') |
| 890 | 884 |
| 891 | 885 |
| 892 class OuputApiUnittest(PresubmitTestsBase): | 886 class OuputApiUnittest(PresubmitTestsBase): |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 'NewContents', 'OldContents', 'OldFileTempPath', 'Property', 'ServerPath', | 948 'NewContents', 'OldContents', 'OldFileTempPath', 'Property', 'ServerPath', |
| 955 ] | 949 ] |
| 956 # If this test fails, you should add the relevant test. | 950 # If this test fails, you should add the relevant test. |
| 957 self.compareMembers(presubmit.AffectedFile('a', 'b'), members) | 951 self.compareMembers(presubmit.AffectedFile('a', 'b'), members) |
| 958 self.compareMembers(presubmit.SvnAffectedFile('a', 'b'), members) | 952 self.compareMembers(presubmit.SvnAffectedFile('a', 'b'), members) |
| 959 | 953 |
| 960 def testAffectedFile(self): | 954 def testAffectedFile(self): |
| 961 path = presubmit.os.path.join('foo', 'blat.cc') | 955 path = presubmit.os.path.join('foo', 'blat.cc') |
| 962 presubmit.os.path.exists(path).AndReturn(True) | 956 presubmit.os.path.exists(path).AndReturn(True) |
| 963 presubmit.os.path.isdir(path).AndReturn(False) | 957 presubmit.os.path.isdir(path).AndReturn(False) |
| 964 presubmit.gclient_utils.FileRead(path, 'rU').AndReturn('whatever\ncookie') | 958 presubmit.gcl.ReadFile(path).AndReturn('whatever\ncookie') |
| 965 presubmit.scm.SVN.CaptureInfo(path).AndReturn( | 959 presubmit.gclient_scm.CaptureSVNInfo(path).AndReturn( |
| 966 {'URL': 'svn:/foo/foo/blat.cc'}) | 960 {'URL': 'svn:/foo/foo/blat.cc'}) |
| 967 self.mox.ReplayAll() | 961 self.mox.ReplayAll() |
| 968 af = presubmit.SvnAffectedFile('foo/blat.cc', 'M') | 962 af = presubmit.SvnAffectedFile('foo/blat.cc', 'M') |
| 969 self.failUnless(af.ServerPath() == 'svn:/foo/foo/blat.cc') | 963 self.failUnless(af.ServerPath() == 'svn:/foo/foo/blat.cc') |
| 970 self.failUnless(af.LocalPath() == presubmit.normpath('foo/blat.cc')) | 964 self.failUnless(af.LocalPath() == presubmit.normpath('foo/blat.cc')) |
| 971 self.failUnless(af.Action() == 'M') | 965 self.failUnless(af.Action() == 'M') |
| 972 self.assertEquals(af.NewContents(), ['whatever', 'cookie']) | 966 self.assertEquals(af.NewContents(), ['whatever', 'cookie']) |
| 973 af = presubmit.AffectedFile('notfound.cc', 'A') | 967 af = presubmit.AffectedFile('notfound.cc', 'A') |
| 974 self.failUnless(af.ServerPath() == '') | 968 self.failUnless(af.ServerPath() == '') |
| 975 | 969 |
| 976 def testProperty(self): | 970 def testProperty(self): |
| 977 presubmit.scm.SVN.GetFileProperty('foo.cc', 'svn:secret-property' | 971 presubmit.gcl.GetSVNFileProperty('foo.cc', 'svn:secret-property' |
| 978 ).AndReturn('secret-property-value') | 972 ).AndReturn('secret-property-value') |
| 979 self.mox.ReplayAll() | 973 self.mox.ReplayAll() |
| 980 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') | 974 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') |
| 981 # Verify cache coherency. | 975 # Verify cache coherency. |
| 982 self.failUnless(affected_file.Property('svn:secret-property') == | 976 self.failUnless(affected_file.Property('svn:secret-property') == |
| 983 'secret-property-value') | 977 'secret-property-value') |
| 984 self.failUnless(affected_file.Property('svn:secret-property') == | 978 self.failUnless(affected_file.Property('svn:secret-property') == |
| 985 'secret-property-value') | 979 'secret-property-value') |
| 986 | 980 |
| 987 def testIsDirectoryNotExists(self): | 981 def testIsDirectoryNotExists(self): |
| 988 presubmit.os.path.exists('foo.cc').AndReturn(False) | 982 presubmit.os.path.exists('foo.cc').AndReturn(False) |
| 989 presubmit.scm.SVN.CaptureInfo('foo.cc').AndReturn({}) | 983 presubmit.gclient_scm.CaptureSVNInfo('foo.cc').AndReturn({}) |
| 990 self.mox.ReplayAll() | 984 self.mox.ReplayAll() |
| 991 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') | 985 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') |
| 992 # Verify cache coherency. | 986 # Verify cache coherency. |
| 993 self.failIf(affected_file.IsDirectory()) | 987 self.failIf(affected_file.IsDirectory()) |
| 994 self.failIf(affected_file.IsDirectory()) | 988 self.failIf(affected_file.IsDirectory()) |
| 995 | 989 |
| 996 def testIsDirectory(self): | 990 def testIsDirectory(self): |
| 997 presubmit.os.path.exists('foo.cc').AndReturn(True) | 991 presubmit.os.path.exists('foo.cc').AndReturn(True) |
| 998 presubmit.os.path.isdir('foo.cc').AndReturn(True) | 992 presubmit.os.path.isdir('foo.cc').AndReturn(True) |
| 999 self.mox.ReplayAll() | 993 self.mox.ReplayAll() |
| 1000 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') | 994 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') |
| 1001 # Verify cache coherency. | 995 # Verify cache coherency. |
| 1002 self.failUnless(affected_file.IsDirectory()) | 996 self.failUnless(affected_file.IsDirectory()) |
| 1003 self.failUnless(affected_file.IsDirectory()) | 997 self.failUnless(affected_file.IsDirectory()) |
| 1004 | 998 |
| 1005 def testIsTextFile(self): | 999 def testIsTextFile(self): |
| 1006 list = [presubmit.SvnAffectedFile('foo/blat.txt', 'M'), | 1000 list = [presubmit.SvnAffectedFile('foo/blat.txt', 'M'), |
| 1007 presubmit.SvnAffectedFile('foo/binary.blob', 'M'), | 1001 presubmit.SvnAffectedFile('foo/binary.blob', 'M'), |
| 1008 presubmit.SvnAffectedFile('blat/flop.txt', 'D')] | 1002 presubmit.SvnAffectedFile('blat/flop.txt', 'D')] |
| 1009 blat = presubmit.os.path.join('foo', 'blat.txt') | 1003 blat = presubmit.os.path.join('foo', 'blat.txt') |
| 1010 blob = presubmit.os.path.join('foo', 'binary.blob') | 1004 blob = presubmit.os.path.join('foo', 'binary.blob') |
| 1011 presubmit.os.path.exists(blat).AndReturn(True) | 1005 presubmit.os.path.exists(blat).AndReturn(True) |
| 1012 presubmit.os.path.isdir(blat).AndReturn(False) | 1006 presubmit.os.path.isdir(blat).AndReturn(False) |
| 1013 presubmit.os.path.exists(blob).AndReturn(True) | 1007 presubmit.os.path.exists(blob).AndReturn(True) |
| 1014 presubmit.os.path.isdir(blob).AndReturn(False) | 1008 presubmit.os.path.isdir(blob).AndReturn(False) |
| 1015 presubmit.scm.SVN.GetFileProperty(blat, 'svn:mime-type').AndReturn(None) | 1009 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) |
| 1016 presubmit.scm.SVN.GetFileProperty(blob, 'svn:mime-type' | 1010 presubmit.gcl.GetSVNFileProperty(blob, 'svn:mime-type' |
| 1017 ).AndReturn('application/octet-stream') | 1011 ).AndReturn('application/octet-stream') |
| 1018 self.mox.ReplayAll() | 1012 self.mox.ReplayAll() |
| 1019 | 1013 |
| 1020 output = filter(lambda x: x.IsTextFile(), list) | 1014 output = filter(lambda x: x.IsTextFile(), list) |
| 1021 self.failUnless(len(output) == 1) | 1015 self.failUnless(len(output) == 1) |
| 1022 self.failUnless(list[0] == output[0]) | 1016 self.failUnless(list[0] == output[0]) |
| 1023 | 1017 |
| 1024 | 1018 |
| 1025 class GclChangeUnittest(PresubmitTestsBase): | 1019 class GclChangeUnittest(PresubmitTestsBase): |
| 1026 def testMembersChanged(self): | 1020 def testMembersChanged(self): |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 change1 = presubmit.SvnChange('mychange', '', self.fake_root_dir, [], 0, 0) | 1144 change1 = presubmit.SvnChange('mychange', '', self.fake_root_dir, [], 0, 0) |
| 1151 input_api1 = self.MockInputApi(change1, committing) | 1145 input_api1 = self.MockInputApi(change1, committing) |
| 1152 files1 = [ | 1146 files1 = [ |
| 1153 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), | 1147 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), |
| 1154 presubmit.SvnAffectedFile('foo.cc', 'M'), | 1148 presubmit.SvnAffectedFile('foo.cc', 'M'), |
| 1155 ] | 1149 ] |
| 1156 if use_source_file: | 1150 if use_source_file: |
| 1157 input_api1.AffectedSourceFiles(None).AndReturn(files1) | 1151 input_api1.AffectedSourceFiles(None).AndReturn(files1) |
| 1158 else: | 1152 else: |
| 1159 input_api1.AffectedFiles(include_deleted=False).AndReturn(files1) | 1153 input_api1.AffectedFiles(include_deleted=False).AndReturn(files1) |
| 1160 presubmit.scm.SVN.GetFileProperty(presubmit.normpath('foo/bar.cc'), | 1154 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), |
| 1161 property).AndReturn(value1) | 1155 property).AndReturn(value1) |
| 1162 presubmit.scm.SVN.GetFileProperty(presubmit.normpath('foo.cc'), | 1156 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), |
| 1163 property).AndReturn(value1) | 1157 property).AndReturn(value1) |
| 1164 change2 = presubmit.SvnChange('mychange', '', self.fake_root_dir, [], 0, 0) | 1158 change2 = presubmit.SvnChange('mychange', '', self.fake_root_dir, [], 0, 0) |
| 1165 input_api2 = self.MockInputApi(change2, committing) | 1159 input_api2 = self.MockInputApi(change2, committing) |
| 1166 files2 = [ | 1160 files2 = [ |
| 1167 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), | 1161 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), |
| 1168 presubmit.SvnAffectedFile('foo.cc', 'M'), | 1162 presubmit.SvnAffectedFile('foo.cc', 'M'), |
| 1169 ] | 1163 ] |
| 1170 if use_source_file: | 1164 if use_source_file: |
| 1171 input_api2.AffectedSourceFiles(None).AndReturn(files2) | 1165 input_api2.AffectedSourceFiles(None).AndReturn(files2) |
| 1172 else: | 1166 else: |
| 1173 input_api2.AffectedFiles(include_deleted=False).AndReturn(files2) | 1167 input_api2.AffectedFiles(include_deleted=False).AndReturn(files2) |
| 1174 | 1168 |
| 1175 presubmit.scm.SVN.GetFileProperty(presubmit.normpath('foo/bar.cc'), | 1169 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), |
| 1176 property).AndReturn(value2) | 1170 property).AndReturn(value2) |
| 1177 presubmit.scm.SVN.GetFileProperty(presubmit.normpath('foo.cc'), | 1171 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), |
| 1178 property).AndReturn(value2) | 1172 property).AndReturn(value2) |
| 1179 self.mox.ReplayAll() | 1173 self.mox.ReplayAll() |
| 1180 | 1174 |
| 1181 results1 = check(input_api1, presubmit.OutputApi, None) | 1175 results1 = check(input_api1, presubmit.OutputApi, None) |
| 1182 self.assertEquals(results1, []) | 1176 self.assertEquals(results1, []) |
| 1183 results2 = check(input_api2, presubmit.OutputApi, None) | 1177 results2 = check(input_api2, presubmit.OutputApi, None) |
| 1184 self.assertEquals(len(results2), 1) | 1178 self.assertEquals(len(results2), 1) |
| 1185 self.assertEquals(results2[0].__class__, error_type) | 1179 self.assertEquals(results2[0].__class__, error_type) |
| 1186 | 1180 |
| 1187 def testCannedCheckChangeHasBugField(self): | 1181 def testCannedCheckChangeHasBugField(self): |
| 1188 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, | 1182 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 self.mox.ReplayAll() | 1454 self.mox.ReplayAll() |
| 1461 | 1455 |
| 1462 results = presubmit_canned_checks.RunPythonUnitTests( | 1456 results = presubmit_canned_checks.RunPythonUnitTests( |
| 1463 input_api, presubmit.OutputApi, ['test_module']) | 1457 input_api, presubmit.OutputApi, ['test_module']) |
| 1464 self.assertEquals(len(results), 0) | 1458 self.assertEquals(len(results), 0) |
| 1465 | 1459 |
| 1466 | 1460 |
| 1467 if __name__ == '__main__': | 1461 if __name__ == '__main__': |
| 1468 import unittest | 1462 import unittest |
| 1469 unittest.main() | 1463 unittest.main() |
| OLD | NEW |