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

Side by Side Diff: tests/gclient_scm_test.py

Issue 189913020: gclient: print a warning if a dep would get deleted or moved in the future (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: rebase+fix Created 6 years, 8 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 | « testing_support/fake_repos.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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 def testGITFakeHttpsUrl(self): 143 def testGITFakeHttpsUrl(self):
144 self.url = 'git+https://foo' 144 self.url = 'git+https://foo'
145 145
146 self.mox.ReplayAll() 146 self.mox.ReplayAll()
147 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 147 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
148 relpath=self.relpath) 148 relpath=self.relpath)
149 self.assertEqual(scm.url, 'https://foo') 149 self.assertEqual(scm.url, 'https://foo')
150 150
151 def testRunCommandException(self): 151 def testRunCommandException(self):
152 options = self.Options(verbose=False) 152 options = self.Options(verbose=False)
153 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
154 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 153 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
155 154
156 self.mox.ReplayAll() 155 self.mox.ReplayAll()
157 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 156 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
158 relpath=self.relpath) 157 relpath=self.relpath)
159 exception = "Unsupported argument(s): %s" % ','.join(self.args) 158 exception = "Unsupported argument(s): %s" % ','.join(self.args)
160 self.assertRaisesError(exception, scm.RunCommand, 159 self.assertRaisesError(exception, scm.RunCommand,
161 'update', options, self.args) 160 'update', options, self.args)
162 161
163 def testRunCommandUnknown(self): 162 def testRunCommandUnknown(self):
164 # TODO(maruel): if ever used. 163 # TODO(maruel): if ever used.
165 pass 164 pass
166 165
167 def testRevertMissing(self): 166 def testRevertMissing(self):
168 options = self.Options(verbose=True) 167 options = self.Options(verbose=True)
169 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) 168 gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
170 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 169 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
171 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 170 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
172 ).AndReturn('1.5.1') 171 ).AndReturn('1.5.1')
173 # It'll to a checkout instead. 172 # It'll to a checkout instead.
174 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
175 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 173 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
176 # Checkout. 174 # Checkout.
177 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 175 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
178 parent = gclient_scm.os.path.dirname(self.base_path) 176 parent = gclient_scm.os.path.dirname(self.base_path)
179 gclient_scm.os.path.exists(parent).AndReturn(False) 177 gclient_scm.os.path.exists(parent).AndReturn(False)
180 gclient_scm.os.makedirs(parent) 178 gclient_scm.os.makedirs(parent)
181 gclient_scm.os.path.exists(parent).AndReturn(True) 179 gclient_scm.os.path.exists(parent).AndReturn(True)
182 files_list = self.mox.CreateMockAnything() 180 files_list = self.mox.CreateMockAnything()
183 gclient_scm.scm.SVN.RunAndGetFileList( 181 gclient_scm.scm.SVN.RunAndGetFileList(
184 options.verbose, 182 options.verbose,
(...skipping 11 matching lines...) Expand all
196 self.checkstdout( 194 self.checkstdout(
197 ('_____ %s is missing, synching instead\n' % self.relpath)) 195 ('_____ %s is missing, synching instead\n' % self.relpath))
198 196
199 def testRevertNoDotSvn(self): 197 def testRevertNoDotSvn(self):
200 options = self.Options(verbose=True, force=True) 198 options = self.Options(verbose=True, force=True)
201 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 199 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
202 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) 200 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False)
203 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) 201 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
204 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) 202 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
205 # Checkout. 203 # Checkout.
206 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
207 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 204 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
208 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 205 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
209 parent = gclient_scm.os.path.dirname(self.base_path) 206 parent = gclient_scm.os.path.dirname(self.base_path)
210 gclient_scm.os.path.exists(parent).AndReturn(False) 207 gclient_scm.os.path.exists(parent).AndReturn(False)
211 gclient_scm.os.makedirs(parent) 208 gclient_scm.os.makedirs(parent)
212 gclient_scm.os.path.exists(parent).AndReturn(True) 209 gclient_scm.os.path.exists(parent).AndReturn(True)
213 files_list = self.mox.CreateMockAnything() 210 files_list = self.mox.CreateMockAnything()
214 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 211 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
215 ).AndReturn('1.6') 212 ).AndReturn('1.6')
216 gclient_scm.scm.SVN.RunAndGetFileList( 213 gclient_scm.scm.SVN.RunAndGetFileList(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 319
323 # TODO(maruel): TEST REVISIONS!!! 320 # TODO(maruel): TEST REVISIONS!!!
324 # TODO(maruel): TEST RELOCATE!!! 321 # TODO(maruel): TEST RELOCATE!!!
325 def testUpdateCheckout(self): 322 def testUpdateCheckout(self):
326 options = self.Options(verbose=True) 323 options = self.Options(verbose=True)
327 file_info = gclient_scm.gclient_utils.PrintableObject() 324 file_info = gclient_scm.gclient_utils.PrintableObject()
328 file_info.root = 'blah' 325 file_info.root = 'blah'
329 file_info.url = self.url 326 file_info.url = self.url
330 file_info.uuid = 'ABC' 327 file_info.uuid = 'ABC'
331 file_info.revision = 42 328 file_info.revision = 42
332 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
333 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 329 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
334 # Checkout. 330 # Checkout.
335 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 331 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
336 parent = gclient_scm.os.path.dirname(self.base_path) 332 parent = gclient_scm.os.path.dirname(self.base_path)
337 gclient_scm.os.path.exists(parent).AndReturn(False) 333 gclient_scm.os.path.exists(parent).AndReturn(False)
338 gclient_scm.os.makedirs(parent) 334 gclient_scm.os.makedirs(parent)
339 gclient_scm.os.path.exists(parent).AndReturn(True) 335 gclient_scm.os.path.exists(parent).AndReturn(True)
340 files_list = self.mox.CreateMockAnything() 336 files_list = self.mox.CreateMockAnything()
341 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 337 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
342 ).AndReturn('1.5.1') 338 ).AndReturn('1.5.1')
(...skipping 12 matching lines...) Expand all
355 def testUpdateUpdate(self): 351 def testUpdateUpdate(self):
356 options = self.Options(verbose=True) 352 options = self.Options(verbose=True)
357 options.force = True 353 options.force = True
358 options.nohooks = False 354 options.nohooks = False
359 file_info = { 355 file_info = {
360 'Repository Root': 'blah', 356 'Repository Root': 'blah',
361 'URL': self.url, 357 'URL': self.url,
362 'UUID': 'ABC', 358 'UUID': 'ABC',
363 'Revision': 42, 359 'Revision': 42,
364 } 360 }
365 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
366 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 361 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
362 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
363 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
367 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 364 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
368 365
369 # Checkout or update. 366 # Checkout or update.
370 dotted_path = join(self.base_path, '.') 367 dotted_path = join(self.base_path, '.')
371 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 368 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
372 369
373 # Verify no locked files. 370 # Verify no locked files.
374 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) 371 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([])
375 372
376 # Cheat a bit here. 373 # Cheat a bit here.
(...skipping 24 matching lines...) Expand all
401 398
402 def testUpdateReset(self): 399 def testUpdateReset(self):
403 options = self.Options(verbose=True) 400 options = self.Options(verbose=True)
404 options.reset = True 401 options.reset = True
405 file_info = { 402 file_info = {
406 'Repository Root': 'blah', 403 'Repository Root': 'blah',
407 'URL': self.url, 404 'URL': self.url,
408 'UUID': 'ABC', 405 'UUID': 'ABC',
409 'Revision': 42, 406 'Revision': 42,
410 } 407 }
411 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
412 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 408 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
409 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
410 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
413 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 411 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
414 412
415 # Checkout or update. 413 # Checkout or update.
416 dotted_path = join(self.base_path, '.') 414 dotted_path = join(self.base_path, '.')
417 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 415 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
418 416
419 # Create an untracked file and directory. 417 # Create an untracked file and directory.
420 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path 418 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
421 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) 419 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
422 420
(...skipping 14 matching lines...) Expand all
437 options = self.Options(verbose=True) 435 options = self.Options(verbose=True)
438 options.reset = True 436 options.reset = True
439 options.delete_unversioned_trees = True 437 options.delete_unversioned_trees = True
440 438
441 file_info = { 439 file_info = {
442 'Repository Root': 'blah', 440 'Repository Root': 'blah',
443 'URL': self.url, 441 'URL': self.url,
444 'UUID': 'ABC', 442 'UUID': 'ABC',
445 'Revision': 42, 443 'Revision': 42,
446 } 444 }
447 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
448 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 445 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
446 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
447 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
449 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 448 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
450 449
451 # Checkout or update. 450 # Checkout or update.
452 dotted_path = join(self.base_path, '.') 451 dotted_path = join(self.base_path, '.')
453 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 452 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
454 453
455 # Create an untracked file and directory. 454 # Create an untracked file and directory.
456 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path 455 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
457 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) 456 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
458 457
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], 502 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path],
504 always=True, 503 always=True,
505 cwd=self.root_dir) 504 cwd=self.root_dir)
506 gclient_scm.scm.SVN.RunAndGetFileList( 505 gclient_scm.scm.SVN.RunAndGetFileList(
507 options.verbose, 506 options.verbose,
508 ['update', 'DEPS', '--ignore-externals'], 507 ['update', 'DEPS', '--ignore-externals'],
509 cwd=self.base_path, 508 cwd=self.base_path,
510 file_list=files_list) 509 file_list=files_list)
511 510
512 # Now we fall back on scm.update(). 511 # Now we fall back on scm.update().
513 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
514 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 512 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
513 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
514 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
515 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 515 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
516 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 516 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
517 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 517 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
518 ).AndReturn(file_info) 518 ).AndReturn(file_info)
519 519
520 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 520 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
521 ).AndReturn({'Revision': 100}) 521 ).AndReturn({'Revision': 100})
522 522
523 self.mox.ReplayAll() 523 self.mox.ReplayAll()
524 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 524 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], 573 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path],
574 always=True, 574 always=True,
575 cwd=self.root_dir) 575 cwd=self.root_dir)
576 gclient_scm.scm.SVN.RunAndGetFileList( 576 gclient_scm.scm.SVN.RunAndGetFileList(
577 options.verbose, 577 options.verbose,
578 ['update', 'DEPS', '--ignore-externals'], 578 ['update', 'DEPS', '--ignore-externals'],
579 cwd=self.base_path, 579 cwd=self.base_path,
580 file_list=files_list) 580 file_list=files_list)
581 581
582 # Now we fall back on scm.update(). 582 # Now we fall back on scm.update().
583 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
584 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 583 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
584 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
585 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
585 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 586 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
586 gclient_scm.scm.SVN._CaptureInfo( 587 gclient_scm.scm.SVN._CaptureInfo(
587 [], join(self.base_path, ".")).AndReturn(file_info) 588 [], join(self.base_path, ".")).AndReturn(file_info)
588 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 589 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
589 ).AndReturn(file_info) 590 ).AndReturn(file_info)
590 591
591 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 592 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
592 ).AndReturn({'Revision': 100}) 593 ).AndReturn({'Revision': 100})
593 594
594 self.mox.ReplayAll() 595 self.mox.ReplayAll()
(...skipping 14 matching lines...) Expand all
609 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 610 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
610 ).AndReturn('1.5.1') 611 ).AndReturn('1.5.1')
611 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) 612 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True)
612 613
613 # Verify no locked files. 614 # Verify no locked files.
614 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') 615 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.')
615 ).AndReturn([]) 616 ).AndReturn([])
616 617
617 # Now we fall back on scm.update(). 618 # Now we fall back on scm.update().
618 files_list = self.mox.CreateMockAnything() 619 files_list = self.mox.CreateMockAnything()
619 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
620 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 620 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
621 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
622 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
621 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 623 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
622 gclient_scm.scm.SVN._CaptureInfo( 624 gclient_scm.scm.SVN._CaptureInfo(
623 [], join(self.base_path, '.')).AndReturn(file_info) 625 [], join(self.base_path, '.')).AndReturn(file_info)
624 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 626 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
625 ).AndReturn(file_info) 627 ).AndReturn(file_info)
626 628
627 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 629 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
628 ).AndReturn({'Revision': 100}) 630 ).AndReturn({'Revision': 100})
629 631
630 self.mox.ReplayAll() 632 self.mox.ReplayAll()
631 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 633 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
632 relpath=self.relpath) 634 relpath=self.relpath)
633 scm.updatesingle(options, ['DEPS'], files_list) 635 scm.updatesingle(options, ['DEPS'], files_list)
634 self.checkstdout('_____ %s at 42\n' % self.relpath) 636 self.checkstdout('_____ %s at 42\n' % self.relpath)
635 637
636 def testUpdateGit(self): 638 def testUpdateGit(self):
637 options = self.Options(verbose=True) 639 options = self.Options(verbose=True)
638 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') 640 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
639 gclient_scm.os.path.exists(file_path).AndReturn(True) 641 gclient_scm.os.path.exists(file_path).AndReturn(False)
642 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
643 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
644 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
645 error = gclient_scm.subprocess2.CalledProcessError(
646 1, 'cmd', '/cwd', 'stdout', 'stderr')
647 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error)
648
649 gclient_scm.os.path.exists(self.root_dir).AndReturn(True)
650 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
651 ).AndReturn('1.5.1')
652 gclient_scm.scm.SVN.RunAndGetFileList(
653 options.verbose,
654 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
655 cwd=self.root_dir,
656 file_list=[])
657
658 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
659 ).AndReturn({'Revision': 100})
660
661 self.mox.ReplayAll()
662 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
663 relpath=self.relpath)
664 scm.update(options, None, [])
665
666 def testUpdateGitForce(self):
667 options = self.Options(verbose=True, force=True)
668 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
669 gclient_scm.os.path.exists(file_path).AndReturn(False)
670 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
671 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
672 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
673 error = gclient_scm.subprocess2.CalledProcessError(
674 1, 'cmd', '/cwd', 'stdout', 'stderr')
675 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error)
676 gclient_scm.os.path.exists(self.root_dir).AndReturn(True)
677 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
678 ).AndReturn('1.5.1')
679 gclient_scm.scm.SVN.RunAndGetFileList(
680 options.verbose,
681 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
682 cwd=self.root_dir,
683 file_list=[])
684
685 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
686 ).AndReturn({'Revision': 100})
640 687
641 self.mox.ReplayAll() 688 self.mox.ReplayAll()
642 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 689 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
643 relpath=self.relpath) 690 relpath=self.relpath)
644 file_list = [] 691 file_list = []
645 scm.update(options, self.args, file_list) 692 scm.update(options, None, file_list)
693
694 def testUpdateGitSvn(self):
695 options = self.Options(verbose=True)
696 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
697 gclient_scm.os.path.exists(file_path).AndReturn(False)
698 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
699 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
700 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True)
701 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True)
702 gclient_scm.scm.GIT.Capture(['config', '--local', '--get',
703 'svn-remote.svn.url'],
704 cwd=self.base_path).AndReturn(self.url)
705
706 self.mox.ReplayAll()
707 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
708 relpath=self.relpath)
709 file_list = []
710 scm.update(options, [], file_list)
646 self.checkstdout( 711 self.checkstdout(
647 ('________ found .git directory; skipping %s\n' % self.relpath)) 712 ('\n_____ %s looks like a git-svn checkout. Skipping.\n' % self.relpath)
713 )
648 714
649 def testUpdateHg(self): 715 def testUpdateHg(self):
650 options = self.Options(verbose=True) 716 options = self.Options(verbose=True)
651 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
652 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True) 717 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True)
653 718
654 self.mox.ReplayAll() 719 self.mox.ReplayAll()
655 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 720 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
656 relpath=self.relpath) 721 relpath=self.relpath)
657 file_list = [] 722 file_list = []
658 scm.update(options, self.args, file_list) 723 scm.update(options, self.args, file_list)
659 self.checkstdout( 724 self.checkstdout(
660 ('________ found .hg directory; skipping %s\n' % self.relpath)) 725 ('________ found .hg directory; skipping %s\n' % self.relpath))
661 726
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 self.deps_os = None 1167 self.deps_os = None
1103 self.force = force 1168 self.force = force
1104 self.reset = False 1169 self.reset = False
1105 self.nohooks = False 1170 self.nohooks = False
1106 # TODO(maruel): Test --jobs > 1. 1171 # TODO(maruel): Test --jobs > 1.
1107 self.jobs = 1 1172 self.jobs = 1
1108 1173
1109 def Options(self, *args, **kwargs): 1174 def Options(self, *args, **kwargs):
1110 return self.OptionsObject(*args, **kwargs) 1175 return self.OptionsObject(*args, **kwargs)
1111 1176
1177 def checkstdout(self, expected):
1178 value = sys.stdout.getvalue()
1179 sys.stdout.close()
1180 # pylint: disable=E1101
1181 self.assertEquals(expected, strip_timestamps(value))
1182
1112 def setUp(self): 1183 def setUp(self):
1113 BaseTestCase.setUp(self) 1184 BaseTestCase.setUp(self)
1114 self.fake_hash_1 = 't0ta11yf4k3' 1185 self.fake_hash_1 = 't0ta11yf4k3'
1115 self.fake_hash_2 = '3v3nf4k3r' 1186 self.fake_hash_2 = '3v3nf4k3r'
1116 self.url = 'git://foo' 1187 self.url = 'git://foo'
1117 self.root_dir = '/tmp' if sys.platform != 'win32' else 't:\\tmp' 1188 self.root_dir = '/tmp' if sys.platform != 'win32' else 't:\\tmp'
1118 self.relpath = 'fake' 1189 self.relpath = 'fake'
1119 self.base_path = os.path.join(self.root_dir, self.relpath) 1190 self.base_path = os.path.join(self.root_dir, self.relpath)
1120 1191
1121 def tearDown(self): 1192 def tearDown(self):
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 self.assertEquals(git_svn_scm.GetUsableRev('3', options), 1283 self.assertEquals(git_svn_scm.GetUsableRev('3', options),
1213 self.fake_hash_2) 1284 self.fake_hash_2)
1214 # Given a git sha1 with a git-svn checkout, it should be used as is. 1285 # Given a git sha1 with a git-svn checkout, it should be used as is.
1215 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), 1286 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options),
1216 self.fake_hash_1) 1287 self.fake_hash_1)
1217 # We currently check for seemingly valid SVN revisions by assuming 6 digit 1288 # We currently check for seemingly valid SVN revisions by assuming 6 digit
1218 # numbers, so assure that numeric revs >= 1000000 don't work. 1289 # numbers, so assure that numeric revs >= 1000000 don't work.
1219 self.assertRaises(gclient_scm.gclient_utils.Error, 1290 self.assertRaises(gclient_scm.gclient_utils.Error,
1220 git_svn_scm.GetUsableRev, too_big, options) 1291 git_svn_scm.GetUsableRev, too_big, options)
1221 1292
1293 def testUpdateNoDotGit(self):
1294 options = self.Options()
1295
1296 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
1297 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1298 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1299 ).AndReturn(False)
1300 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1301 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1302 ).AndReturn(False)
1303
1304 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
1305 # pylint: disable=E1120
1306 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
1307 options)
1308 # pylint: disable=E1120
1309 self.mox.StubOutWithMock(gclient_scm.GitWrapper, 'UpdateSubmoduleConfig',
1310 True)
1311 gclient_scm.GitWrapper.UpdateSubmoduleConfig()
1312 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
1313 gclient_scm.subprocess2.check_output(['git', 'ls-files'],
1314 cwd=self.base_path,
1315 stderr=-1,
1316 ).AndReturn('')
1317 gclient_scm.subprocess2.check_output(
1318 ['git', 'rev-parse', '--verify', 'HEAD'],
1319 cwd=self.base_path,
1320 stderr=-1,
1321 ).AndReturn('')
1322
1323 self.mox.ReplayAll()
1324 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1325 relpath=self.relpath)
1326 scm.update(options, None, [])
1327 self.checkstdout('\n')
1328
1329 def testUpdateNoDotGitForce(self):
1330 options = self.Options(force=True)
1331
1332 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
1333 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1334 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1335 ).AndReturn(False)
1336 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1337 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1338 ).AndReturn(False)
1339 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
1340 # pylint: disable=E1120
1341 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
1342 options)
1343 # pylint: disable=E1120
1344 self.mox.StubOutWithMock(gclient_scm.GitWrapper, 'UpdateSubmoduleConfig',
1345 True)
1346 gclient_scm.GitWrapper.UpdateSubmoduleConfig()
1347 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
1348 gclient_scm.subprocess2.check_output(['git', 'ls-files'],
1349 cwd=self.base_path,
1350 stderr=-1,
1351 ).AndReturn('')
1352 gclient_scm.subprocess2.check_output(
1353 ['git', 'rev-parse', '--verify', 'HEAD'],
1354 cwd=self.base_path,
1355 stderr=-1,
1356 ).AndReturn('')
1357
1358 self.mox.ReplayAll()
1359 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1360 relpath=self.relpath)
1361 scm.update(options, None, [])
1362 self.checkstdout('\n')
1363
1222 1364
1223 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): 1365 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
1224 def testUpdateUpdate(self): 1366 def testUpdateUpdate(self):
1225 if not self.enabled: 1367 if not self.enabled:
1226 return 1368 return
1227 options = self.Options() 1369 options = self.Options()
1228 expected_file_list = [] 1370 expected_file_list = []
1229 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1371 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1230 relpath=self.relpath) 1372 relpath=self.relpath)
1231 file_list = [] 1373 file_list = []
1232 options.revision = 'unmanaged' 1374 options.revision = 'unmanaged'
1233 scm.update(options, (), file_list) 1375 scm.update(options, (), file_list)
1234 self.assertEquals(file_list, expected_file_list) 1376 self.assertEquals(file_list, expected_file_list)
1235 self.assertEquals(scm.revinfo(options, (), None), 1377 self.assertEquals(scm.revinfo(options, (), None),
1236 '069c602044c5388d2d15c3f875b057c852003458') 1378 '069c602044c5388d2d15c3f875b057c852003458')
1237 self.checkstdout('________ unmanaged solution; skipping .\n') 1379 self.checkstdout('________ unmanaged solution; skipping .\n')
1238 1380
1239 1381
1240 if __name__ == '__main__': 1382 if __name__ == '__main__':
1241 if '-v' in sys.argv: 1383 if '-v' in sys.argv:
1242 logging.basicConfig( 1384 logging.basicConfig(
1243 level=logging.DEBUG, 1385 level=logging.DEBUG,
1244 format='%(asctime).19s %(levelname)s %(filename)s:' 1386 format='%(asctime).19s %(levelname)s %(filename)s:'
1245 '%(lineno)s %(message)s') 1387 '%(lineno)s %(message)s')
1246 unittest.main() 1388 unittest.main()
1247 1389
1248 # vim: ts=2:sw=2:tw=80:et: 1390 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « testing_support/fake_repos.py ('k') | tests/gclient_smoketest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698