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

Side by Side Diff: tests/scm_unittest.py

Issue 3104036: Cleanup the code in gclient_utils to standardize on CheckCall nomenclature. (Closed)
Patch Set: Rewrote the patch in part as I had introduced regressions. Removed a lot of dead code Created 10 years, 3 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
« no previous file with comments | « tests/gclient_utils_test.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 scm.py.""" 6 """Unit tests for scm.py."""
7 7
8 from shutil import rmtree 8 from shutil import rmtree
9 import tempfile 9 import tempfile
10 10
(...skipping 11 matching lines...) Expand all
22 except scm.gclient_utils.Error, e: 22 except scm.gclient_utils.Error, e:
23 self.assertEquals(e.args[0], msg) 23 self.assertEquals(e.args[0], msg)
24 else: 24 else:
25 self.fail('%s not raised' % msg) 25 self.fail('%s not raised' % msg)
26 26
27 27
28 class BaseSCMTestCase(BaseTestCase): 28 class BaseSCMTestCase(BaseTestCase):
29 def setUp(self): 29 def setUp(self):
30 BaseTestCase.setUp(self) 30 BaseTestCase.setUp(self)
31 self.mox.StubOutWithMock(scm.gclient_utils, 'Popen') 31 self.mox.StubOutWithMock(scm.gclient_utils, 'Popen')
32 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCall') 32 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilter')
33 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCallAndFilter') 33 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilterAndHeader')
34 34
35 35
36 class RootTestCase(BaseSCMTestCase): 36 class RootTestCase(BaseSCMTestCase):
37 def testMembersChanged(self): 37 def testMembersChanged(self):
38 self.mox.ReplayAll() 38 self.mox.ReplayAll()
39 members = [ 39 members = [
40 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail', 40 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail',
41 'cStringIO', 'gclient_utils', 'glob', 'os', 're', 'shutil', 41 'cStringIO', 'gclient_utils', 'glob', 'os', 're', 'shutil',
42 'subprocess', 'sys', 'tempfile', 'time', 'xml', 42 'subprocess', 'sys', 'tempfile', 'time', 'xml',
43 ] 43 ]
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) 122 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
123 self.fake_root = self.Dir() 123 self.fake_root = self.Dir()
124 124
125 def tearDown(self): 125 def tearDown(self):
126 rmtree(self.root_dir) 126 rmtree(self.root_dir)
127 SuperMoxBaseTestBase.tearDown(self) 127 SuperMoxBaseTestBase.tearDown(self)
128 128
129 def testMembersChanged(self): 129 def testMembersChanged(self):
130 self.mox.ReplayAll() 130 self.mox.ReplayAll()
131 members = [ 131 members = [
132 'COMMAND', 'AssertVersion', 'Capture', 'CaptureStatus', 132 'AssertVersion', 'Capture', 'CaptureStatus',
133 'FetchUpstreamTuple', 133 'FetchUpstreamTuple',
134 'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot', 134 'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot',
135 'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch', 135 'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch',
136 'GetUpstreamBranch', 'IsGitSvn', 'RunAndFilterOutput', 136 'GetUpstreamBranch', 'IsGitSvn', 'ShortBranchName',
137 'ShortBranchName',
138 ] 137 ]
139 # If this test fails, you should add the relevant test. 138 # If this test fails, you should add the relevant test.
140 self.compareMembers(scm.GIT, members) 139 self.compareMembers(scm.GIT, members)
141 140
142 def testGetEmail(self): 141 def testGetEmail(self):
143 self.mox.StubOutWithMock(scm.GIT, 'Capture') 142 self.mox.StubOutWithMock(scm.GIT, 'Capture')
144 scm.GIT.Capture(['config', 'user.email'], self.fake_root, error_ok=True 143 scm.GIT.Capture(['config', 'user.email'], self.fake_root, error_ok=True
145 ).AndReturn(['mini@me.com', '']) 144 ).AndReturn(['mini@me.com', ''])
146 self.mox.ReplayAll() 145 self.mox.ReplayAll()
147 self.assertEqual(scm.GIT.GetEmail(self.fake_root), 'mini@me.com') 146 self.assertEqual(scm.GIT.GetEmail(self.fake_root), 'mini@me.com')
148 147
149 148
150 class SVNTestCase(BaseSCMTestCase): 149 class SVNTestCase(BaseSCMTestCase):
151 def setUp(self): 150 def setUp(self):
152 BaseSCMTestCase.setUp(self) 151 BaseSCMTestCase.setUp(self)
153 self.root_dir = self.Dir() 152 self.root_dir = self.Dir()
154 self.args = self.Args() 153 self.args = self.Args()
155 self.url = self.Url() 154 self.url = self.Url()
156 self.relpath = 'asf' 155 self.relpath = 'asf'
157 156
158 def testMembersChanged(self): 157 def testMembersChanged(self):
159 self.mox.ReplayAll() 158 self.mox.ReplayAll()
160 members = [ 159 members = [
161 'COMMAND', 'AssertVersion', 'Capture', 'CaptureBaseRevision', 160 'AssertVersion', 'Capture', 'CaptureBaseRevision',
162 'CaptureHeadRevision', 'CaptureInfo', 'CaptureStatus', 161 'CaptureHeadRevision', 'CaptureInfo', 'CaptureStatus',
163 'current_version', 'DiffItem', 'GenerateDiff', 162 'current_version', 'DiffItem', 'GenerateDiff',
164 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved', 163 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved',
165 'IsMovedInfo', 'ReadSimpleAuth', 'Run', 'RunAndFilterOutput', 164 'IsMovedInfo', 'ReadSimpleAuth', 'Run', 'RunAndGetFileList',
166 'RunAndGetFileList',
167 ] 165 ]
168 # If this test fails, you should add the relevant test. 166 # If this test fails, you should add the relevant test.
169 self.compareMembers(scm.SVN, members) 167 self.compareMembers(scm.SVN, members)
170 168
171 def testGetCheckoutRoot(self): 169 def testGetCheckoutRoot(self):
172 self.mox.StubOutWithMock(scm.SVN, 'CaptureInfo') 170 self.mox.StubOutWithMock(scm.SVN, 'CaptureInfo')
173 self.mox.StubOutWithMock(scm, 'GetCasedPath') 171 self.mox.StubOutWithMock(scm, 'GetCasedPath')
174 scm.os.path.abspath(self.root_dir + 'x').AndReturn(self.root_dir) 172 scm.os.path.abspath(self.root_dir + 'x').AndReturn(self.root_dir)
175 scm.GetCasedPath(self.root_dir).AndReturn(self.root_dir) 173 scm.GetCasedPath(self.root_dir).AndReturn(self.root_dir)
176 result1 = { "Repository Root": "Some root" } 174 result1 = { "Repository Root": "Some root" }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 ('? ', 'unversionned_file.txt'), 306 ('? ', 'unversionned_file.txt'),
309 ('M ', 'build\\internal\\essential.vsprops'), 307 ('M ', 'build\\internal\\essential.vsprops'),
310 ('A + ', 'chrome\\app\\d'), 308 ('A + ', 'chrome\\app\\d'),
311 ('MM ', 'chrome\\app\\DEPS'), 309 ('MM ', 'chrome\\app\\DEPS'),
312 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), 310 ('C ', 'scripts\\master\\factory\\gclient_factory.py'),
313 ] 311 ]
314 self.assertEquals(sorted(info), sorted(expected)) 312 self.assertEquals(sorted(info), sorted(expected))
315 313
316 def testRun(self): 314 def testRun(self):
317 param2 = 'bleh' 315 param2 = 'bleh'
318 scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], 316 scm.gclient_utils.CheckCallAndFilterAndHeader(
319 cwd=param2).AndReturn(None) 317 ['svn', 'foo', 'bar'], cwd=param2,
318 always=True).AndReturn(None)
320 self.mox.ReplayAll() 319 self.mox.ReplayAll()
321 scm.SVN.Run(['foo', 'bar'], cwd=param2) 320 scm.SVN.Run(['foo', 'bar'], cwd=param2)
322 321
323 def testCaptureStatusEmpty(self): 322 def testCaptureStatusEmpty(self):
324 text = r"""<?xml version="1.0"?> 323 text = r"""<?xml version="1.0"?>
325 <status> 324 <status>
326 <target 325 <target
327 path="perf"> 326 path="perf">
328 </target> 327 </target>
329 </status>""" 328 </status>"""
330 proc = self.mox.CreateMockAnything() 329 proc = self.mox.CreateMockAnything()
331 scm.gclient_utils.Popen(['svn', 'status', '--xml'], 330 scm.gclient_utils.Popen(['svn', 'status', '--xml'],
332 cwd=None, 331 cwd=None,
333 stderr=None, 332 stderr=None,
334 stdout=scm.subprocess.PIPE).AndReturn(proc) 333 stdout=scm.subprocess.PIPE).AndReturn(proc)
335 proc.communicate().AndReturn((text, 0)) 334 proc.communicate().AndReturn((text, 0))
336 self.mox.ReplayAll() 335 self.mox.ReplayAll()
337 info = scm.SVN.CaptureStatus(None) 336 info = scm.SVN.CaptureStatus(None)
338 self.assertEquals(info, []) 337 self.assertEquals(info, [])
339 338
340 339
341 if __name__ == '__main__': 340 if __name__ == '__main__':
342 import unittest 341 import unittest
343 unittest.main() 342 unittest.main()
344 343
345 # vim: ts=2:sw=2:tw=80:et: 344 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « tests/gclient_utils_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698