| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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: disable=E1103,E1101,E1120 | 8 # pylint: disable=E1103,E1101,E1120 |
| 9 | 9 |
| 10 import os | 10 import os |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 def testChangeInfoMembers(self): | 180 def testChangeInfoMembers(self): |
| 181 self.mox.ReplayAll() | 181 self.mox.ReplayAll() |
| 182 members = [ | 182 members = [ |
| 183 'CloseIssue', 'Delete', 'Exists', 'GetFiles', 'GetFileNames', | 183 'CloseIssue', 'Delete', 'Exists', 'GetFiles', 'GetFileNames', |
| 184 'GetLocalRoot', 'GetIssueDescription', 'Load', 'MissingTests', | 184 'GetLocalRoot', 'GetIssueDescription', 'Load', 'MissingTests', |
| 185 'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', 'SendToRietveld', | 185 'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', 'SendToRietveld', |
| 186 'SEPARATOR', | 186 'SEPARATOR', |
| 187 'UpdateRietveldDescription', | 187 'UpdateRietveldDescription', |
| 188 'description', 'issue', 'name', | 188 'description', 'issue', 'name', |
| 189 'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld', | 189 'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld', |
| 190 'subject', | |
| 191 ] | 190 ] |
| 192 # If this test fails, you should add the relevant test. | 191 # If this test fails, you should add the relevant test. |
| 193 self.compareMembers( | 192 self.compareMembers( |
| 194 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo', False), | 193 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo', False), |
| 195 members) | 194 members) |
| 196 | 195 |
| 197 def testChangeInfoBase(self): | 196 def testChangeInfoBase(self): |
| 198 files = [('M', 'foo'), ('A', 'bar')] | 197 files = [('M', 'foo'), ('A', 'bar')] |
| 199 self.mox.ReplayAll() | 198 self.mox.ReplayAll() |
| 200 o = gcl.ChangeInfo( | 199 o = gcl.ChangeInfo( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 change_info.rietveld = 'https://my_server' | 304 change_info.rietveld = 'https://my_server' |
| 306 files = [item[1] for item in change_info.files] | 305 files = [item[1] for item in change_info.files] |
| 307 output = presubmit_support.PresubmitOutput() | 306 output = presubmit_support.PresubmitOutput() |
| 308 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 307 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
| 309 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 308 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
| 310 gcl.os.getcwd().AndReturn('somewhere') | 309 gcl.os.getcwd().AndReturn('somewhere') |
| 311 change_info.GetFiles().AndReturn(change_info.files) | 310 change_info.GetFiles().AndReturn(change_info.files) |
| 312 gcl.os.chdir('proout') | 311 gcl.os.chdir('proout') |
| 313 change_info.GetFileNames().AndReturn(files) | 312 change_info.GetFileNames().AndReturn(files) |
| 314 gcl.GenerateDiff(files) | 313 gcl.GenerateDiff(files) |
| 315 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 314 gcl.upload.RealMain( |
| 316 '-r', 'georges@example.com', | 315 [ 'upload.py', '-y', '--server=https://my_server', |
| 317 '--message=\'\'', '--issue=1'], | 316 '-r', 'georges@example.com', '--issue=1'], |
| 318 change_info.patch).AndReturn(("1", | 317 change_info.patch).AndReturn(("1", |
| 319 "2")) | 318 "2")) |
| 320 change_info.GetLocalRoot().AndReturn('proout') | 319 change_info.GetLocalRoot().AndReturn('proout') |
| 321 change_info.Save() | 320 change_info.Save() |
| 322 change_info.PrimeLint() | 321 change_info.PrimeLint() |
| 323 gcl.os.chdir('somewhere') | 322 gcl.os.chdir('somewhere') |
| 324 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" | 323 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" |
| 325 " submit a try. ***") | 324 " submit a try. ***") |
| 326 gcl.sys.stdout.write("\n") | 325 gcl.sys.stdout.write("\n") |
| 327 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) | 326 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) |
| 328 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True | 327 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True |
| (...skipping 22 matching lines...) Expand all Loading... |
| 351 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) | 350 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) |
| 352 gcl.os.write(42, change_info.description) | 351 gcl.os.write(42, change_info.description) |
| 353 gcl.os.close(42) | 352 gcl.os.close(42) |
| 354 gcl.GetCodeReviewSetting('CC_LIST') | 353 gcl.GetCodeReviewSetting('CC_LIST') |
| 355 gcl.GetCodeReviewSetting('PRIVATE') | 354 gcl.GetCodeReviewSetting('PRIVATE') |
| 356 gcl.os.getcwd().AndReturn('somewhere') | 355 gcl.os.getcwd().AndReturn('somewhere') |
| 357 gcl.os.chdir(change_info.GetLocalRoot()) | 356 gcl.os.chdir(change_info.GetLocalRoot()) |
| 358 gcl.GenerateDiff(change_info.GetFileNames()) | 357 gcl.GenerateDiff(change_info.GetFileNames()) |
| 359 gcl.upload.RealMain( | 358 gcl.upload.RealMain( |
| 360 [ 'upload.py', '-y', '--server=https://my_server', '--server=a', | 359 [ 'upload.py', '-y', '--server=https://my_server', '--server=a', |
| 361 '--description_file=descfile', '--message=deescription'], | 360 '--file=descfile'], |
| 362 change_info.patch).AndReturn(("1", "2")) | 361 change_info.patch).AndReturn(("1", "2")) |
| 363 gcl.os.remove('descfile') | 362 gcl.os.remove('descfile') |
| 364 change_info.SendToRietveld("/lint/issue%s_%s" % ('1', '2'), timeout=1) | 363 change_info.SendToRietveld("/lint/issue%s_%s" % ('1', '2'), timeout=1) |
| 365 gcl.os.chdir('somewhere') | 364 gcl.os.chdir('somewhere') |
| 366 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" | 365 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" |
| 367 " submit a try. ***") | 366 " submit a try. ***") |
| 368 gcl.sys.stdout.write("\n") | 367 gcl.sys.stdout.write("\n") |
| 369 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) | 368 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) |
| 370 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True | 369 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True |
| 371 ).AndReturn(change_info) | 370 ).AndReturn(change_info) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 391 output = presubmit_support.PresubmitOutput() | 390 output = presubmit_support.PresubmitOutput() |
| 392 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 391 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
| 393 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) | 392 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) |
| 394 gcl.os.write(42, change_info.description) | 393 gcl.os.write(42, change_info.description) |
| 395 gcl.os.close(42) | 394 gcl.os.close(42) |
| 396 gcl.GetCodeReviewSetting('CC_LIST') | 395 gcl.GetCodeReviewSetting('CC_LIST') |
| 397 gcl.GetCodeReviewSetting('PRIVATE') | 396 gcl.GetCodeReviewSetting('PRIVATE') |
| 398 gcl.os.getcwd().AndReturn('somewhere') | 397 gcl.os.getcwd().AndReturn('somewhere') |
| 399 gcl.os.chdir(change_info.GetLocalRoot()) | 398 gcl.os.chdir(change_info.GetLocalRoot()) |
| 400 gcl.GenerateDiff(change_info.GetFileNames()) | 399 gcl.GenerateDiff(change_info.GetFileNames()) |
| 401 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 400 gcl.upload.RealMain( |
| 402 "--description_file=descfile", | 401 ['upload.py', '-y', '--server=https://my_server', "--file=descfile"], |
| 403 "--message=deescription"], change_info.patch).AndReturn(("1", "2")) | 402 change_info.patch).AndReturn(("1", "2")) |
| 404 gcl.os.remove('descfile') | 403 gcl.os.remove('descfile') |
| 405 change_info.SendToRietveld("/lint/issue%s_%s" % ('1', '2'), timeout=1) | 404 change_info.SendToRietveld("/lint/issue%s_%s" % ('1', '2'), timeout=1) |
| 406 gcl.os.chdir('somewhere') | 405 gcl.os.chdir('somewhere') |
| 407 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" | 406 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" |
| 408 " submit a try. ***") | 407 " submit a try. ***") |
| 409 gcl.sys.stdout.write("\n") | 408 gcl.sys.stdout.write("\n") |
| 410 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) | 409 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) |
| 411 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True | 410 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True |
| 412 ).AndReturn(change_info) | 411 ).AndReturn(change_info) |
| 413 self.mox.ReplayAll() | 412 self.mox.ReplayAll() |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 files = [item[1] for item in change_info.files] | 447 files = [item[1] for item in change_info.files] |
| 449 output = presubmit_support.PresubmitOutput() | 448 output = presubmit_support.PresubmitOutput() |
| 450 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 449 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
| 451 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 450 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
| 452 gcl.os.getcwd().AndReturn('somewhere') | 451 gcl.os.getcwd().AndReturn('somewhere') |
| 453 change_info.GetFiles().AndReturn(change_info.files) | 452 change_info.GetFiles().AndReturn(change_info.files) |
| 454 change_info.GetFileNames().AndReturn(files) | 453 change_info.GetFileNames().AndReturn(files) |
| 455 change_info.GetLocalRoot().AndReturn('proout') | 454 change_info.GetLocalRoot().AndReturn('proout') |
| 456 gcl.os.chdir('proout') | 455 gcl.os.chdir('proout') |
| 457 gcl.GenerateDiff(files) | 456 gcl.GenerateDiff(files) |
| 458 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 457 gcl.upload.RealMain( |
| 459 '--reviewers=georges@example.com', | 458 [ 'upload.py', '-y', '--server=https://my_server', |
| 460 '--message=\'\'', '--issue=1'], | 459 '--reviewers=georges@example.com', '--issue=1'], |
| 461 change_info.patch).AndReturn(("1", "2")) | 460 change_info.patch).AndReturn(("1", "2")) |
| 462 change_info.Save() | 461 change_info.Save() |
| 463 change_info.PrimeLint() | 462 change_info.PrimeLint() |
| 464 gcl.os.chdir('somewhere') | 463 gcl.os.chdir('somewhere') |
| 465 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" | 464 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" |
| 466 " submit a try. ***") | 465 " submit a try. ***") |
| 467 gcl.sys.stdout.write("\n") | 466 gcl.sys.stdout.write("\n") |
| 468 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) | 467 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) |
| 469 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True | 468 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True |
| 470 ).AndReturn(change_info) | 469 ).AndReturn(change_info) |
| 471 self.mox.ReplayAll() | 470 self.mox.ReplayAll() |
| 472 | 471 |
| 473 gcl.CMDupload(['naame']) | 472 gcl.CMDupload(['naame']) |
| 474 self.checkstdout('*** Upload does not submit a try; use gcl try to submit ' | 473 self.checkstdout('*** Upload does not submit a try; use gcl try to submit ' |
| 475 'a try. ***\n' | 474 'a try. ***\n' |
| 476 '*** Upload does not submit a try; use gcl try to submit a try. ***\n') | 475 '*** Upload does not submit a try; use gcl try to submit a try. ***\n') |
| 477 | 476 |
| 478 def testSuggestReviewers(self): | 477 def testSuggestReviewers(self): |
| 479 change_info = self.fakeChange() | 478 change_info = self.fakeChange() |
| 480 output = presubmit_support.PresubmitOutput() | 479 output = presubmit_support.PresubmitOutput() |
| 481 output.reviewers = ['foo@example.com', 'bar@example.com'] | 480 output.reviewers = ['foo@example.com', 'bar@example.com'] |
| 482 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 481 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
| 483 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 482 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
| 484 gcl.os.getcwd().AndReturn('somewhere') | 483 gcl.os.getcwd().AndReturn('somewhere') |
| 485 gcl.os.chdir('proout') | 484 gcl.os.chdir('proout') |
| 486 gcl.GenerateDiff(change_info.GetFileNames()) | 485 gcl.GenerateDiff(change_info.GetFileNames()) |
| 487 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 486 gcl.upload.RealMain( |
| 488 '--reviewers=foo@example.com,bar@example.com', | 487 [ 'upload.py', '-y', '--server=https://my_server', |
| 489 '--message=\'\'', '--issue=1'], | 488 '--reviewers=foo@example.com,bar@example.com', '--issue=1'], |
| 490 change_info.patch).AndReturn(("1", "2")) | 489 change_info.patch).AndReturn(("1", "2")) |
| 491 change_info.Save() | 490 change_info.Save() |
| 492 change_info.PrimeLint() | 491 change_info.PrimeLint() |
| 493 gcl.os.chdir('somewhere') | 492 gcl.os.chdir('somewhere') |
| 494 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" | 493 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" |
| 495 " submit a try. ***") | 494 " submit a try. ***") |
| 496 gcl.sys.stdout.write("\n") | 495 gcl.sys.stdout.write("\n") |
| 497 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) | 496 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) |
| 498 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True | 497 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True |
| 499 ).AndReturn(change_info) | 498 ).AndReturn(change_info) |
| 500 self.mox.ReplayAll() | 499 self.mox.ReplayAll() |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 self.assertEquals(change_info.description, | 584 self.assertEquals(change_info.description, |
| 586 'deescription\n\nCommitted: https://view/12345') | 585 'deescription\n\nCommitted: https://view/12345') |
| 587 # pylint: disable=W0212 | 586 # pylint: disable=W0212 |
| 588 self.assertTrue(change_info._deleted) | 587 self.assertTrue(change_info._deleted) |
| 589 self.assertTrue(change_info._closed) | 588 self.assertTrue(change_info._closed) |
| 590 | 589 |
| 591 | 590 |
| 592 if __name__ == '__main__': | 591 if __name__ == '__main__': |
| 593 import unittest | 592 import unittest |
| 594 unittest.main() | 593 unittest.main() |
| OLD | NEW |