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=E1101,E1103,W0403 | 8 # pylint: disable=E1101,E1103,W0403 |
9 | 9 |
10 # Import before super_mox to keep valid references. | 10 # Import before super_mox to keep valid references. |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 435 |
436 self.mox.ReplayAll() | 436 self.mox.ReplayAll() |
437 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 437 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
438 relpath=self.relpath) | 438 relpath=self.relpath) |
439 file_list = [] | 439 file_list = [] |
440 scm.update(options, self.args, file_list) | 440 scm.update(options, self.args, file_list) |
441 self.checkstdout( | 441 self.checkstdout( |
442 ('________ found .hg directory; skipping %s\n' % self.relpath)) | 442 ('________ found .hg directory; skipping %s\n' % self.relpath)) |
443 | 443 |
444 | 444 |
445 class GitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, | 445 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, |
446 unittest.TestCase): | 446 unittest.TestCase): |
447 """This class doesn't use pymox.""" | 447 """This class doesn't use pymox.""" |
448 class OptionsObject(object): | 448 class OptionsObject(object): |
449 def __init__(self, verbose=False, revision=None): | 449 def __init__(self, verbose=False, revision=None): |
450 self.verbose = verbose | 450 self.verbose = verbose |
451 self.revision = revision | 451 self.revision = revision |
452 self.manually_grab_svn_rev = True | 452 self.manually_grab_svn_rev = True |
453 self.deps_os = None | 453 self.deps_os = None |
454 self.force = False | 454 self.force = False |
455 self.reset = False | 455 self.reset = False |
456 self.nohooks = False | 456 self.nohooks = False |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 self.base_path = join(self.root_dir, self.relpath) | 536 self.base_path = join(self.root_dir, self.relpath) |
537 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) | 537 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) |
538 StdoutCheck.setUp(self) | 538 StdoutCheck.setUp(self) |
539 | 539 |
540 def tearDown(self): | 540 def tearDown(self): |
541 StdoutCheck.tearDown(self) | 541 StdoutCheck.tearDown(self) |
542 TestCaseUtils.tearDown(self) | 542 TestCaseUtils.tearDown(self) |
543 unittest.TestCase.tearDown(self) | 543 unittest.TestCase.tearDown(self) |
544 rmtree(self.root_dir) | 544 rmtree(self.root_dir) |
545 | 545 |
| 546 |
| 547 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): |
546 def testDir(self): | 548 def testDir(self): |
547 members = [ | 549 members = [ |
548 'FullUrlForRelativeUrl', 'GetRevisionDate', 'RunCommand', | 550 'FullUrlForRelativeUrl', 'GetRevisionDate', 'RunCommand', |
549 'cleanup', 'diff', 'pack', 'relpath', 'revert', | 551 'cleanup', 'diff', 'pack', 'relpath', 'revert', |
550 'revinfo', 'runhooks', 'status', 'update', 'url', | 552 'revinfo', 'runhooks', 'status', 'update', 'url', |
551 ] | 553 ] |
552 | 554 |
553 # If you add a member, be sure to add the relevant test! | 555 # If you add a member, be sure to add the relevant test! |
554 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) | 556 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) |
555 | 557 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 def testRevinfo(self): | 818 def testRevinfo(self): |
817 if not self.enabled: | 819 if not self.enabled: |
818 return | 820 return |
819 options = self.Options() | 821 options = self.Options() |
820 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 822 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
821 relpath=self.relpath) | 823 relpath=self.relpath) |
822 rev_info = scm.revinfo(options, (), None) | 824 rev_info = scm.revinfo(options, (), None) |
823 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') | 825 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') |
824 | 826 |
825 | 827 |
| 828 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): |
| 829 def testUpdateCheckout(self): |
| 830 if not self.enabled: |
| 831 return |
| 832 options = self.Options(verbose=True) |
| 833 root_dir = gclient_scm.os.path.realpath(tempfile.mkdtemp()) |
| 834 relpath = 'foo' |
| 835 base_path = join(root_dir, relpath) |
| 836 url = join(self.base_path, '.git') |
| 837 try: |
| 838 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, |
| 839 relpath=relpath) |
| 840 file_list = [] |
| 841 options.revision = 'unmanaged' |
| 842 scm.update(options, (), file_list) |
| 843 self.assertEquals(len(file_list), 2) |
| 844 self.assert_(gclient_scm.os.path.isfile(join(base_path, 'a'))) |
| 845 self.assertEquals(scm.revinfo(options, (), None), |
| 846 '069c602044c5388d2d15c3f875b057c852003458') |
| 847 finally: |
| 848 rmtree(root_dir) |
| 849 msg1 = ( |
| 850 "\n_____ foo at refs/heads/master\n\n" |
| 851 "________ running 'git clone -b master --verbose %s %s' in '%s'\n" |
| 852 "Initialized empty Git repository in %s\n") % ( |
| 853 join(self.root_dir, '.', '.git'), |
| 854 join(root_dir, 'foo'), |
| 855 root_dir, |
| 856 join(gclient_scm.os.path.realpath(root_dir), 'foo', '.git') + '/') |
| 857 msg2 = ( |
| 858 "\n_____ foo at refs/heads/master\n\n" |
| 859 "________ running 'git clone -b master --verbose %s %s' in '%s'\n" |
| 860 "Cloning into %s...\ndone.\n") % ( |
| 861 join(self.root_dir, '.', '.git'), |
| 862 join(root_dir, 'foo'), |
| 863 root_dir, |
| 864 join(gclient_scm.os.path.realpath(root_dir), 'foo')) |
| 865 out = sys.stdout.getvalue() |
| 866 sys.stdout.close() |
| 867 sys.stdout = self._old_stdout |
| 868 self.assertTrue(out in (msg1, msg2), (out, msg1, msg2)) |
| 869 |
| 870 def testUpdateUpdate(self): |
| 871 if not self.enabled: |
| 872 return |
| 873 options = self.Options() |
| 874 expected_file_list = [] |
| 875 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 876 relpath=self.relpath) |
| 877 file_list = [] |
| 878 options.revision = 'unmanaged' |
| 879 scm.update(options, (), file_list) |
| 880 self.assertEquals(file_list, expected_file_list) |
| 881 self.assertEquals(scm.revinfo(options, (), None), |
| 882 '069c602044c5388d2d15c3f875b057c852003458') |
| 883 self.checkstdout('________ unmanaged solution; skipping .\n') |
| 884 |
| 885 |
826 if __name__ == '__main__': | 886 if __name__ == '__main__': |
827 if '-v' in sys.argv: | 887 if '-v' in sys.argv: |
828 logging.basicConfig( | 888 logging.basicConfig( |
829 level=logging.DEBUG, | 889 level=logging.DEBUG, |
830 format='%(asctime).19s %(levelname)s %(filename)s:' | 890 format='%(asctime).19s %(levelname)s %(filename)s:' |
831 '%(lineno)s %(message)s') | 891 '%(lineno)s %(message)s') |
832 unittest.main() | 892 unittest.main() |
833 | 893 |
834 # vim: ts=2:sw=2:tw=80:et: | 894 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |