| OLD | NEW |
| 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 gcl.py.""" | 6 """Unit tests for gcl.py.""" |
| 7 | 7 |
| 8 # pylint is too confused. | 8 # pylint is too confused. |
| 9 # pylint: disable=E1101,E1103,E1120,W0212,W0403 | 9 # pylint: disable=E1101,E1103,E1120,W0212,W0403 |
| 10 | 10 |
| 11 # Fixes include path. | 11 # Fixes include path. |
| 12 from super_mox import mox, SuperMoxTestBase | 12 from super_mox import mox, SuperMoxTestBase |
| 13 | 13 |
| 14 import gcl | 14 import gcl |
| 15 import presubmit_support |
| 15 | 16 |
| 16 | 17 |
| 17 class GclTestsBase(SuperMoxTestBase): | 18 class GclTestsBase(SuperMoxTestBase): |
| 18 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 19 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
| 19 def setUp(self): | 20 def setUp(self): |
| 20 SuperMoxTestBase.setUp(self) | 21 SuperMoxTestBase.setUp(self) |
| 21 self.fake_root_dir = self.RootDir() | 22 self.fake_root_dir = self.RootDir() |
| 22 self.mox.StubOutWithMock(gcl, 'RunShell') | 23 self.mox.StubOutWithMock(gcl, 'RunShell') |
| 23 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo') | 24 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo') |
| 24 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot') | 25 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot') |
| (...skipping 24 matching lines...) Expand all Loading... |
| 49 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings', | 50 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings', |
| 50 'CMDstatus', 'CMDtry', 'CMDupload', | 51 'CMDstatus', 'CMDtry', 'CMDupload', |
| 51 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', | 52 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', |
| 52 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', | 53 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', |
| 53 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', | 54 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', |
| 54 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', | 55 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', |
| 55 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', | 56 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', |
| 56 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', | 57 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', |
| 57 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', | 58 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', |
| 58 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', | 59 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', |
| 59 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', | 60 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 'REVIEWERS_REGEX', |
| 60 'RunShell', 'RunShellWithReturnCode', 'SVN', | 61 'RunShell', 'RunShellWithReturnCode', 'SVN', |
| 61 'TryChange', 'UnknownFiles', 'Warn', | 62 'TryChange', 'UnknownFiles', 'Warn', |
| 62 'attrs', 'breakpad', 'defer_attributes', 'gclient_utils', 'getpass', | 63 'attrs', 'breakpad', 'defer_attributes', 'gclient_utils', 'getpass', |
| 63 'json', 'main', 'need_change', 'need_change_and_args', 'no_args', | 64 'json', 'main', 'need_change', 'need_change_and_args', 'no_args', |
| 64 'optparse', 'os', 'random', 're', 'string', 'subprocess', 'sys', | 65 'optparse', 'os', 'owners', 'presubmit_support', 'random', 're', |
| 65 'tempfile', 'time', 'upload', 'urllib2', | 66 'string', 'subprocess', 'suggest_reviewers', 'sys', 'tempfile', 'time', |
| 67 'upload', 'urllib2', |
| 66 ] | 68 ] |
| 67 # If this test fails, you should add the relevant test. | 69 # If this test fails, you should add the relevant test. |
| 68 self.compareMembers(gcl, members) | 70 self.compareMembers(gcl, members) |
| 69 | 71 |
| 70 def testIsSVNMoved(self): | 72 def testIsSVNMoved(self): |
| 71 # TODO(maruel): TEST ME | 73 # TODO(maruel): TEST ME |
| 72 pass | 74 pass |
| 73 | 75 |
| 74 def testGetSVNFileProperty(self): | 76 def testGetSVNFileProperty(self): |
| 75 # TODO(maruel): TEST ME | 77 # TODO(maruel): TEST ME |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') | 144 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') |
| 143 | 145 |
| 144 def testChangeInfoMembers(self): | 146 def testChangeInfoMembers(self): |
| 145 self.mox.ReplayAll() | 147 self.mox.ReplayAll() |
| 146 members = [ | 148 members = [ |
| 147 'CloseIssue', 'Delete', 'Exists', 'GetFiles', 'GetFileNames', | 149 'CloseIssue', 'Delete', 'Exists', 'GetFiles', 'GetFileNames', |
| 148 'GetLocalRoot', 'GetIssueDescription', 'Load', 'MissingTests', | 150 'GetLocalRoot', 'GetIssueDescription', 'Load', 'MissingTests', |
| 149 'NeedsUpload', 'PrimeLint', 'Save', 'SendToRietveld', | 151 'NeedsUpload', 'PrimeLint', 'Save', 'SendToRietveld', |
| 150 'UpdateRietveldDescription', | 152 'UpdateRietveldDescription', |
| 151 'description', 'issue', 'name', | 153 'description', 'issue', 'name', |
| 152 'needs_upload', 'patch', 'patchset', 'rietveld', | 154 'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld', |
| 155 'subject' |
| 153 ] | 156 ] |
| 154 # If this test fails, you should add the relevant test. | 157 # If this test fails, you should add the relevant test. |
| 155 self.compareMembers( | 158 self.compareMembers( |
| 156 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo'), | 159 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo'), |
| 157 members) | 160 members) |
| 158 | 161 |
| 159 def testChangeInfoBase(self): | 162 def testChangeInfoBase(self): |
| 160 files = [('M', 'foo'), ('A', 'bar')] | 163 files = [('M', 'foo'), ('A', 'bar')] |
| 161 self.mox.ReplayAll() | 164 self.mox.ReplayAll() |
| 162 o = gcl.ChangeInfo('name2', '42', '53', 'description2', files, | 165 o = gcl.ChangeInfo('name2', '42', '53', 'description2', files, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 def testNew(self): | 254 def testNew(self): |
| 252 change_info = self.mox.CreateMock(gcl.ChangeInfo) | 255 change_info = self.mox.CreateMock(gcl.ChangeInfo) |
| 253 change_info.name = 'naame' | 256 change_info.name = 'naame' |
| 254 change_info.issue = 1 | 257 change_info.issue = 1 |
| 255 change_info.patchset = 0 | 258 change_info.patchset = 0 |
| 256 change_info.description = 'deescription', | 259 change_info.description = 'deescription', |
| 257 change_info.files = [('A', 'aa'), ('M', 'bb')] | 260 change_info.files = [('A', 'aa'), ('M', 'bb')] |
| 258 change_info.patch = None | 261 change_info.patch = None |
| 259 change_info.rietveld = 'my_server' | 262 change_info.rietveld = 'my_server' |
| 260 files = [item[1] for item in change_info.files] | 263 files = [item[1] for item in change_info.files] |
| 261 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True) | 264 output = presubmit_support.PresubmitOutput() |
| 265 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
| 262 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 266 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
| 263 gcl.os.getcwd().AndReturn('somewhere') | 267 gcl.os.getcwd().AndReturn('somewhere') |
| 264 change_info.GetFiles().AndReturn(change_info.files) | 268 change_info.GetFiles().AndReturn(change_info.files) |
| 265 change_info.GetLocalRoot().AndReturn('proout') | 269 change_info.GetLocalRoot().AndReturn('proout') |
| 266 gcl.os.chdir('proout') | 270 gcl.os.chdir('proout') |
| 267 change_info.GetFileNames().AndReturn(files) | 271 change_info.GetFileNames().AndReturn(files) |
| 268 gcl.GenerateDiff(files) | 272 gcl.GenerateDiff(files) |
| 269 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', | 273 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', |
| 270 '-r', 'georges@example.com', | 274 '-r', 'georges@example.com', |
| 271 '--message=\'\'', '--issue=1'], | 275 '--message=\'\'', '--issue=1'], |
| (...skipping 14 matching lines...) Expand all Loading... |
| 286 self.checkstdout('*** Upload does not submit a try; use gcl try to submit ' | 290 self.checkstdout('*** Upload does not submit a try; use gcl try to submit ' |
| 287 'a try. ***\n' | 291 'a try. ***\n' |
| 288 '*** Upload does not submit a try; use gcl try to submit a try. ***\n') | 292 '*** Upload does not submit a try; use gcl try to submit a try. ***\n') |
| 289 | 293 |
| 290 def testServerOverride(self): | 294 def testServerOverride(self): |
| 291 change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription', | 295 change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription', |
| 292 [('A', 'aa'), ('M', 'bb')], | 296 [('A', 'aa'), ('M', 'bb')], |
| 293 self.fake_root_dir, 'my_server') | 297 self.fake_root_dir, 'my_server') |
| 294 self.mox.StubOutWithMock(change_info, 'Save') | 298 self.mox.StubOutWithMock(change_info, 'Save') |
| 295 change_info.Save() | 299 change_info.Save() |
| 296 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True) | 300 output = presubmit_support.PresubmitOutput() |
| 301 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
| 297 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) | 302 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) |
| 298 gcl.os.write(42, change_info.description) | 303 gcl.os.write(42, change_info.description) |
| 299 gcl.os.close(42) | 304 gcl.os.close(42) |
| 300 gcl.GetCodeReviewSetting('CC_LIST') | 305 gcl.GetCodeReviewSetting('CC_LIST') |
| 301 gcl.GetCodeReviewSetting('PRIVATE') | 306 gcl.GetCodeReviewSetting('PRIVATE') |
| 302 gcl.os.getcwd().AndReturn('somewhere') | 307 gcl.os.getcwd().AndReturn('somewhere') |
| 303 gcl.os.chdir(change_info.GetLocalRoot()) | 308 gcl.os.chdir(change_info.GetLocalRoot()) |
| 304 gcl.GenerateDiff(change_info.GetFileNames()) | 309 gcl.GenerateDiff(change_info.GetFileNames()) |
| 305 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', '--server=a', | 310 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', '--server=a', |
| 306 "--description_file=descfile", | 311 "--description_file=descfile", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 320 self.checkstdout('*** Upload does not submit a try; use gcl try to submit ' | 325 self.checkstdout('*** Upload does not submit a try; use gcl try to submit ' |
| 321 'a try. ***\n' | 326 'a try. ***\n' |
| 322 '*** Upload does not submit a try; use gcl try to submit a try. ***\n') | 327 '*** Upload does not submit a try; use gcl try to submit a try. ***\n') |
| 323 | 328 |
| 324 def testNormal(self): | 329 def testNormal(self): |
| 325 change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription', | 330 change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription', |
| 326 [('A', 'aa'), ('M', 'bb')], | 331 [('A', 'aa'), ('M', 'bb')], |
| 327 self.fake_root_dir, 'my_server') | 332 self.fake_root_dir, 'my_server') |
| 328 self.mox.StubOutWithMock(change_info, 'Save') | 333 self.mox.StubOutWithMock(change_info, 'Save') |
| 329 change_info.Save() | 334 change_info.Save() |
| 330 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True) | 335 output = presubmit_support.PresubmitOutput() |
| 336 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
| 331 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) | 337 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) |
| 332 gcl.os.write(42, change_info.description) | 338 gcl.os.write(42, change_info.description) |
| 333 gcl.os.close(42) | 339 gcl.os.close(42) |
| 334 gcl.GetCodeReviewSetting('CC_LIST') | 340 gcl.GetCodeReviewSetting('CC_LIST') |
| 335 gcl.GetCodeReviewSetting('PRIVATE') | 341 gcl.GetCodeReviewSetting('PRIVATE') |
| 336 gcl.os.getcwd().AndReturn('somewhere') | 342 gcl.os.getcwd().AndReturn('somewhere') |
| 337 gcl.os.chdir(change_info.GetLocalRoot()) | 343 gcl.os.chdir(change_info.GetLocalRoot()) |
| 338 gcl.GenerateDiff(change_info.GetFileNames()) | 344 gcl.GenerateDiff(change_info.GetFileNames()) |
| 339 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', | 345 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', |
| 340 "--description_file=descfile", | 346 "--description_file=descfile", |
| (...skipping 29 matching lines...) Expand all Loading... |
| 370 try: | 376 try: |
| 371 gcl.CMDupload(['naame', '-s', 'foo']) | 377 gcl.CMDupload(['naame', '-s', 'foo']) |
| 372 self.fail() | 378 self.fail() |
| 373 except SystemExit: | 379 except SystemExit: |
| 374 pass | 380 pass |
| 375 | 381 |
| 376 | 382 |
| 377 if __name__ == '__main__': | 383 if __name__ == '__main__': |
| 378 import unittest | 384 import unittest |
| 379 unittest.main() | 385 unittest.main() |
| OLD | NEW |