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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 change_info.issue = 1 | 46 change_info.issue = 1 |
47 change_info.patchset = 0 | 47 change_info.patchset = 0 |
48 change_info.description = 'deescription' | 48 change_info.description = 'deescription' |
49 change_info.files = files | 49 change_info.files = files |
50 change_info.GetFiles = lambda : change_info.files | 50 change_info.GetFiles = lambda : change_info.files |
51 change_info.GetIssueDescription = lambda : change_info.description | 51 change_info.GetIssueDescription = lambda : change_info.description |
52 change_info.GetFileNames = lambda : [f[1] for f in change_info.files] | 52 change_info.GetFileNames = lambda : [f[1] for f in change_info.files] |
53 change_info.GetLocalRoot = lambda : 'proout' | 53 change_info.GetLocalRoot = lambda : 'proout' |
54 change_info.patch = None | 54 change_info.patch = None |
55 change_info.rietveld = 'https://my_server' | 55 change_info.rietveld = 'https://my_server' |
| 56 change_info.reviewers = None |
56 change_info._closed = False | 57 change_info._closed = False |
57 change_info._deleted = False | 58 change_info._deleted = False |
58 change_info._comments_added = [] | 59 change_info._comments_added = [] |
59 | 60 |
60 class RpcServer(object): | 61 class RpcServer(object): |
61 # pylint: disable=R0201,W0613 | 62 # pylint: disable=R0201,W0613 |
62 def get_issue_properties(self, issue, messages): | 63 def get_issue_properties(self, issue, messages): |
63 return { 'patchsets': [1337] } | 64 return { 'patchsets': [1337] } |
64 change_info.RpcServer = RpcServer | 65 change_info.RpcServer = RpcServer |
65 | 66 |
(...skipping 28 matching lines...) Expand all Loading... |
94 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings', | 95 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings', |
95 'CMDstatus', 'CMDtry', 'CMDupload', | 96 'CMDstatus', 'CMDtry', 'CMDupload', |
96 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', | 97 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', |
97 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', | 98 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', |
98 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', | 99 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', |
99 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', | 100 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', |
100 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', | 101 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', |
101 'GetCodeReviewSetting', 'GetFilesNotInCL', 'GetInfoDir', | 102 'GetCodeReviewSetting', 'GetFilesNotInCL', 'GetInfoDir', |
102 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', | 103 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', |
103 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', | 104 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', |
104 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', | 105 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 'REVIEWERS_REGEX', |
105 'RunShell', 'RunShellWithReturnCode', 'SVN', | 106 'RunShell', 'RunShellWithReturnCode', 'SVN', |
106 'TryChange', 'UnknownFiles', 'Warn', | 107 'TryChange', 'UnknownFiles', 'Warn', |
107 'attrs', 'breakpad', 'defer_attributes', 'fix_encoding', | 108 'attrs', 'breakpad', 'defer_attributes', 'fix_encoding', |
108 'gclient_utils', 'git_cl', 'json', 'main', 'need_change', | 109 'gclient_utils', 'json', 'main', 'need_change', 'need_change_and_args', |
109 'need_change_and_args', 'no_args', 'optparse', 'os', | 110 'no_args', 'optparse', 'os', 'presubmit_support', 'random', 're', |
110 'presubmit_support', 'random', 're', 'rietveld', | 111 'rietveld', |
111 'string', 'subprocess2', 'sys', 'tempfile', 'time', | 112 'string', 'subprocess2', 'sys', 'tempfile', 'time', |
112 'upload', 'urllib2', | 113 'upload', 'urllib2', |
113 ] | 114 ] |
114 # If this test fails, you should add the relevant test. | 115 # If this test fails, you should add the relevant test. |
115 self.compareMembers(gcl, members) | 116 self.compareMembers(gcl, members) |
116 | 117 |
117 def testIsSVNMoved(self): | 118 def testIsSVNMoved(self): |
118 # TODO(maruel): TEST ME | 119 # TODO(maruel): TEST ME |
119 pass | 120 pass |
120 | 121 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 class ChangeInfoUnittest(GclTestsBase): | 186 class ChangeInfoUnittest(GclTestsBase): |
186 def setUp(self): | 187 def setUp(self): |
187 GclTestsBase.setUp(self) | 188 GclTestsBase.setUp(self) |
188 self.mox.StubOutWithMock(gcl, 'GetChangelistInfoFile') | 189 self.mox.StubOutWithMock(gcl, 'GetChangelistInfoFile') |
189 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') | 190 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') |
190 | 191 |
191 def testChangeInfoMembers(self): | 192 def testChangeInfoMembers(self): |
192 self.mox.ReplayAll() | 193 self.mox.ReplayAll() |
193 members = [ | 194 members = [ |
194 'AddComment', 'CloseIssue', 'Delete', 'Exists', 'GetFiles', | 195 'AddComment', 'CloseIssue', 'Delete', 'Exists', 'GetFiles', |
195 'GetFileNames', 'GetLocalRoot', | 196 'GetFileNames', 'GetLocalRoot', 'GetIssueDescription', 'Load', |
196 'Load', | |
197 'MissingTests', 'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', | 197 'MissingTests', 'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', |
198 'SendToRietveld', | 198 'SendToRietveld', |
199 'SEPARATOR', | 199 'SEPARATOR', |
200 'UpdateDescriptionFromIssue', 'UpdateRietveldDescription', | 200 'UpdateRietveldDescription', |
201 'append_footer', | 201 'description', 'issue', 'name', |
202 'description', 'force_description', 'get_reviewers', 'issue', 'name', | 202 'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld', |
203 'needs_upload', 'patch', 'patchset', 'rietveld', | |
204 ] | 203 ] |
205 # If this test fails, you should add the relevant test. | 204 # If this test fails, you should add the relevant test. |
206 self.compareMembers( | 205 self.compareMembers( |
207 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo', False), | 206 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo', False), |
208 members) | 207 members) |
209 | 208 |
210 def testChangeInfoBase(self): | 209 def testChangeInfoBase(self): |
211 files = [('M', 'foo'), ('A', 'bar')] | 210 files = [('M', 'foo'), ('A', 'bar')] |
212 self.mox.ReplayAll() | 211 self.mox.ReplayAll() |
213 o = gcl.ChangeInfo( | 212 o = gcl.ChangeInfo( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 change_info.files = [('A', 'aa'), ('M', 'bb')] | 315 change_info.files = [('A', 'aa'), ('M', 'bb')] |
317 change_info.patch = None | 316 change_info.patch = None |
318 change_info.rietveld = 'https://my_server' | 317 change_info.rietveld = 'https://my_server' |
319 files = [item[1] for item in change_info.files] | 318 files = [item[1] for item in change_info.files] |
320 output = presubmit_support.PresubmitOutput() | 319 output = presubmit_support.PresubmitOutput() |
321 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 320 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
322 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 321 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
323 gcl.os.getcwd().AndReturn('somewhere') | 322 gcl.os.getcwd().AndReturn('somewhere') |
324 change_info.GetFiles().AndReturn(change_info.files) | 323 change_info.GetFiles().AndReturn(change_info.files) |
325 gcl.os.chdir('proout') | 324 gcl.os.chdir('proout') |
326 change_info.get_reviewers().AndReturn('foo@bar.com') | |
327 change_info.GetFileNames().AndReturn(files) | 325 change_info.GetFileNames().AndReturn(files) |
328 gcl.GenerateDiff(files) | 326 gcl.GenerateDiff(files) |
329 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 327 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', |
330 '-r', 'georges@example.com', | 328 '-r', 'georges@example.com', |
331 '--issue=1', '--title= '], | 329 '--issue=1', '--title= '], |
332 change_info.patch).AndReturn(("1", | 330 change_info.patch).AndReturn(("1", |
333 "2")) | 331 "2")) |
334 change_info.GetLocalRoot().AndReturn('proout') | 332 change_info.GetLocalRoot().AndReturn('proout') |
335 change_info.Save() | 333 change_info.Save() |
336 change_info.PrimeLint() | 334 change_info.PrimeLint() |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 449 |
452 def testReviewersInDescription(self): | 450 def testReviewersInDescription(self): |
453 change_info = self.mox.CreateMock(gcl.ChangeInfo) | 451 change_info = self.mox.CreateMock(gcl.ChangeInfo) |
454 change_info.name = 'naame' | 452 change_info.name = 'naame' |
455 change_info.issue = 1 | 453 change_info.issue = 1 |
456 change_info.patchset = 0 | 454 change_info.patchset = 0 |
457 change_info.description = 'deescription\n\nR=georges@example.com', | 455 change_info.description = 'deescription\n\nR=georges@example.com', |
458 change_info.files = [('A', 'aa'), ('M', 'bb')] | 456 change_info.files = [('A', 'aa'), ('M', 'bb')] |
459 change_info.patch = None | 457 change_info.patch = None |
460 change_info.rietveld = 'https://my_server' | 458 change_info.rietveld = 'https://my_server' |
| 459 change_info.reviewers = ['georges@example.com'] |
461 files = [item[1] for item in change_info.files] | 460 files = [item[1] for item in change_info.files] |
462 output = presubmit_support.PresubmitOutput() | 461 output = presubmit_support.PresubmitOutput() |
463 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 462 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
464 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 463 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
465 gcl.os.getcwd().AndReturn('somewhere') | 464 gcl.os.getcwd().AndReturn('somewhere') |
466 change_info.GetFiles().AndReturn(change_info.files) | 465 change_info.GetFiles().AndReturn(change_info.files) |
467 change_info.get_reviewers().AndReturn(['georges@example.com']) | |
468 change_info.GetFileNames().AndReturn(files) | 466 change_info.GetFileNames().AndReturn(files) |
469 change_info.GetLocalRoot().AndReturn('proout') | 467 change_info.GetLocalRoot().AndReturn('proout') |
470 gcl.os.chdir('proout') | 468 gcl.os.chdir('proout') |
471 gcl.GenerateDiff(files) | 469 gcl.GenerateDiff(files) |
472 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 470 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', |
473 '--reviewers=georges@example.com', | 471 '--reviewers=georges@example.com', |
474 '--issue=1', '--title= '], | 472 '--issue=1', '--title= '], |
475 change_info.patch).AndReturn(("1", "2")) | 473 change_info.patch).AndReturn(("1", "2")) |
476 change_info.Save() | 474 change_info.Save() |
477 change_info.PrimeLint() | 475 change_info.PrimeLint() |
(...skipping 17 matching lines...) Expand all Loading... |
495 output.reviewers = ['foo@example.com', 'bar@example.com'] | 493 output.reviewers = ['foo@example.com', 'bar@example.com'] |
496 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) | 494 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output) |
497 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') | 495 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') |
498 gcl.os.getcwd().AndReturn('somewhere') | 496 gcl.os.getcwd().AndReturn('somewhere') |
499 gcl.os.chdir('proout') | 497 gcl.os.chdir('proout') |
500 gcl.GenerateDiff(change_info.GetFileNames()) | 498 gcl.GenerateDiff(change_info.GetFileNames()) |
501 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', | 499 gcl.upload.RealMain(['upload.py', '-y', '--server=https://my_server', |
502 '--reviewers=foo@example.com,bar@example.com', | 500 '--reviewers=foo@example.com,bar@example.com', |
503 '--issue=1', '--title= '], | 501 '--issue=1', '--title= '], |
504 change_info.patch).AndReturn(("1", "2")) | 502 change_info.patch).AndReturn(("1", "2")) |
505 change_info.get_reviewers().AndReturn(['foo@example.com,bar@example.com']) | |
506 change_info.Save() | 503 change_info.Save() |
507 change_info.PrimeLint() | 504 change_info.PrimeLint() |
508 gcl.os.chdir('somewhere') | 505 gcl.os.chdir('somewhere') |
509 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" | 506 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" |
510 " submit a try. ***") | 507 " submit a try. ***") |
511 gcl.sys.stdout.write("\n") | 508 gcl.sys.stdout.write("\n") |
512 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) | 509 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) |
513 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True | 510 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True |
514 ).AndReturn(change_info) | 511 ).AndReturn(change_info) |
515 self.mox.ReplayAll() | 512 self.mox.ReplayAll() |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 self.mox.ReplayAll() | 565 self.mox.ReplayAll() |
569 | 566 |
570 retval = gcl.CMDcommit(['naame']) | 567 retval = gcl.CMDcommit(['naame']) |
571 | 568 |
572 self.assertEquals(retval, 1) | 569 self.assertEquals(retval, 1) |
573 | 570 |
574 def testPresubmitSucceeds(self): | 571 def testPresubmitSucceeds(self): |
575 change_info = self.mockLoad() | 572 change_info = self.mockLoad() |
576 self.mockPresubmit(change_info, fail=False) | 573 self.mockPresubmit(change_info, fail=False) |
577 self.mockCommit( | 574 self.mockCommit( |
578 change_info, 'deescription\n\nReview URL: https://my_server/1', '') | 575 change_info, 'deescription\nReview URL: https://my_server/1', '') |
579 change_info.UpdateDescriptionFromIssue() | |
580 self.mox.ReplayAll() | 576 self.mox.ReplayAll() |
581 | 577 |
582 retval = gcl.CMDcommit(['naame']) | 578 retval = gcl.CMDcommit(['naame']) |
583 | 579 |
584 self.assertEquals(retval, 0) | 580 self.assertEquals(retval, 0) |
585 self.assertEquals(change_info.description, 'deescription') | 581 self.assertEquals(change_info.description, 'deescription') |
586 # pylint: disable=W0212 | 582 # pylint: disable=W0212 |
587 self.assertFalse(change_info._deleted) | 583 self.assertFalse(change_info._deleted) |
588 self.assertFalse(change_info._closed) | 584 self.assertFalse(change_info._closed) |
589 | 585 |
590 def testPresubmitSucceedsWithCommittedMessage(self): | 586 def testPresubmitSucceedsWithCommittedMessage(self): |
591 change_info = self.mockLoad() | 587 change_info = self.mockLoad() |
592 self.mockPresubmit(change_info, fail=False) | 588 self.mockPresubmit(change_info, fail=False) |
593 self.mockCommit( | 589 self.mockCommit( |
594 change_info, | 590 change_info, 'deescription\nReview URL: https://my_server/1', |
595 'deescription\n\nReview URL: https://my_server/1', | |
596 '\nCommitted revision 12345') | 591 '\nCommitted revision 12345') |
597 change_info.UpdateDescriptionFromIssue() | 592 |
598 change_info.append_footer('Committed: http://view/12345') | |
599 self.mox.ReplayAll() | 593 self.mox.ReplayAll() |
600 | 594 |
601 retval = gcl.CMDcommit(['naame']) | 595 retval = gcl.CMDcommit(['naame']) |
602 self.assertEquals(retval, 0) | 596 self.assertEquals(retval, 0) |
603 # This is because append_footer is mocked. | 597 self.assertEquals(change_info.description, |
604 self.assertEquals(change_info.description, 'deescription') | 598 'deescription\n\nCommitted: http://view/12345') |
605 # pylint: disable=W0212 | 599 # pylint: disable=W0212 |
606 self.assertTrue(change_info._deleted) | 600 self.assertTrue(change_info._deleted) |
607 self.assertTrue(change_info._closed) | 601 self.assertTrue(change_info._closed) |
608 self.assertEqual( | 602 self.assertEqual( |
609 change_info._comments_added, | 603 change_info._comments_added, |
610 ["Committed patchset #1 manually as r12345 (presubmit successful)."]) | 604 ["Committed patchset #1 manually as r12345 (presubmit successful)."]) |
611 | 605 |
612 | 606 |
613 if __name__ == '__main__': | 607 if __name__ == '__main__': |
614 import unittest | 608 import unittest |
615 unittest.main() | 609 unittest.main() |
OLD | NEW |