OLD | NEW |
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 BaseTestCase.setUp(self) | 97 BaseTestCase.setUp(self) |
98 self.url = self.SvnUrl() | 98 self.url = self.SvnUrl() |
99 | 99 |
100 def testDir(self): | 100 def testDir(self): |
101 members = [ | 101 members = [ |
102 'BinaryExists', | 102 'BinaryExists', |
103 'FullUrlForRelativeUrl', | 103 'FullUrlForRelativeUrl', |
104 'GetCheckoutRoot', | 104 'GetCheckoutRoot', |
105 'GetRevisionDate', | 105 'GetRevisionDate', |
106 'GetUsableRev', | 106 'GetUsableRev', |
| 107 'Svnversion', |
107 'RunCommand', | 108 'RunCommand', |
108 'cleanup', | 109 'cleanup', |
109 'diff', | 110 'diff', |
| 111 'name', |
110 'nag_max', | 112 'nag_max', |
111 'nag_timer', | 113 'nag_timer', |
112 'pack', | 114 'pack', |
113 'relpath', | 115 'relpath', |
114 'revert', | 116 'revert', |
115 'revinfo', | 117 'revinfo', |
116 'runhooks', | 118 'runhooks', |
117 'status', | 119 'status', |
118 'update', | 120 'update', |
119 'updatesingle', | 121 'updatesingle', |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 gclient_scm.os.path.exists(parent).AndReturn(False) | 193 gclient_scm.os.path.exists(parent).AndReturn(False) |
192 gclient_scm.os.makedirs(parent) | 194 gclient_scm.os.makedirs(parent) |
193 gclient_scm.os.path.exists(parent).AndReturn(True) | 195 gclient_scm.os.path.exists(parent).AndReturn(True) |
194 files_list = self.mox.CreateMockAnything() | 196 files_list = self.mox.CreateMockAnything() |
195 gclient_scm.scm.SVN.RunAndGetFileList( | 197 gclient_scm.scm.SVN.RunAndGetFileList( |
196 options.verbose, | 198 options.verbose, |
197 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 199 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
198 cwd=self.root_dir, | 200 cwd=self.root_dir, |
199 file_list=files_list) | 201 file_list=files_list) |
200 | 202 |
| 203 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 204 ).AndReturn({'Revision': 100}) |
| 205 |
201 self.mox.ReplayAll() | 206 self.mox.ReplayAll() |
202 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 207 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
203 relpath=self.relpath) | 208 relpath=self.relpath) |
204 scm.revert(options, self.args, files_list) | 209 scm.revert(options, self.args, files_list) |
205 self.checkstdout( | 210 self.checkstdout( |
206 ('\n_____ %s is missing, synching instead\n' % self.relpath)) | 211 ('\n_____ %s is missing, synching instead\n' % self.relpath)) |
207 | 212 |
208 def testRevertNoDotSvn(self): | 213 def testRevertNoDotSvn(self): |
209 options = self.Options(verbose=True, force=True) | 214 options = self.Options(verbose=True, force=True) |
210 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 215 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
(...skipping 10 matching lines...) Expand all Loading... |
221 gclient_scm.os.path.exists(parent).AndReturn(True) | 226 gclient_scm.os.path.exists(parent).AndReturn(True) |
222 files_list = self.mox.CreateMockAnything() | 227 files_list = self.mox.CreateMockAnything() |
223 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 228 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
224 ).AndReturn('1.6') | 229 ).AndReturn('1.6') |
225 gclient_scm.scm.SVN.RunAndGetFileList( | 230 gclient_scm.scm.SVN.RunAndGetFileList( |
226 options.verbose, | 231 options.verbose, |
227 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 232 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
228 cwd=self.root_dir, | 233 cwd=self.root_dir, |
229 file_list=files_list) | 234 file_list=files_list) |
230 gclient_scm.gclient_utils.rmtree(self.base_path) | 235 gclient_scm.gclient_utils.rmtree(self.base_path) |
| 236 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 237 ).AndReturn({'Revision': 100}) |
231 self.mox.ReplayAll() | 238 self.mox.ReplayAll() |
232 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 239 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
233 relpath=self.relpath) | 240 relpath=self.relpath) |
234 scm.revert(options, self.args, files_list) | 241 scm.revert(options, self.args, files_list) |
235 self.checkstdout( | 242 self.checkstdout( |
236 '\n_____ %s is not a valid svn checkout, synching instead\n' % | 243 '\n_____ %s is not a valid svn checkout, synching instead\n' % |
237 self.relpath) | 244 self.relpath) |
238 | 245 |
239 def testRevertNone(self): | 246 def testRevertNone(self): |
240 options = self.Options(verbose=True) | 247 options = self.Options(verbose=True) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 gclient_scm.os.makedirs(parent) | 352 gclient_scm.os.makedirs(parent) |
346 gclient_scm.os.path.exists(parent).AndReturn(True) | 353 gclient_scm.os.path.exists(parent).AndReturn(True) |
347 files_list = self.mox.CreateMockAnything() | 354 files_list = self.mox.CreateMockAnything() |
348 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 355 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
349 ).AndReturn('1.5.1') | 356 ).AndReturn('1.5.1') |
350 gclient_scm.scm.SVN.RunAndGetFileList( | 357 gclient_scm.scm.SVN.RunAndGetFileList( |
351 options.verbose, | 358 options.verbose, |
352 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 359 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
353 cwd=self.root_dir, | 360 cwd=self.root_dir, |
354 file_list=files_list) | 361 file_list=files_list) |
| 362 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 363 ).AndReturn({'Revision': 100}) |
355 self.mox.ReplayAll() | 364 self.mox.ReplayAll() |
356 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 365 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
357 relpath=self.relpath) | 366 relpath=self.relpath) |
358 scm.update(options, (), files_list) | 367 scm.update(options, (), files_list) |
359 | 368 |
360 def testUpdateUpdate(self): | 369 def testUpdateUpdate(self): |
361 options = self.Options(verbose=True) | 370 options = self.Options(verbose=True) |
362 options.force = True | 371 options.force = True |
363 options.nohooks = False | 372 options.nohooks = False |
364 file_info = { | 373 file_info = { |
(...skipping 14 matching lines...) Expand all Loading... |
379 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) | 388 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) |
380 | 389 |
381 # Cheat a bit here. | 390 # Cheat a bit here. |
382 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 391 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
383 ).AndReturn(file_info) | 392 ).AndReturn(file_info) |
384 | 393 |
385 # _AddAdditionalUpdateFlags() | 394 # _AddAdditionalUpdateFlags() |
386 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 395 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
387 ).AndReturn('1.5.1') | 396 ).AndReturn('1.5.1') |
388 | 397 |
| 398 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 399 ).AndReturn({'Revision': 100}) |
| 400 |
389 additional_args = [] | 401 additional_args = [] |
390 if options.manually_grab_svn_rev: | 402 if options.manually_grab_svn_rev: |
391 additional_args = ['--revision', str(file_info['Revision'])] | 403 additional_args = ['--revision', str(file_info['Revision'])] |
392 additional_args.extend(['--force', '--ignore-externals']) | 404 additional_args.extend(['--force', '--ignore-externals']) |
393 files_list = [] | 405 files_list = [] |
394 gclient_scm.scm.SVN.RunAndGetFileList( | 406 gclient_scm.scm.SVN.RunAndGetFileList( |
395 options.verbose, | 407 options.verbose, |
396 ['update', self.base_path] + additional_args, | 408 ['update', self.base_path] + additional_args, |
397 cwd=self.root_dir, file_list=files_list) | 409 cwd=self.root_dir, file_list=files_list) |
398 | 410 |
(...skipping 19 matching lines...) Expand all Loading... |
418 dotted_path = join(self.base_path, '.') | 430 dotted_path = join(self.base_path, '.') |
419 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 431 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
420 | 432 |
421 # Create an untracked file and directory. | 433 # Create an untracked file and directory. |
422 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | 434 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path |
423 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 435 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) |
424 | 436 |
425 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 437 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
426 ).AndReturn(file_info) | 438 ).AndReturn(file_info) |
427 | 439 |
| 440 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 441 ).AndReturn({'Revision': 100}) |
| 442 |
428 self.mox.ReplayAll() | 443 self.mox.ReplayAll() |
429 files_list = [] | 444 files_list = [] |
430 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 445 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
431 relpath=self.relpath) | 446 relpath=self.relpath) |
432 scm.update(options, (), files_list) | 447 scm.update(options, (), files_list) |
433 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 448 self.checkstdout('\n_____ %s at 42\n' % self.relpath) |
434 | 449 |
435 def testUpdateResetDeleteUnversionedTrees(self): | 450 def testUpdateResetDeleteUnversionedTrees(self): |
436 options = self.Options(verbose=True) | 451 options = self.Options(verbose=True) |
437 options.reset = True | 452 options.reset = True |
(...skipping 21 matching lines...) Expand all Loading... |
459 ).AndReturn(file_info) | 474 ).AndReturn(file_info) |
460 | 475 |
461 # Confirm that the untracked file is removed. | 476 # Confirm that the untracked file is removed. |
462 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path | 477 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path |
463 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 478 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) |
464 gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True) | 479 gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True) |
465 gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False) | 480 gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False) |
466 gclient_scm.os.path.islink(join(self.base_path, 'dir')).AndReturn(False) | 481 gclient_scm.os.path.islink(join(self.base_path, 'dir')).AndReturn(False) |
467 gclient_scm.gclient_utils.rmtree(join(self.base_path, 'dir')) | 482 gclient_scm.gclient_utils.rmtree(join(self.base_path, 'dir')) |
468 | 483 |
| 484 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 485 ).AndReturn({'Revision': 100}) |
| 486 |
469 self.mox.ReplayAll() | 487 self.mox.ReplayAll() |
470 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 488 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
471 relpath=self.relpath) | 489 relpath=self.relpath) |
472 files_list = [] | 490 files_list = [] |
473 scm.update(options, (), files_list) | 491 scm.update(options, (), files_list) |
474 self.checkstdout( | 492 self.checkstdout( |
475 ('\n_____ %s at 42\n' | 493 ('\n_____ %s at 42\n' |
476 '\n_____ removing unversioned directory dir\n') % self.relpath) | 494 '\n_____ removing unversioned directory dir\n') % self.relpath) |
477 | 495 |
478 def testUpdateSingleCheckout(self): | 496 def testUpdateSingleCheckout(self): |
(...skipping 29 matching lines...) Expand all Loading... |
508 file_list=files_list) | 526 file_list=files_list) |
509 | 527 |
510 # Now we fall back on scm.update(). | 528 # Now we fall back on scm.update(). |
511 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 529 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
512 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 530 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
513 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 531 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
514 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 532 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
515 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 533 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
516 ).AndReturn(file_info) | 534 ).AndReturn(file_info) |
517 | 535 |
| 536 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 537 ).AndReturn({'Revision': 100}) |
| 538 |
518 self.mox.ReplayAll() | 539 self.mox.ReplayAll() |
519 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 540 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
520 relpath=self.relpath) | 541 relpath=self.relpath) |
521 scm.updatesingle(options, ['DEPS'], files_list) | 542 scm.updatesingle(options, ['DEPS'], files_list) |
522 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 543 self.checkstdout('\n_____ %s at 42\n' % self.relpath) |
523 | 544 |
524 def testUpdateSingleCheckoutSVN14(self): | 545 def testUpdateSingleCheckoutSVN14(self): |
525 options = self.Options(verbose=True) | 546 options = self.Options(verbose=True) |
526 | 547 |
527 # Checks to make sure that we support svn co --depth. | 548 # Checks to make sure that we support svn co --depth. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 | 599 |
579 # Now we fall back on scm.update(). | 600 # Now we fall back on scm.update(). |
580 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 601 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
581 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 602 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
582 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 603 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
583 gclient_scm.scm.SVN._CaptureInfo( | 604 gclient_scm.scm.SVN._CaptureInfo( |
584 [], join(self.base_path, ".")).AndReturn(file_info) | 605 [], join(self.base_path, ".")).AndReturn(file_info) |
585 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 606 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
586 ).AndReturn(file_info) | 607 ).AndReturn(file_info) |
587 | 608 |
| 609 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 610 ).AndReturn({'Revision': 100}) |
| 611 |
588 self.mox.ReplayAll() | 612 self.mox.ReplayAll() |
589 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 613 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
590 relpath=self.relpath) | 614 relpath=self.relpath) |
591 scm.updatesingle(options, ['DEPS'], files_list) | 615 scm.updatesingle(options, ['DEPS'], files_list) |
592 self.checkstdout( | 616 self.checkstdout( |
593 ('\n_____ %s at 42\n' % self.relpath)) | 617 ('\n_____ %s at 42\n' % self.relpath)) |
594 | 618 |
595 def testUpdateSingleUpdate(self): | 619 def testUpdateSingleUpdate(self): |
596 options = self.Options(verbose=True) | 620 options = self.Options(verbose=True) |
597 file_info = { | 621 file_info = { |
(...skipping 13 matching lines...) Expand all Loading... |
611 # Now we fall back on scm.update(). | 635 # Now we fall back on scm.update(). |
612 files_list = self.mox.CreateMockAnything() | 636 files_list = self.mox.CreateMockAnything() |
613 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 637 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
614 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 638 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
615 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 639 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
616 gclient_scm.scm.SVN._CaptureInfo( | 640 gclient_scm.scm.SVN._CaptureInfo( |
617 [], join(self.base_path, '.')).AndReturn(file_info) | 641 [], join(self.base_path, '.')).AndReturn(file_info) |
618 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 642 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
619 ).AndReturn(file_info) | 643 ).AndReturn(file_info) |
620 | 644 |
| 645 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 646 ).AndReturn({'Revision': 100}) |
| 647 |
621 self.mox.ReplayAll() | 648 self.mox.ReplayAll() |
622 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, |
623 relpath=self.relpath) | 650 relpath=self.relpath) |
624 scm.updatesingle(options, ['DEPS'], files_list) | 651 scm.updatesingle(options, ['DEPS'], files_list) |
625 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 652 self.checkstdout('\n_____ %s at 42\n' % self.relpath) |
626 | 653 |
627 def testUpdateGit(self): | 654 def testUpdateGit(self): |
628 options = self.Options(verbose=True) | 655 options = self.Options(verbose=True) |
629 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') | 656 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
630 gclient_scm.os.path.exists(file_path).AndReturn(True) | 657 gclient_scm.os.path.exists(file_path).AndReturn(True) |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 'BinaryExists', | 819 'BinaryExists', |
793 'FullUrlForRelativeUrl', | 820 'FullUrlForRelativeUrl', |
794 'GetCheckoutRoot', | 821 'GetCheckoutRoot', |
795 'GetRevisionDate', | 822 'GetRevisionDate', |
796 'GetUsableRev', | 823 'GetUsableRev', |
797 'RunCommand', | 824 'RunCommand', |
798 'cache_dir', | 825 'cache_dir', |
799 'cache_locks', | 826 'cache_locks', |
800 'cleanup', | 827 'cleanup', |
801 'diff', | 828 'diff', |
| 829 'name', |
802 'nag_max', | 830 'nag_max', |
803 'nag_timer', | 831 'nag_timer', |
804 'pack', | 832 'pack', |
805 'UpdateSubmoduleConfig', | 833 'UpdateSubmoduleConfig', |
806 'relpath', | 834 'relpath', |
807 'revert', | 835 'revert', |
808 'revinfo', | 836 'revinfo', |
809 'runhooks', | 837 'runhooks', |
810 'status', | 838 'status', |
811 'update', | 839 'update', |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 | 1208 |
1181 if __name__ == '__main__': | 1209 if __name__ == '__main__': |
1182 if '-v' in sys.argv: | 1210 if '-v' in sys.argv: |
1183 logging.basicConfig( | 1211 logging.basicConfig( |
1184 level=logging.DEBUG, | 1212 level=logging.DEBUG, |
1185 format='%(asctime).19s %(levelname)s %(filename)s:' | 1213 format='%(asctime).19s %(levelname)s %(filename)s:' |
1186 '%(lineno)s %(message)s') | 1214 '%(lineno)s %(message)s') |
1187 unittest.main() | 1215 unittest.main() |
1188 | 1216 |
1189 # vim: ts=2:sw=2:tw=80:et: | 1217 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |