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

Side by Side Diff: tests/gcl_unittest.py

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

Powered by Google App Engine
This is Rietveld 408576698