| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 def __init__(self, verbose=False, revision=None, force=False): | 76 def __init__(self, verbose=False, revision=None, force=False): |
| 77 self.verbose = verbose | 77 self.verbose = verbose |
| 78 self.revision = revision | 78 self.revision = revision |
| 79 self.manually_grab_svn_rev = True | 79 self.manually_grab_svn_rev = True |
| 80 self.deps_os = None | 80 self.deps_os = None |
| 81 self.force = force | 81 self.force = force |
| 82 self.reset = False | 82 self.reset = False |
| 83 self.nohooks = False | 83 self.nohooks = False |
| 84 # TODO(maruel): Test --jobs > 1. | 84 # TODO(maruel): Test --jobs > 1. |
| 85 self.jobs = 1 | 85 self.jobs = 1 |
| 86 self.delete_unversioned_trees = False |
| 86 | 87 |
| 87 def Options(self, *args, **kwargs): | 88 def Options(self, *args, **kwargs): |
| 88 return self.OptionsObject(*args, **kwargs) | 89 return self.OptionsObject(*args, **kwargs) |
| 89 | 90 |
| 90 def setUp(self): | 91 def setUp(self): |
| 91 BaseTestCase.setUp(self) | 92 BaseTestCase.setUp(self) |
| 92 self.url = self.SvnUrl() | 93 self.url = self.SvnUrl() |
| 93 | 94 |
| 94 def testDir(self): | 95 def testDir(self): |
| 95 members = [ | 96 members = [ |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 # Verify no locked files. | 361 # Verify no locked files. |
| 361 dotted_path = join(self.base_path, '.') | 362 dotted_path = join(self.base_path, '.') |
| 362 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) | 363 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) |
| 363 | 364 |
| 364 # Checkout or update. | 365 # Checkout or update. |
| 365 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 366 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 366 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 367 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
| 367 # Cheat a bit here. | 368 # Cheat a bit here. |
| 368 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 369 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 369 ).AndReturn(file_info) | 370 ).AndReturn(file_info) |
| 371 gclient_scm.scm.SVN.Capture(['--version'], None |
| 372 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 373 |
| 370 additional_args = [] | 374 additional_args = [] |
| 371 if options.manually_grab_svn_rev: | 375 if options.manually_grab_svn_rev: |
| 372 additional_args = ['--revision', str(file_info['Revision'])] | 376 additional_args = ['--revision', str(file_info['Revision'])] |
| 373 gclient_scm.scm.SVN.Capture(['--version'], None | |
| 374 ).AndReturn('svn, version 1.5.1 (r32289)') | |
| 375 additional_args.extend(['--force', '--ignore-externals']) | 377 additional_args.extend(['--force', '--ignore-externals']) |
| 376 files_list = [] | 378 files_list = [] |
| 377 gclient_scm.scm.SVN.RunAndGetFileList( | 379 gclient_scm.scm.SVN.RunAndGetFileList( |
| 380 options.verbose, |
| 381 ['update', self.base_path] + additional_args, |
| 382 cwd=self.root_dir, file_list=files_list) |
| 383 |
| 384 self.mox.ReplayAll() |
| 385 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 386 relpath=self.relpath) |
| 387 scm.update(options, (), files_list) |
| 388 |
| 389 def testUpdateForceNoDeleteUnversionedTrees(self): |
| 390 options = self.Options(verbose=True) |
| 391 options.force = True |
| 392 |
| 393 file_info = { |
| 394 'Repository Root': 'blah', |
| 395 'URL': self.url, |
| 396 'UUID': 'ABC', |
| 397 'Revision': 42, |
| 398 } |
| 399 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 400 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 401 |
| 402 # Create an untracked file and directory. |
| 403 dotted_path = join(self.base_path, '.') |
| 404 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path |
| 405 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) |
| 406 |
| 407 # Checkout or update. |
| 408 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 409 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
| 410 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 411 ).AndReturn(file_info) |
| 412 gclient_scm.scm.SVN.Capture(['--version'], None |
| 413 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 414 |
| 415 additional_args = [] |
| 416 if options.manually_grab_svn_rev: |
| 417 additional_args = ['--revision', str(file_info['Revision'])] |
| 418 additional_args.extend(['--force', '--ignore-externals']) |
| 419 files_list = [] |
| 420 gclient_scm.scm.SVN.RunAndGetFileList( |
| 378 options.verbose, | 421 options.verbose, |
| 379 ['update', self.base_path] + additional_args, | 422 ['update', self.base_path] + additional_args, |
| 380 cwd=self.root_dir, file_list=files_list) | 423 cwd=self.root_dir, file_list=files_list) |
| 381 | 424 |
| 382 self.mox.ReplayAll() | 425 self.mox.ReplayAll() |
| 383 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 426 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 384 relpath=self.relpath) | 427 relpath=self.relpath) |
| 385 scm.update(options, (), files_list) | 428 scm.update(options, (), files_list) |
| 386 | 429 |
| 430 def testUpdateForceDeleteUnversionedTrees(self): |
| 431 options = self.Options(verbose=True) |
| 432 options.force = True |
| 433 options.delete_unversioned_trees = True |
| 434 |
| 435 file_info = { |
| 436 'Repository Root': 'blah', |
| 437 'URL': self.url, |
| 438 'UUID': 'ABC', |
| 439 'Revision': 42, |
| 440 } |
| 441 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 442 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 443 |
| 444 # Create an untracked file and directory. |
| 445 dotted_path = join(self.base_path, '.') |
| 446 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path |
| 447 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) |
| 448 |
| 449 # Checkout or update. |
| 450 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 451 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
| 452 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 453 ).AndReturn(file_info) |
| 454 gclient_scm.scm.SVN.Capture(['--version'], None |
| 455 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 456 |
| 457 # Confirm that the untracked file is removed. |
| 458 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path |
| 459 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) |
| 460 gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True) |
| 461 gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False) |
| 462 gclient_scm.gclient_utils.RemoveDirectory(join(self.base_path, 'dir')) |
| 463 |
| 464 additional_args = [] |
| 465 if options.manually_grab_svn_rev: |
| 466 additional_args = ['--revision', str(file_info['Revision'])] |
| 467 additional_args.extend(['--force', '--ignore-externals']) |
| 468 files_list = [] |
| 469 gclient_scm.scm.SVN.RunAndGetFileList( |
| 470 options.verbose, |
| 471 ['update', self.base_path] + additional_args, |
| 472 cwd=self.root_dir, file_list=files_list) |
| 473 |
| 474 self.mox.ReplayAll() |
| 475 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 476 relpath=self.relpath) |
| 477 scm.update(options, (), files_list) |
| 478 self.checkstdout('\n_____ removing unversioned directory dir\n') |
| 479 |
| 387 def testUpdateSingleCheckout(self): | 480 def testUpdateSingleCheckout(self): |
| 388 options = self.Options(verbose=True) | 481 options = self.Options(verbose=True) |
| 389 file_info = { | 482 file_info = { |
| 390 'URL': self.url, | 483 'URL': self.url, |
| 391 'Revision': 42, | 484 'Revision': 42, |
| 392 } | 485 } |
| 393 | 486 |
| 394 # Checks to make sure that we support svn co --depth. | 487 # Checks to make sure that we support svn co --depth. |
| 395 gclient_scm.scm.SVN.current_version = None | 488 gclient_scm.scm.SVN.current_version = None |
| 396 gclient_scm.scm.SVN.Capture(['--version'], None | 489 gclient_scm.scm.SVN.Capture(['--version'], None |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 class OptionsObject(object): | 675 class OptionsObject(object): |
| 583 def __init__(self, verbose=False, revision=None): | 676 def __init__(self, verbose=False, revision=None): |
| 584 self.verbose = verbose | 677 self.verbose = verbose |
| 585 self.revision = revision | 678 self.revision = revision |
| 586 self.manually_grab_svn_rev = True | 679 self.manually_grab_svn_rev = True |
| 587 self.deps_os = None | 680 self.deps_os = None |
| 588 self.force = False | 681 self.force = False |
| 589 self.reset = False | 682 self.reset = False |
| 590 self.nohooks = False | 683 self.nohooks = False |
| 591 self.merge = False | 684 self.merge = False |
| 685 self.delete_unversioned_trees = False |
| 592 | 686 |
| 593 sample_git_import = """blob | 687 sample_git_import = """blob |
| 594 mark :1 | 688 mark :1 |
| 595 data 6 | 689 data 6 |
| 596 Hello | 690 Hello |
| 597 | 691 |
| 598 blob | 692 blob |
| 599 mark :2 | 693 mark :2 |
| 600 data 4 | 694 data 4 |
| 601 Bye | 695 Bye |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 file_list = [] | 982 file_list = [] |
| 889 scm.update(options, (), file_list) | 983 scm.update(options, (), file_list) |
| 890 self.assertEquals(file_list, expected_file_list) | 984 self.assertEquals(file_list, expected_file_list) |
| 891 self.assertEquals(scm.revinfo(options, (), None), | 985 self.assertEquals(scm.revinfo(options, (), None), |
| 892 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 986 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
| 893 self.checkstdout( | 987 self.checkstdout( |
| 894 '\n_____ . at refs/heads/master\n' | 988 '\n_____ . at refs/heads/master\n' |
| 895 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' | 989 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' |
| 896 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n') | 990 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n') |
| 897 | 991 |
| 992 def testUpdateForceNoDeleteUnversionedTrees(self): |
| 993 if not self.enabled: |
| 994 return |
| 995 options = self.Options() |
| 996 options.force = True |
| 997 |
| 998 dir_path = join(self.base_path, 'c') |
| 999 os.mkdir(dir_path) |
| 1000 open(join(dir_path, 'nested'), 'w').writelines('new\n') |
| 1001 |
| 1002 file_path = join(self.base_path, 'file') |
| 1003 open(file_path, 'w').writelines('new\n') |
| 1004 |
| 1005 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 1006 relpath=self.relpath) |
| 1007 file_list = [] |
| 1008 scm.update(options, (), file_list) |
| 1009 self.assert_(gclient_scm.os.path.isdir(dir_path)) |
| 1010 self.assert_(gclient_scm.os.path.isfile(file_path)) |
| 1011 self.checkstdout( |
| 1012 '\n________ running \'git reset --hard HEAD\' in \'%s\'' |
| 1013 '\nHEAD is now at 069c602 A and B\n' |
| 1014 '\n_____ . at refs/heads/master\n' |
| 1015 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' |
| 1016 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n' |
| 1017 % join(self.root_dir, '.')) |
| 1018 |
| 1019 def testUpdateForceDeleteUnversionedTrees(self): |
| 1020 if not self.enabled: |
| 1021 return |
| 1022 options = self.Options() |
| 1023 options.force = True |
| 1024 options.delete_unversioned_trees = True |
| 1025 |
| 1026 dir_path = join(self.base_path, 'dir') |
| 1027 os.mkdir(dir_path) |
| 1028 open(join(dir_path, 'nested'), 'w').writelines('new\n') |
| 1029 |
| 1030 file_path = join(self.base_path, 'file') |
| 1031 open(file_path, 'w').writelines('new\n') |
| 1032 |
| 1033 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 1034 relpath=self.relpath) |
| 1035 file_list = [] |
| 1036 scm.update(options, (), file_list) |
| 1037 self.assert_(not gclient_scm.os.path.isdir(dir_path)) |
| 1038 self.assert_(gclient_scm.os.path.isfile(file_path)) |
| 1039 self.checkstdout( |
| 1040 '\n________ running \'git reset --hard HEAD\' in \'%s\'' |
| 1041 '\nHEAD is now at 069c602 A and B\n' |
| 1042 '\n_____ . at refs/heads/master\n' |
| 1043 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' |
| 1044 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n' |
| 1045 '\n_____ removing unversioned directory dir/\n' % join(self.root_dir, |
| 1046 '.')) |
| 1047 |
| 898 def testUpdateUnstagedConflict(self): | 1048 def testUpdateUnstagedConflict(self): |
| 899 if not self.enabled: | 1049 if not self.enabled: |
| 900 return | 1050 return |
| 901 options = self.Options() | 1051 options = self.Options() |
| 902 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 1052 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 903 relpath=self.relpath) | 1053 relpath=self.relpath) |
| 904 file_path = join(self.base_path, 'b') | 1054 file_path = join(self.base_path, 'b') |
| 905 open(file_path, 'w').writelines('conflict\n') | 1055 open(file_path, 'w').writelines('conflict\n') |
| 906 try: | 1056 try: |
| 907 scm.update(options, (), []) | 1057 scm.update(options, (), []) |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 | 1293 |
| 1144 if __name__ == '__main__': | 1294 if __name__ == '__main__': |
| 1145 if '-v' in sys.argv: | 1295 if '-v' in sys.argv: |
| 1146 logging.basicConfig( | 1296 logging.basicConfig( |
| 1147 level=logging.DEBUG, | 1297 level=logging.DEBUG, |
| 1148 format='%(asctime).19s %(levelname)s %(filename)s:' | 1298 format='%(asctime).19s %(levelname)s %(filename)s:' |
| 1149 '%(lineno)s %(message)s') | 1299 '%(lineno)s %(message)s') |
| 1150 unittest.main() | 1300 unittest.main() |
| 1151 | 1301 |
| 1152 # vim: ts=2:sw=2:tw=80:et: | 1302 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |