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

Side by Side Diff: tests/gcl_unittest.py

Issue 8344085: Revert r106358 "Get rid of RunShell*() functions in gcl.py to finish the conversion to subprocess2" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 2 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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 import presubmit_support
16 16
17 17
18 class GclTestsBase(SuperMoxTestBase): 18 class GclTestsBase(SuperMoxTestBase):
19 """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."""
20 def setUp(self): 20 def setUp(self):
21 SuperMoxTestBase.setUp(self) 21 SuperMoxTestBase.setUp(self)
22 self.fake_root_dir = self.RootDir() 22 self.fake_root_dir = self.RootDir()
23 self.mox.StubOutWithMock(gcl.subprocess2, 'call') 23 self.mox.StubOutWithMock(gcl, 'RunShell')
24 self.mox.StubOutWithMock(gcl.subprocess2, 'check_output')
25 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo') 24 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo')
26 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot') 25 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot')
27 self.mox.StubOutWithMock(gcl, 'tempfile') 26 self.mox.StubOutWithMock(gcl, 'tempfile')
28 self.mox.StubOutWithMock(gcl.upload, 'RealMain') 27 self.mox.StubOutWithMock(gcl.upload, 'RealMain')
29 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead') 28 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead')
30 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite') 29 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite')
31 gcl.REPOSITORY_ROOT = None 30 gcl.REPOSITORY_ROOT = None
32 self.old_review_settings = gcl.CODEREVIEW_SETTINGS 31 self.old_review_settings = gcl.CODEREVIEW_SETTINGS
33 self.assertEquals(gcl.CODEREVIEW_SETTINGS, {}) 32 self.assertEquals(gcl.CODEREVIEW_SETTINGS, {})
34 33
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 'CMDstatus', 'CMDtry', 'CMDupload', 81 'CMDstatus', 'CMDtry', 'CMDupload',
83 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', 82 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX',
84 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', 83 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks',
85 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', 84 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage',
86 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', 85 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir',
87 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', 86 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir',
88 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', 87 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir',
89 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', 88 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles',
90 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', 89 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG',
91 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 'REVIEWERS_REGEX', 90 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 'REVIEWERS_REGEX',
92 'SVN', 'TryChange', 'UnknownFiles', 'Warn', 91 'RunShell', 'RunShellWithReturnCode', 'SVN',
92 'TryChange', 'UnknownFiles', 'Warn',
93 'attrs', 'breakpad', 'defer_attributes', 'fix_encoding', 93 'attrs', 'breakpad', 'defer_attributes', 'fix_encoding',
94 'gclient_utils', 'json', 'main', 'need_change', 'need_change_and_args', 94 'gclient_utils', 'json', 'main', 'need_change', 'need_change_and_args',
95 'no_args', 'optparse', 'os', 'presubmit_support', 'random', 're', 95 'no_args', 'optparse', 'os', 'presubmit_support', 'random', 're',
96 'rietveld', 96 'rietveld',
97 'string', 'subprocess2', 'sys', 'tempfile', 'time', 97 'string', 'subprocess2', 'sys', 'tempfile', 'time',
98 'upload', 'urllib2', 98 'upload', 'urllib2',
99 ] 99 ]
100 # If this test fails, you should add the relevant test. 100 # If this test fails, you should add the relevant test.
101 self.compareMembers(gcl, members) 101 self.compareMembers(gcl, members)
102 102
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 def mockCommit(self, change_info, commit_message, shell_output): 520 def mockCommit(self, change_info, commit_message, shell_output):
521 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'commit')) 521 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'commit'))
522 gcl.os.write(42, commit_message) 522 gcl.os.write(42, commit_message)
523 gcl.os.close(42) 523 gcl.os.close(42)
524 gcl.tempfile.mkstemp(text=True).AndReturn((43, 'files')) 524 gcl.tempfile.mkstemp(text=True).AndReturn((43, 'files'))
525 gcl.os.write(43, '\n'.join(change_info.GetFileNames())) 525 gcl.os.write(43, '\n'.join(change_info.GetFileNames()))
526 gcl.os.close(43) 526 gcl.os.close(43)
527 527
528 gcl.os.getcwd().AndReturn('prev') 528 gcl.os.getcwd().AndReturn('prev')
529 gcl.os.chdir(change_info.GetLocalRoot()) 529 gcl.os.chdir(change_info.GetLocalRoot())
530 gcl.subprocess2.check_output( 530 gcl.RunShell(['svn', 'commit', '--file=commit', '--targets=files'],
531 ['svn', 'commit', '--file=commit', '--targets=files'] 531 True).AndReturn(shell_output)
532 ).AndReturn(shell_output)
533 if 'Committed' in shell_output: 532 if 'Committed' in shell_output:
534 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting') 533 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting')
535 gcl.GetCodeReviewSetting('VIEW_VC').AndReturn('http://view/') 534 gcl.GetCodeReviewSetting('VIEW_VC').AndReturn('http://view/')
536 535
537 gcl.os.remove('commit') 536 gcl.os.remove('commit')
538 gcl.os.remove('files') 537 gcl.os.remove('files')
539 gcl.os.chdir('prev') 538 gcl.os.chdir('prev')
540 539
541 def testPresubmitEmpty(self): 540 def testPresubmitEmpty(self):
542 self.mockLoad(files=[]) 541 self.mockLoad(files=[])
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 self.assertEquals(retval, 0) 581 self.assertEquals(retval, 0)
583 self.assertEquals(change_info.description, 582 self.assertEquals(change_info.description,
584 'deescription\n\nCommitted: http://view/12345') 583 'deescription\n\nCommitted: http://view/12345')
585 self.assertTrue(change_info._deleted) 584 self.assertTrue(change_info._deleted)
586 self.assertTrue(change_info._closed) 585 self.assertTrue(change_info._closed)
587 586
588 587
589 if __name__ == '__main__': 588 if __name__ == '__main__':
590 import unittest 589 import unittest
591 unittest.main() 590 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