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

Side by Side Diff: tests/gclient_scm_test.py

Issue 133073015: Re-reland r245404 ("If the destination directory doesn't contain the desired repo, delete it") (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Clean up check_output call, print hostname on bots Created 6 years, 10 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 | « scm.py ('k') | tests/gclient_smoketest.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/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 gclient_scm.py.""" 6 """Unit tests for gclient_scm.py."""
7 7
8 # pylint: disable=E1103 8 # pylint: disable=E1103
9 9
10 # Import before super_mox to keep valid references. 10 # Import before super_mox to keep valid references.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 def setUp(self): 95 def setUp(self):
96 BaseTestCase.setUp(self) 96 BaseTestCase.setUp(self)
97 self.url = self.SvnUrl() 97 self.url = self.SvnUrl()
98 98
99 def testDir(self): 99 def testDir(self):
100 members = [ 100 members = [
101 'BinaryExists', 101 'BinaryExists',
102 'FullUrlForRelativeUrl', 102 'FullUrlForRelativeUrl',
103 'GetCheckoutRoot', 103 'GetCheckoutRoot',
104 'GetRemoteURL',
104 'GetRevisionDate', 105 'GetRevisionDate',
105 'GetUsableRev', 106 'GetUsableRev',
106 'Svnversion', 107 'Svnversion',
107 'RunCommand', 108 'RunCommand',
108 'cleanup', 109 'cleanup',
109 'diff', 110 'diff',
110 'name', 111 'name',
111 'pack', 112 'pack',
112 'relpath', 113 'relpath',
113 'revert', 114 'revert',
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 def testGITFakeHttpsUrl(self): 155 def testGITFakeHttpsUrl(self):
155 self.url = 'git+https://foo' 156 self.url = 'git+https://foo'
156 157
157 self.mox.ReplayAll() 158 self.mox.ReplayAll()
158 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 159 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
159 relpath=self.relpath) 160 relpath=self.relpath)
160 self.assertEqual(scm.url, 'https://foo') 161 self.assertEqual(scm.url, 'https://foo')
161 162
162 def testRunCommandException(self): 163 def testRunCommandException(self):
163 options = self.Options(verbose=False) 164 options = self.Options(verbose=False)
164 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 165 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
165 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 166 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
166 167 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
167 self.mox.ReplayAll() 168 self.mox.ReplayAll()
168 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 169 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
169 relpath=self.relpath) 170 relpath=self.relpath)
170 exception = "Unsupported argument(s): %s" % ','.join(self.args) 171 exception = "Unsupported argument(s): %s" % ','.join(self.args)
171 self.assertRaisesError(exception, scm.RunCommand, 172 self.assertRaisesError(exception, scm.RunCommand,
172 'update', options, self.args) 173 'update', options, self.args)
173 174
174 def testRunCommandUnknown(self): 175 def testRunCommandUnknown(self):
175 # TODO(maruel): if ever used. 176 # TODO(maruel): if ever used.
176 pass 177 pass
177 178
178 def testRevertMissing(self): 179 def testRevertMissing(self):
179 options = self.Options(verbose=True) 180 options = self.Options(verbose=True)
180 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) 181 gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
181 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 182 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
182 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 183 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
183 ).AndReturn('1.5.1') 184 ).AndReturn('1.5.1')
184 # It'll to a checkout instead. 185 # It'll to a checkout instead.
185 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
186 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
187 # Checkout. 186 # Checkout.
188 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 187 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
189 parent = gclient_scm.os.path.dirname(self.base_path) 188 parent = gclient_scm.os.path.dirname(self.base_path)
190 gclient_scm.os.path.exists(parent).AndReturn(False) 189 gclient_scm.os.path.exists(parent).AndReturn(False)
191 gclient_scm.os.makedirs(parent) 190 gclient_scm.os.makedirs(parent)
192 gclient_scm.os.path.exists(parent).AndReturn(True) 191 gclient_scm.os.path.exists(parent).AndReturn(True)
193 files_list = self.mox.CreateMockAnything() 192 files_list = self.mox.CreateMockAnything()
194 gclient_scm.scm.SVN.RunAndGetFileList( 193 gclient_scm.scm.SVN.RunAndGetFileList(
195 options.verbose, 194 options.verbose,
196 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], 195 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
197 cwd=self.root_dir, 196 cwd=self.root_dir,
198 file_list=files_list) 197 file_list=files_list)
199 198
200 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 199 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
201 ).AndReturn({'Revision': 100}) 200 ).AndReturn({'Revision': 100})
202 201
203 self.mox.ReplayAll() 202 self.mox.ReplayAll()
204 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 203 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
205 relpath=self.relpath) 204 relpath=self.relpath)
206 scm.revert(options, self.args, files_list) 205 scm.revert(options, self.args, files_list)
207 self.checkstdout( 206 self.checkstdout(
208 ('\n_____ %s is missing, synching instead\n' % self.relpath)) 207 ('\n_____ %s is missing, synching instead\n' % self.relpath))
209 208
210 def testRevertNoDotSvn(self): 209 def testRevertNoDotSvn(self):
211 options = self.Options(verbose=True, force=True) 210 options = self.Options(verbose=True, force=True)
212 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 211 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
213 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) 212 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False)
214 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
215 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
216 # Checkout. 213 # Checkout.
217 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
218 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
219 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 214 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
220 parent = gclient_scm.os.path.dirname(self.base_path) 215 parent = gclient_scm.os.path.dirname(self.base_path)
221 gclient_scm.os.path.exists(parent).AndReturn(False) 216 gclient_scm.os.path.exists(parent).AndReturn(False)
222 gclient_scm.os.makedirs(parent) 217 gclient_scm.os.makedirs(parent)
223 gclient_scm.os.path.exists(parent).AndReturn(True) 218 gclient_scm.os.path.exists(parent).AndReturn(True)
219 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
220 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
224 files_list = self.mox.CreateMockAnything() 221 files_list = self.mox.CreateMockAnything()
225 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 222 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
226 ).AndReturn('1.6') 223 ).AndReturn('1.6')
227 gclient_scm.scm.SVN.RunAndGetFileList( 224 gclient_scm.scm.SVN.RunAndGetFileList(
228 options.verbose, 225 options.verbose,
229 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], 226 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
230 cwd=self.root_dir, 227 cwd=self.root_dir,
231 file_list=files_list) 228 file_list=files_list)
232 gclient_scm.gclient_utils.rmtree(self.base_path) 229 gclient_scm.gclient_utils.rmtree(self.base_path)
233 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 230 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 330
334 # TODO(maruel): TEST REVISIONS!!! 331 # TODO(maruel): TEST REVISIONS!!!
335 # TODO(maruel): TEST RELOCATE!!! 332 # TODO(maruel): TEST RELOCATE!!!
336 def testUpdateCheckout(self): 333 def testUpdateCheckout(self):
337 options = self.Options(verbose=True) 334 options = self.Options(verbose=True)
338 file_info = gclient_scm.gclient_utils.PrintableObject() 335 file_info = gclient_scm.gclient_utils.PrintableObject()
339 file_info.root = 'blah' 336 file_info.root = 'blah'
340 file_info.url = self.url 337 file_info.url = self.url
341 file_info.uuid = 'ABC' 338 file_info.uuid = 'ABC'
342 file_info.revision = 42 339 file_info.revision = 42
343 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
344 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
345 # Checkout. 340 # Checkout.
346 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 341 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
347 parent = gclient_scm.os.path.dirname(self.base_path) 342 parent = gclient_scm.os.path.dirname(self.base_path)
348 gclient_scm.os.path.exists(parent).AndReturn(False) 343 gclient_scm.os.path.exists(parent).AndReturn(False)
349 gclient_scm.os.makedirs(parent) 344 gclient_scm.os.makedirs(parent)
350 gclient_scm.os.path.exists(parent).AndReturn(True) 345 gclient_scm.os.path.exists(parent).AndReturn(True)
351 files_list = self.mox.CreateMockAnything() 346 files_list = self.mox.CreateMockAnything()
352 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 347 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
353 ).AndReturn('1.5.1') 348 ).AndReturn('1.5.1')
354 gclient_scm.scm.SVN.RunAndGetFileList( 349 gclient_scm.scm.SVN.RunAndGetFileList(
(...skipping 11 matching lines...) Expand all
366 def testUpdateUpdate(self): 361 def testUpdateUpdate(self):
367 options = self.Options(verbose=True) 362 options = self.Options(verbose=True)
368 options.force = True 363 options.force = True
369 options.nohooks = False 364 options.nohooks = False
370 file_info = { 365 file_info = {
371 'Repository Root': 'blah', 366 'Repository Root': 'blah',
372 'URL': self.url, 367 'URL': self.url,
373 'UUID': 'ABC', 368 'UUID': 'ABC',
374 'Revision': 42, 369 'Revision': 42,
375 } 370 }
376 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 371 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
377 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 372 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
378 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 373 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
379 374
380 # Checkout or update. 375 # Checkout or update.
381 dotted_path = join(self.base_path, '.') 376 dotted_path = join(self.base_path, '.')
382 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 377 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
383 378
384 # Verify no locked files. 379 # Verify no locked files.
385 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) 380 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([])
386 381
387 # Cheat a bit here. 382 # Cheat a bit here.
(...skipping 24 matching lines...) Expand all
412 407
413 def testUpdateReset(self): 408 def testUpdateReset(self):
414 options = self.Options(verbose=True) 409 options = self.Options(verbose=True)
415 options.reset = True 410 options.reset = True
416 file_info = { 411 file_info = {
417 'Repository Root': 'blah', 412 'Repository Root': 'blah',
418 'URL': self.url, 413 'URL': self.url,
419 'UUID': 'ABC', 414 'UUID': 'ABC',
420 'Revision': 42, 415 'Revision': 42,
421 } 416 }
422 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 417 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
423 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 418 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
424 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 419 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
425 420
426 # Checkout or update. 421 # Checkout or update.
427 dotted_path = join(self.base_path, '.') 422 dotted_path = join(self.base_path, '.')
428 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 423 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
429 424
430 # Create an untracked file and directory. 425 # Create an untracked file and directory.
431 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path 426 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
432 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) 427 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
433 428
(...skipping 14 matching lines...) Expand all
448 options = self.Options(verbose=True) 443 options = self.Options(verbose=True)
449 options.reset = True 444 options.reset = True
450 options.delete_unversioned_trees = True 445 options.delete_unversioned_trees = True
451 446
452 file_info = { 447 file_info = {
453 'Repository Root': 'blah', 448 'Repository Root': 'blah',
454 'URL': self.url, 449 'URL': self.url,
455 'UUID': 'ABC', 450 'UUID': 'ABC',
456 'Revision': 42, 451 'Revision': 42,
457 } 452 }
458 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 453 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
459 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 454 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
460 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 455 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
461 456
462 # Checkout or update. 457 # Checkout or update.
463 dotted_path = join(self.base_path, '.') 458 dotted_path = join(self.base_path, '.')
464 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 459 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
465 460
466 # Create an untracked file and directory. 461 # Create an untracked file and directory.
467 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path 462 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
468 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) 463 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
469 464
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], 509 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path],
515 always=True, 510 always=True,
516 cwd=self.root_dir) 511 cwd=self.root_dir)
517 gclient_scm.scm.SVN.RunAndGetFileList( 512 gclient_scm.scm.SVN.RunAndGetFileList(
518 options.verbose, 513 options.verbose,
519 ['update', 'DEPS', '--ignore-externals'], 514 ['update', 'DEPS', '--ignore-externals'],
520 cwd=self.base_path, 515 cwd=self.base_path,
521 file_list=files_list) 516 file_list=files_list)
522 517
523 # Now we fall back on scm.update(). 518 # Now we fall back on scm.update().
524 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 519 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
525 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 520 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
526 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 521 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
527 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 522 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
528 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 523 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
529 ).AndReturn(file_info) 524 ).AndReturn(file_info)
530 525
531 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 526 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
532 ).AndReturn({'Revision': 100}) 527 ).AndReturn({'Revision': 100})
533 528
534 self.mox.ReplayAll() 529 self.mox.ReplayAll()
535 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 530 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], 579 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path],
585 always=True, 580 always=True,
586 cwd=self.root_dir) 581 cwd=self.root_dir)
587 gclient_scm.scm.SVN.RunAndGetFileList( 582 gclient_scm.scm.SVN.RunAndGetFileList(
588 options.verbose, 583 options.verbose,
589 ['update', 'DEPS', '--ignore-externals'], 584 ['update', 'DEPS', '--ignore-externals'],
590 cwd=self.base_path, 585 cwd=self.base_path,
591 file_list=files_list) 586 file_list=files_list)
592 587
593 # Now we fall back on scm.update(). 588 # Now we fall back on scm.update().
594 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 589 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
595 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 590 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
596 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 591 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
597 gclient_scm.scm.SVN._CaptureInfo( 592 gclient_scm.scm.SVN._CaptureInfo(
598 [], join(self.base_path, ".")).AndReturn(file_info) 593 [], join(self.base_path, ".")).AndReturn(file_info)
599 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 594 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
600 ).AndReturn(file_info) 595 ).AndReturn(file_info)
601 596
602 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 597 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
603 ).AndReturn({'Revision': 100}) 598 ).AndReturn({'Revision': 100})
604 599
605 self.mox.ReplayAll() 600 self.mox.ReplayAll()
(...skipping 14 matching lines...) Expand all
620 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 615 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
621 ).AndReturn('1.5.1') 616 ).AndReturn('1.5.1')
622 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) 617 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True)
623 618
624 # Verify no locked files. 619 # Verify no locked files.
625 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') 620 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.')
626 ).AndReturn([]) 621 ).AndReturn([])
627 622
628 # Now we fall back on scm.update(). 623 # Now we fall back on scm.update().
629 files_list = self.mox.CreateMockAnything() 624 files_list = self.mox.CreateMockAnything()
630 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 625 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
631 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 626 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
632 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 627 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
633 gclient_scm.scm.SVN._CaptureInfo( 628 gclient_scm.scm.SVN._CaptureInfo(
634 [], join(self.base_path, '.')).AndReturn(file_info) 629 [], join(self.base_path, '.')).AndReturn(file_info)
635 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 630 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
636 ).AndReturn(file_info) 631 ).AndReturn(file_info)
637 632
638 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 633 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
639 ).AndReturn({'Revision': 100}) 634 ).AndReturn({'Revision': 100})
640 635
641 self.mox.ReplayAll() 636 self.mox.ReplayAll()
642 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 637 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
643 relpath=self.relpath) 638 relpath=self.relpath)
644 scm.updatesingle(options, ['DEPS'], files_list) 639 scm.updatesingle(options, ['DEPS'], files_list)
645 self.checkstdout('\n_____ %s at 42\n' % self.relpath) 640 self.checkstdout('\n_____ %s at 42\n' % self.relpath)
646 641
647 def testUpdateGit(self): 642 def testUpdateGitSvn(self):
648 options = self.Options(verbose=True) 643 options = self.Options(verbose=True)
649 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') 644 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
650 gclient_scm.os.path.exists(file_path).AndReturn(True) 645 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
646 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True)
651 647
652 self.mox.ReplayAll() 648 self.mox.ReplayAll()
653 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 649 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
654 relpath=self.relpath)
655 file_list = []
656 scm.update(options, self.args, file_list)
657 self.checkstdout(
658 ('________ found .git directory; skipping %s\n' % self.relpath))
659
660 def testUpdateHg(self):
661 options = self.Options(verbose=True)
662 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
663 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True)
664
665 self.mox.ReplayAll()
666 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
667 relpath=self.relpath) 650 relpath=self.relpath)
668 file_list = [] 651 file_list = []
669 scm.update(options, self.args, file_list) 652 scm.update(options, self.args, file_list)
670 self.checkstdout( 653 self.checkstdout(
671 ('________ found .hg directory; skipping %s\n' % self.relpath)) 654 ('________ %s looks like git-svn; skipping.\n' % self.relpath))
672 655
673 def testGetUsableRevSVN(self): 656 def testGetUsableRevSVN(self):
674 # pylint: disable=E1101 657 # pylint: disable=E1101
675 options = self.Options(verbose=True) 658 options = self.Options(verbose=True)
676 659
677 # Mock SVN revision validity checking. 660 # Mock SVN revision validity checking.
678 self.mox.StubOutWithMock( 661 self.mox.StubOutWithMock(
679 gclient_scm.scm.SVN, 'IsValidRevision', True) 662 gclient_scm.scm.SVN, 'IsValidRevision', True)
680 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 1) 663 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 1)
681 ).AndReturn(True) 664 ).AndReturn(True)
682 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 'fake') 665 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 'fake')
683 ).AndReturn(False) 666 ).AndReturn(False)
684 667
685 self.mox.ReplayAll() 668 self.mox.ReplayAll()
686 669
687 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir) 670 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir)
688 # With an SVN checkout, 1 an example of a valid usable rev. 671 # With an SVN checkout, 1 an example of a valid usable rev.
689 self.assertEquals(svn_scm.GetUsableRev(1, options), 1) 672 self.assertEquals(svn_scm.GetUsableRev(1, options), 1)
690 # With an SVN checkout, a fake or unknown rev should raise an excpetion. 673 # With an SVN checkout, a fake or unknown rev should raise an excpetion.
691 self.assertRaises(gclient_scm.gclient_utils.Error, 674 self.assertRaises(gclient_scm.gclient_utils.Error,
692 svn_scm.GetUsableRev, 'fake', options) 675 svn_scm.GetUsableRev, 'fake', options)
693 676
677 def testGetRemoteURL(self):
678 self.mox.UnsetStubs()
679 options = self.Options(verbose=True)
680 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture', True)
681 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
682 relpath=self.relpath)
683
684 if svn_scm.relpath:
685 cwd = os.path.join(svn_scm._root_dir, svn_scm.relpath)
686 else:
687 cwd = svn_scm._root_dir
688
689 gclient_scm.scm.SVN.Capture(['info', '--xml', os.curdir], cwd).AndReturn(
690 """<?xml version="1.0"?>
691 <info>
692 <entry
693 path="."
694 revision="1234"
695 kind="dir">
696 <url>%s</url>
697 <repository>
698 <root>https://dummy.repo.com/svn</root>
699 <uuid>FAKE</uuid>
700 </repository>
701 <wc-info>
702 <schedule>normal</schedule>
703 <depth>infinity</depth>
704 </wc-info>
705 <commit
706 revision="1234">
707 <author>fakedev@chromium.org</author>
708 <date>2013-11-14T15:08:21.757885Z</date>
709 </commit>
710 </entry>
711 </info>
712 """ % svn_scm.url)
713
714 self.mox.ReplayAll()
715
716 self.assertEquals(svn_scm.GetRemoteURL(options), self.url)
717
718
694 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, 719 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils,
695 unittest.TestCase): 720 unittest.TestCase):
696 """This class doesn't use pymox.""" 721 """This class doesn't use pymox."""
697 class OptionsObject(object): 722 class OptionsObject(object):
698 def __init__(self, verbose=False, revision=None): 723 def __init__(self, verbose=False, revision=None):
699 self.verbose = verbose 724 self.verbose = verbose
700 self.revision = revision 725 self.revision = revision
701 self.manually_grab_svn_rev = True 726 self.manually_grab_svn_rev = True
702 self.deps_os = None 727 self.deps_os = None
703 self.force = False 728 self.force = False
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists 854 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists
830 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists 855 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists
831 856
832 857
833 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): 858 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
834 def testDir(self): 859 def testDir(self):
835 members = [ 860 members = [
836 'BinaryExists', 861 'BinaryExists',
837 'FullUrlForRelativeUrl', 862 'FullUrlForRelativeUrl',
838 'GetCheckoutRoot', 863 'GetCheckoutRoot',
864 'GetRemoteURL',
839 'GetRevisionDate', 865 'GetRevisionDate',
840 'GetUsableRev', 866 'GetUsableRev',
841 'RunCommand', 867 'RunCommand',
842 'cache_dir', 868 'cache_dir',
843 'cache_locks', 869 'cache_locks',
844 'cleanup', 870 'cleanup',
845 'diff', 871 'diff',
846 'name', 872 'name',
847 'pack', 873 'pack',
848 'UpdateSubmoduleConfig', 874 'UpdateSubmoduleConfig',
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 1181
1156 def testGetUsableRevGit(self): 1182 def testGetUsableRevGit(self):
1157 # pylint: disable=E1101 1183 # pylint: disable=E1101
1158 options = self.Options(verbose=True) 1184 options = self.Options(verbose=True)
1159 1185
1160 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) 1186 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True)
1161 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 1187 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1
1162 ).AndReturn(True) 1188 ).AndReturn(True)
1163 1189
1164 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) 1190 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
1165 gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( 1191 gclient_scm.scm.GIT.IsGitSvn(self.base_path).MultipleTimes(
1166 ).AndReturn(False) 1192 ).AndReturn(False)
1167 1193
1168 gclient_scm.scm.os.path.isdir(self.base_path).AndReturn(True) 1194 gclient_scm.scm.os.path.isdir(self.base_path).AndReturn(True)
1169 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 1195 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1170 1196
1171 self.mox.ReplayAll() 1197 self.mox.ReplayAll()
1172 1198
1173 git_scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1199 git_scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1174 relpath=self.relpath) 1200 relpath=self.relpath)
1175 # A [fake] git sha1 with a git repo should work (this is in the case that 1201 # A [fake] git sha1 with a git repo should work (this is in the case that
(...skipping 28 matching lines...) Expand all
1204 cwd=self.base_path).AndReturn('blah') 1230 cwd=self.base_path).AndReturn('blah')
1205 gclient_scm.scm.GIT.Capture(['fetch'], cwd=self.base_path) 1231 gclient_scm.scm.GIT.Capture(['fetch'], cwd=self.base_path)
1206 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path) 1232 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path)
1207 error = subprocess2.CalledProcessError(1, 'cmd', '/cwd', 'stdout', 'stderr') 1233 error = subprocess2.CalledProcessError(1, 'cmd', '/cwd', 'stdout', 'stderr')
1208 gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], 1234 gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'],
1209 cwd=self.base_path).AndRaise(error) 1235 cwd=self.base_path).AndRaise(error)
1210 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path) 1236 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path)
1211 gclient_scm.scm.GIT.Capture(['fetch', 'origin'], cwd=self.base_path) 1237 gclient_scm.scm.GIT.Capture(['fetch', 'origin'], cwd=self.base_path)
1212 1238
1213 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) 1239 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
1214 gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( 1240 gclient_scm.scm.GIT.IsGitSvn(self.base_path).MultipleTimes(
1215 ).AndReturn(True) 1241 ).AndReturn(True)
1216 1242
1217 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) 1243 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True)
1218 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 1244 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1
1219 ).AndReturn(True) 1245 ).AndReturn(True)
1220 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=too_big 1246 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=too_big
1221 ).MultipleTimes(2).AndReturn(False) 1247 ).MultipleTimes(2).AndReturn(False)
1222 1248
1223 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) 1249 gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
1224 gclient_scm.os.path.isdir(self.base_path).MultipleTimes().AndReturn(True) 1250 gclient_scm.os.path.isdir(self.base_path).MultipleTimes().AndReturn(True)
(...skipping 19 matching lines...) Expand all
1244 self.assertEquals(git_svn_scm.GetUsableRev('3', options), 1270 self.assertEquals(git_svn_scm.GetUsableRev('3', options),
1245 self.fake_hash_2) 1271 self.fake_hash_2)
1246 # Given a git sha1 with a git-svn checkout, it should be used as is. 1272 # Given a git sha1 with a git-svn checkout, it should be used as is.
1247 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), 1273 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options),
1248 self.fake_hash_1) 1274 self.fake_hash_1)
1249 # We currently check for seemingly valid SVN revisions by assuming 6 digit 1275 # We currently check for seemingly valid SVN revisions by assuming 6 digit
1250 # numbers, so assure that numeric revs >= 1000000 don't work. 1276 # numbers, so assure that numeric revs >= 1000000 don't work.
1251 self.assertRaises(gclient_scm.gclient_utils.Error, 1277 self.assertRaises(gclient_scm.gclient_utils.Error,
1252 git_svn_scm.GetUsableRev, too_big, options) 1278 git_svn_scm.GetUsableRev, too_big, options)
1253 1279
1280 def testGetRemoteURL(self):
1281 options = self.Options(verbose=True)
1282 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Capture', True)
1283 git_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1284 relpath=self.relpath)
1285 git_scm._Capture(['config', 'remote.origin.url'], cwd='/tmp/fake'
1286 ).AndReturn('%s\n' % git_scm.url)
1287
1288 self.mox.ReplayAll()
1289
1290 self.assertEquals(git_scm.GetRemoteURL(options), self.url)
1291
1254 1292
1255 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): 1293 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
1256 def testUpdateUpdate(self): 1294 def testUpdateUpdate(self):
1257 if not self.enabled: 1295 if not self.enabled:
1258 return 1296 return
1259 options = self.Options() 1297 options = self.Options()
1260 expected_file_list = [] 1298 expected_file_list = []
1261 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1299 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1262 relpath=self.relpath) 1300 relpath=self.relpath)
1263 file_list = [] 1301 file_list = []
1264 options.revision = 'unmanaged' 1302 options.revision = 'unmanaged'
1265 scm.update(options, (), file_list) 1303 scm.update(options, (), file_list)
1266 self.assertEquals(file_list, expected_file_list) 1304 self.assertEquals(file_list, expected_file_list)
1267 self.assertEquals(scm.revinfo(options, (), None), 1305 self.assertEquals(scm.revinfo(options, (), None),
1268 '069c602044c5388d2d15c3f875b057c852003458') 1306 '069c602044c5388d2d15c3f875b057c852003458')
1269 self.checkstdout('________ unmanaged solution; skipping .\n') 1307 self.checkstdout('________ unmanaged solution; skipping .\n')
1270 1308
1271 1309
1272 if __name__ == '__main__': 1310 if __name__ == '__main__':
1273 if '-v' in sys.argv: 1311 if '-v' in sys.argv:
1274 logging.basicConfig( 1312 logging.basicConfig(
1275 level=logging.DEBUG, 1313 level=logging.DEBUG,
1276 format='%(asctime).19s %(levelname)s %(filename)s:' 1314 format='%(asctime).19s %(levelname)s %(filename)s:'
1277 '%(lineno)s %(message)s') 1315 '%(lineno)s %(message)s')
1278 unittest.main() 1316 unittest.main()
1279 1317
1280 # vim: ts=2:sw=2:tw=80:et: 1318 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « scm.py ('k') | tests/gclient_smoketest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698