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

Side by Side Diff: tests/gclient_scm_test.py

Issue 3117039: Refactor SubprocessCallAndFilter() to remove positional arguments. (Closed)
Patch Set: Created 10 years, 4 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 | « scm.py ('k') | tests/gclient_utils_test.py » ('j') | 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 gclient_scm.py.""" 6 """Unit tests for gclient_scm.py."""
7 7
8 # Import before super_mox to keep valid references. 8 # Import before super_mox to keep valid references.
9 from os import rename 9 from os import rename
10 from shutil import rmtree 10 from shutil import rmtree
(...skipping 25 matching lines...) Expand all
36 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') 36 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
37 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'SubprocessCall') 37 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'SubprocessCall')
38 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') 38 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory')
39 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo 39 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo
40 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') 40 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture')
41 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo') 41 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo')
42 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') 42 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus')
43 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Run') 43 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Run')
44 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') 44 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList')
45 self._scm_wrapper = gclient_scm.CreateSCM 45 self._scm_wrapper = gclient_scm.CreateSCM
46 gclient_scm.sys.stdout.flush = lambda: None
46 47
47 48
48 class SVNWrapperTestCase(BaseTestCase): 49 class SVNWrapperTestCase(BaseTestCase):
49 class OptionsObject(object): 50 class OptionsObject(object):
50 def __init__(self, test_case, verbose=False, revision=None): 51 def __init__(self, test_case, verbose=False, revision=None):
51 self.verbose = verbose 52 self.verbose = verbose
52 self.revision = revision 53 self.revision = revision
53 self.manually_grab_svn_rev = True 54 self.manually_grab_svn_rev = True
54 self.deps_os = None 55 self.deps_os = None
55 self.force = False 56 self.force = False
56 self.reset = False 57 self.reset = False
57 self.nohooks = False 58 self.nohooks = False
58 59
59 def Options(self, *args, **kwargs): 60 def Options(self, *args, **kwargs):
60 return self.OptionsObject(self, *args, **kwargs) 61 return self.OptionsObject(self, *args, **kwargs)
61 62
62 def setUp(self): 63 def setUp(self):
63 BaseTestCase.setUp(self) 64 BaseTestCase.setUp(self)
64 self.root_dir = self.Dir() 65 self.root_dir = self.Dir()
65 self.args = self.Args() 66 self.args = self.Args()
66 self.url = self.Url() 67 self.url = self.Url()
67 self.relpath = 'asf' 68 self.relpath = 'asf'
68 69
69 def testDir(self): 70 def testDir(self):
70 members = [ 71 members = [
71 'AddAdditionalFlags', 'FullUrlForRelativeUrl', 'RunCommand', 72 'FullUrlForRelativeUrl', 'RunCommand',
72 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', 73 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
73 'revinfo', 'runhooks', 'status', 'update', 74 'revinfo', 'runhooks', 'status', 'update',
74 'updatesingle', 'url', 75 'updatesingle', 'url',
75 ] 76 ]
76 77
77 # If you add a member, be sure to add the relevant test! 78 # If you add a member, be sure to add the relevant test!
78 self.compareMembers(self._scm_wrapper('svn://a'), members) 79 self.compareMembers(self._scm_wrapper('svn://a'), members)
79 80
80 def testUnsupportedSCM(self): 81 def testUnsupportedSCM(self):
81 args = ['gopher://foo', self.root_dir, self.relpath] 82 args = ['gopher://foo', self.root_dir, self.relpath]
(...skipping 29 matching lines...) Expand all
111 'update', options, self.args) 112 'update', options, self.args)
112 113
113 def testRunCommandUnknown(self): 114 def testRunCommandUnknown(self):
114 # TODO(maruel): if ever used. 115 # TODO(maruel): if ever used.
115 pass 116 pass
116 117
117 def testRevertMissing(self): 118 def testRevertMissing(self):
118 options = self.Options(verbose=True) 119 options = self.Options(verbose=True)
119 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 120 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
120 gclient_scm.os.path.isdir(base_path).AndReturn(False) 121 gclient_scm.os.path.isdir(base_path).AndReturn(False)
122 gclient_scm.scm.SVN.Capture(['--version']
123 ).AndReturn('svn, version 1.5.1 (r32289)')
121 # It'll to a checkout instead. 124 # It'll to a checkout instead.
122 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 125 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
123 ).AndReturn(False) 126 ).AndReturn(False)
124 print("\n_____ %s is missing, synching instead" % self.relpath) 127 print("\n_____ %s is missing, synching instead" % self.relpath)
125 # Checkout. 128 # Checkout.
126 gclient_scm.os.path.exists(base_path).AndReturn(False) 129 gclient_scm.os.path.exists(base_path).AndReturn(False)
127 files_list = self.mox.CreateMockAnything() 130 files_list = self.mox.CreateMockAnything()
128 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, 131 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
129 ['checkout', self.url, base_path], 132 ['checkout', self.url, base_path,
133 '--force'],
130 self.root_dir, files_list) 134 self.root_dir, files_list)
131 135
132 self.mox.ReplayAll() 136 self.mox.ReplayAll()
133 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 137 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
134 relpath=self.relpath) 138 relpath=self.relpath)
135 scm.revert(options, self.args, files_list) 139 scm.revert(options, self.args, files_list)
136 140
137 def testRevertNone(self): 141 def testRevertNone(self):
138 options = self.Options(verbose=True) 142 options = self.Options(verbose=True)
139 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 143 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 file_info.root = 'blah' 232 file_info.root = 'blah'
229 file_info.url = self.url 233 file_info.url = self.url
230 file_info.uuid = 'ABC' 234 file_info.uuid = 'ABC'
231 file_info.revision = 42 235 file_info.revision = 42
232 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 236 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
233 ).AndReturn(False) 237 ).AndReturn(False)
234 # Checkout. 238 # Checkout.
235 gclient_scm.os.path.exists(base_path).AndReturn(False) 239 gclient_scm.os.path.exists(base_path).AndReturn(False)
236 files_list = self.mox.CreateMockAnything() 240 files_list = self.mox.CreateMockAnything()
237 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, 241 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
238 ['checkout', self.url, base_path], 242 ['checkout', self.url, base_path,
243 '--force'],
239 self.root_dir, files_list) 244 self.root_dir, files_list)
240 self.mox.ReplayAll() 245 self.mox.ReplayAll()
241 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 246 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
242 relpath=self.relpath) 247 relpath=self.relpath)
243 scm.update(options, (), files_list) 248 scm.update(options, (), files_list)
244 249
245 def testUpdateUpdate(self): 250 def testUpdateUpdate(self):
246 options = self.Options(verbose=True) 251 options = self.Options(verbose=True)
247 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 252 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
248 options.force = True 253 options.force = True
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, 'DEPS') 305 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, 'DEPS')
301 ).AndReturn(False) 306 ).AndReturn(False)
302 307
303 # Verify no locked files. 308 # Verify no locked files.
304 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') 309 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.')
305 ).AndReturn([]) 310 ).AndReturn([])
306 311
307 # When checking out a single file, we issue an svn checkout and svn update. 312 # When checking out a single file, we issue an svn checkout and svn update.
308 files_list = self.mox.CreateMockAnything() 313 files_list = self.mox.CreateMockAnything()
309 gclient_scm.scm.SVN.Run( 314 gclient_scm.scm.SVN.Run(
310 ['checkout', '--depth', 'empty', self.url, base_path], self.root_dir) 315 ['checkout', '--depth', 'empty', self.url, base_path],
316 cwd=self.root_dir)
311 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], 317 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'],
312 gclient_scm.os.path.join(self.root_dir, self.relpath), files_list) 318 gclient_scm.os.path.join(self.root_dir, self.relpath), files_list)
313 319
314 # Now we fall back on scm.update(). 320 # Now we fall back on scm.update().
315 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 321 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
316 ).AndReturn(False) 322 ).AndReturn(False)
317 gclient_scm.os.path.exists(base_path).AndReturn(True) 323 gclient_scm.os.path.exists(base_path).AndReturn(True)
318 gclient_scm.scm.SVN.CaptureInfo( 324 gclient_scm.scm.SVN.CaptureInfo(
319 gclient_scm.os.path.join(base_path, "."), '.' 325 gclient_scm.os.path.join(base_path, "."), '.'
320 ).AndReturn(file_info) 326 ).AndReturn(file_info)
(...skipping 17 matching lines...) Expand all
338 gclient_scm.scm.SVN.current_version = None 344 gclient_scm.scm.SVN.current_version = None
339 gclient_scm.scm.SVN.Capture(['--version'] 345 gclient_scm.scm.SVN.Capture(['--version']
340 ).AndReturn('svn, version 1.4.4 (r25188)') 346 ).AndReturn('svn, version 1.4.4 (r25188)')
341 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path) 347 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path)
342 ).AndReturn(True) 348 ).AndReturn(True)
343 349
344 # When checking out a single file with svn 1.4, we use svn export 350 # When checking out a single file with svn 1.4, we use svn export
345 files_list = self.mox.CreateMockAnything() 351 files_list = self.mox.CreateMockAnything()
346 gclient_scm.scm.SVN.Run( 352 gclient_scm.scm.SVN.Run(
347 ['export', gclient_scm.os.path.join(self.url, 'DEPS'), 353 ['export', gclient_scm.os.path.join(self.url, 'DEPS'),
348 gclient_scm.os.path.join(base_path, 'DEPS')], self.root_dir) 354 gclient_scm.os.path.join(base_path, 'DEPS')],
355 cwd=self.root_dir)
349 356
350 self.mox.ReplayAll() 357 self.mox.ReplayAll()
351 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 358 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
352 relpath=self.relpath) 359 relpath=self.relpath)
353 scm.updatesingle(options, ['DEPS'], files_list) 360 scm.updatesingle(options, ['DEPS'], files_list)
354 361
355 def testUpdateSingleCheckoutSVNUpgrade(self): 362 def testUpdateSingleCheckoutSVNUpgrade(self):
356 options = self.Options(verbose=True) 363 options = self.Options(verbose=True)
357 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 364 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
358 file_info = { 365 file_info = {
(...skipping 13 matching lines...) Expand all
372 ).AndReturn(True) 379 ).AndReturn(True)
373 gclient_scm.os.remove(gclient_scm.os.path.join(base_path, 'DEPS')) 380 gclient_scm.os.remove(gclient_scm.os.path.join(base_path, 'DEPS'))
374 381
375 # Verify no locked files. 382 # Verify no locked files.
376 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') 383 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.')
377 ).AndReturn([]) 384 ).AndReturn([])
378 385
379 # When checking out a single file, we issue an svn checkout and svn update. 386 # When checking out a single file, we issue an svn checkout and svn update.
380 files_list = self.mox.CreateMockAnything() 387 files_list = self.mox.CreateMockAnything()
381 gclient_scm.scm.SVN.Run( 388 gclient_scm.scm.SVN.Run(
382 ['checkout', '--depth', 'empty', self.url, base_path], self.root_dir) 389 ['checkout', '--depth', 'empty', self.url, base_path],
390 cwd=self.root_dir)
383 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], 391 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'],
384 gclient_scm.os.path.join(self.root_dir, self.relpath), files_list) 392 gclient_scm.os.path.join(self.root_dir, self.relpath), files_list)
385 393
386 # Now we fall back on scm.update(). 394 # Now we fall back on scm.update().
387 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 395 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
388 ).AndReturn(False) 396 ).AndReturn(False)
389 gclient_scm.os.path.exists(base_path).AndReturn(True) 397 gclient_scm.os.path.exists(base_path).AndReturn(True)
390 gclient_scm.scm.SVN.CaptureInfo( 398 gclient_scm.scm.SVN.CaptureInfo(
391 gclient_scm.os.path.join(base_path, "."), '.' 399 gclient_scm.os.path.join(base_path, "."), '.'
392 ).AndReturn(file_info) 400 ).AndReturn(file_info)
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 relpath=self.relpath) 760 relpath=self.relpath)
753 rev_info = scm.revinfo(options, (), None) 761 rev_info = scm.revinfo(options, (), None)
754 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') 762 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
755 763
756 764
757 if __name__ == '__main__': 765 if __name__ == '__main__':
758 import unittest 766 import unittest
759 unittest.main() 767 unittest.main()
760 768
761 # vim: ts=2:sw=2:tw=80:et: 769 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « scm.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698