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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 95 |
96 def setUp(self): | 96 def setUp(self): |
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 'GetRemoteURL', | |
105 'GetRevisionDate', | 106 'GetRevisionDate', |
106 'GetUsableRev', | 107 'GetUsableRev', |
107 'Svnversion', | 108 'Svnversion', |
108 'RunCommand', | 109 'RunCommand', |
109 'cleanup', | 110 'cleanup', |
110 'diff', | 111 'diff', |
111 'name', | 112 'name', |
112 'pack', | 113 'pack', |
113 'relpath', | 114 'relpath', |
114 'revert', | 115 'revert', |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
685 | 686 |
686 self.mox.ReplayAll() | 687 self.mox.ReplayAll() |
687 | 688 |
688 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir) | 689 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir) |
689 # With an SVN checkout, 1 an example of a valid usable rev. | 690 # With an SVN checkout, 1 an example of a valid usable rev. |
690 self.assertEquals(svn_scm.GetUsableRev(1, options), 1) | 691 self.assertEquals(svn_scm.GetUsableRev(1, options), 1) |
691 # With an SVN checkout, a fake or unknown rev should raise an excpetion. | 692 # With an SVN checkout, a fake or unknown rev should raise an excpetion. |
692 self.assertRaises(gclient_scm.gclient_utils.Error, | 693 self.assertRaises(gclient_scm.gclient_utils.Error, |
693 svn_scm.GetUsableRev, 'fake', options) | 694 svn_scm.GetUsableRev, 'fake', options) |
694 | 695 |
696 def testGetRemoteURL(self): | |
697 options = self.Options(verbose=True) | |
698 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
699 relpath=self.relpath) | |
700 | |
701 if svn_scm.relpath: | |
702 cwd = os.path.join(svn_scm._root_dir, svn_scm.relpath) | |
703 else: | |
704 cwd = svn_scm._root_dir | |
705 | |
706 gclient_scm.scm.SVN.Capture(['info', os.curdir], cwd).AndReturn( | |
707 """ | |
708 Path: . | |
709 URL: %s | |
710 Repository Root: https://dummy.repo.com/svn | |
711 Repository UUID: FAKE | |
712 Revision: 1234 | |
713 Node Kind: directory | |
714 Schedule: normal | |
715 Last Changed Author: fakedev@chromium.org | |
716 Last Changed Rev: 1234 | |
717 Last Changed Date: 2013-11-11 15:12:34 -0500 (Mon, 11 Nov 2013) | |
718 """ % svn_scm.url) | |
719 | |
720 self.mox.ReplayAll() | |
721 | |
722 self.assertEquals(svn_scm.GetRemoteURL(options), self.url) | |
723 | |
724 | |
695 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, | 725 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, |
696 unittest.TestCase): | 726 unittest.TestCase): |
697 """This class doesn't use pymox.""" | 727 """This class doesn't use pymox.""" |
698 class OptionsObject(object): | 728 class OptionsObject(object): |
699 def __init__(self, verbose=False, revision=None): | 729 def __init__(self, verbose=False, revision=None): |
700 self.verbose = verbose | 730 self.verbose = verbose |
701 self.revision = revision | 731 self.revision = revision |
702 self.manually_grab_svn_rev = True | 732 self.manually_grab_svn_rev = True |
703 self.deps_os = None | 733 self.deps_os = None |
704 self.force = False | 734 self.force = False |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
806 rmtree(self.root_dir) | 836 rmtree(self.root_dir) |
807 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists | 837 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists |
808 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists | 838 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists |
809 | 839 |
810 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): | 840 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): |
811 def testDir(self): | 841 def testDir(self): |
812 members = [ | 842 members = [ |
813 'BinaryExists', | 843 'BinaryExists', |
814 'FullUrlForRelativeUrl', | 844 'FullUrlForRelativeUrl', |
815 'GetCheckoutRoot', | 845 'GetCheckoutRoot', |
846 'GetRemoteURL', | |
816 'GetRevisionDate', | 847 'GetRevisionDate', |
817 'GetUsableRev', | 848 'GetUsableRev', |
818 'RunCommand', | 849 'RunCommand', |
819 'cache_dir', | 850 'cache_dir', |
820 'cache_locks', | 851 'cache_locks', |
821 'cleanup', | 852 'cleanup', |
822 'diff', | 853 'diff', |
823 'name', | 854 'name', |
824 'pack', | 855 'pack', |
825 'UpdateSubmoduleConfig', | 856 'UpdateSubmoduleConfig', |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1173 self.assertEquals(git_svn_scm.GetUsableRev('3', options), | 1204 self.assertEquals(git_svn_scm.GetUsableRev('3', options), |
1174 self.fake_hash_2) | 1205 self.fake_hash_2) |
1175 # Given a git sha1 with a git-svn checkout, it should be used as is. | 1206 # Given a git sha1 with a git-svn checkout, it should be used as is. |
1176 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), | 1207 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), |
1177 self.fake_hash_1) | 1208 self.fake_hash_1) |
1178 # We currently check for seemingly valid SVN revisions by assuming 6 digit | 1209 # We currently check for seemingly valid SVN revisions by assuming 6 digit |
1179 # numbers, so assure that numeric revs >= 1000000 don't work. | 1210 # numbers, so assure that numeric revs >= 1000000 don't work. |
1180 self.assertRaises(gclient_scm.gclient_utils.Error, | 1211 self.assertRaises(gclient_scm.gclient_utils.Error, |
1181 git_svn_scm.GetUsableRev, too_big, options) | 1212 git_svn_scm.GetUsableRev, too_big, options) |
1182 | 1213 |
1214 def testGetRemoteURL(self): | |
1215 options = self.Options(verbose=True) | |
1216 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Capture', True) | |
1217 git_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
1218 relpath=self.relpath) | |
1219 git_scm._Capture(['remote', '-v']).AndReturn( | |
1220 """ | |
1221 origin %s (fetch) | |
1222 origin %s (push) | |
iannucci
2013/11/13 06:26:30
nit: you could do %(url)s in the string and then s
borenet
2013/11/13 19:12:24
Done. I'll leave the "origin" --> REMOTE_NAME refa
| |
1223 """ % (git_scm.url, git_scm.url)) | |
1224 | |
1225 self.mox.ReplayAll() | |
1226 | |
1227 self.assertEquals(git_scm.GetRemoteURL(options), self.url) | |
1228 | |
1183 | 1229 |
1184 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): | 1230 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): |
1185 def testUpdateUpdate(self): | 1231 def testUpdateUpdate(self): |
1186 if not self.enabled: | 1232 if not self.enabled: |
1187 return | 1233 return |
1188 options = self.Options() | 1234 options = self.Options() |
1189 expected_file_list = [] | 1235 expected_file_list = [] |
1190 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 1236 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
1191 relpath=self.relpath) | 1237 relpath=self.relpath) |
1192 file_list = [] | 1238 file_list = [] |
1193 options.revision = 'unmanaged' | 1239 options.revision = 'unmanaged' |
1194 scm.update(options, (), file_list) | 1240 scm.update(options, (), file_list) |
1195 self.assertEquals(file_list, expected_file_list) | 1241 self.assertEquals(file_list, expected_file_list) |
1196 self.assertEquals(scm.revinfo(options, (), None), | 1242 self.assertEquals(scm.revinfo(options, (), None), |
1197 '069c602044c5388d2d15c3f875b057c852003458') | 1243 '069c602044c5388d2d15c3f875b057c852003458') |
1198 self.checkstdout('________ unmanaged solution; skipping .\n') | 1244 self.checkstdout('________ unmanaged solution; skipping .\n') |
1199 | 1245 |
1200 | 1246 |
1201 if __name__ == '__main__': | 1247 if __name__ == '__main__': |
1202 if '-v' in sys.argv: | 1248 if '-v' in sys.argv: |
1203 logging.basicConfig( | 1249 logging.basicConfig( |
1204 level=logging.DEBUG, | 1250 level=logging.DEBUG, |
1205 format='%(asctime).19s %(levelname)s %(filename)s:' | 1251 format='%(asctime).19s %(levelname)s %(filename)s:' |
1206 '%(lineno)s %(message)s') | 1252 '%(lineno)s %(message)s') |
1207 unittest.main() | 1253 unittest.main() |
1208 | 1254 |
1209 # vim: ts=2:sw=2:tw=80:et: | 1255 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |