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

Side by Side Diff: depot_tools/tests/gcl_unittest.py

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

Powered by Google App Engine
This is Rietveld 408576698