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 self.mox.UnsetStubs() | |
698 options = self.Options(verbose=True) | |
699 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture', True) | |
borenet
2013/11/25 13:55:42
The test failed without adding these lines, presum
| |
700 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
701 relpath=self.relpath) | |
702 | |
703 if svn_scm.relpath: | |
704 cwd = os.path.join(svn_scm._root_dir, svn_scm.relpath) | |
705 else: | |
706 cwd = svn_scm._root_dir | |
707 | |
708 gclient_scm.scm.SVN.Capture(['info', '--xml', os.curdir], cwd).AndReturn( | |
709 """<?xml version="1.0"?> | |
710 <info> | |
711 <entry | |
712 path="." | |
713 revision="1234" | |
714 kind="dir"> | |
715 <url>%s</url> | |
716 <repository> | |
717 <root>https://dummy.repo.com/svn</root> | |
718 <uuid>FAKE</uuid> | |
719 </repository> | |
720 <wc-info> | |
721 <schedule>normal</schedule> | |
722 <depth>infinity</depth> | |
723 </wc-info> | |
724 <commit | |
725 revision="1234"> | |
726 <author>fakedev@chromium.org</author> | |
727 <date>2013-11-14T15:08:21.757885Z</date> | |
728 </commit> | |
729 </entry> | |
730 </info> | |
731 """ % svn_scm.url) | |
732 | |
733 self.mox.ReplayAll() | |
734 | |
735 self.assertEquals(svn_scm.GetRemoteURL(options), self.url) | |
736 | |
737 | |
695 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, | 738 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, |
696 unittest.TestCase): | 739 unittest.TestCase): |
697 """This class doesn't use pymox.""" | 740 """This class doesn't use pymox.""" |
698 class OptionsObject(object): | 741 class OptionsObject(object): |
699 def __init__(self, verbose=False, revision=None): | 742 def __init__(self, verbose=False, revision=None): |
700 self.verbose = verbose | 743 self.verbose = verbose |
701 self.revision = revision | 744 self.revision = revision |
702 self.manually_grab_svn_rev = True | 745 self.manually_grab_svn_rev = True |
703 self.deps_os = None | 746 self.deps_os = None |
704 self.force = False | 747 self.force = False |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
806 rmtree(self.root_dir) | 849 rmtree(self.root_dir) |
807 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists | 850 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists |
808 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists | 851 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists |
809 | 852 |
810 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): | 853 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): |
811 def testDir(self): | 854 def testDir(self): |
812 members = [ | 855 members = [ |
813 'BinaryExists', | 856 'BinaryExists', |
814 'FullUrlForRelativeUrl', | 857 'FullUrlForRelativeUrl', |
815 'GetCheckoutRoot', | 858 'GetCheckoutRoot', |
859 'GetRemoteURL', | |
816 'GetRevisionDate', | 860 'GetRevisionDate', |
817 'GetUsableRev', | 861 'GetUsableRev', |
818 'RunCommand', | 862 'RunCommand', |
819 'cache_dir', | 863 'cache_dir', |
820 'cache_locks', | 864 'cache_locks', |
821 'cleanup', | 865 'cleanup', |
822 'diff', | 866 'diff', |
823 'name', | 867 'name', |
824 'pack', | 868 'pack', |
825 'UpdateSubmoduleConfig', | 869 'UpdateSubmoduleConfig', |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1173 self.assertEquals(git_svn_scm.GetUsableRev('3', options), | 1217 self.assertEquals(git_svn_scm.GetUsableRev('3', options), |
1174 self.fake_hash_2) | 1218 self.fake_hash_2) |
1175 # Given a git sha1 with a git-svn checkout, it should be used as is. | 1219 # 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), | 1220 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), |
1177 self.fake_hash_1) | 1221 self.fake_hash_1) |
1178 # We currently check for seemingly valid SVN revisions by assuming 6 digit | 1222 # We currently check for seemingly valid SVN revisions by assuming 6 digit |
1179 # numbers, so assure that numeric revs >= 1000000 don't work. | 1223 # numbers, so assure that numeric revs >= 1000000 don't work. |
1180 self.assertRaises(gclient_scm.gclient_utils.Error, | 1224 self.assertRaises(gclient_scm.gclient_utils.Error, |
1181 git_svn_scm.GetUsableRev, too_big, options) | 1225 git_svn_scm.GetUsableRev, too_big, options) |
1182 | 1226 |
1227 def testGetRemoteURL(self): | |
1228 options = self.Options(verbose=True) | |
1229 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Capture', True) | |
1230 git_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
1231 relpath=self.relpath) | |
1232 git_scm._Capture(['config', 'remote.origin.url'], cwd='/tmp/fake' | |
1233 ).AndReturn('%s\n' % git_scm.url) | |
1234 | |
1235 self.mox.ReplayAll() | |
1236 | |
1237 self.assertEquals(git_scm.GetRemoteURL(options), self.url) | |
1238 | |
1183 | 1239 |
1184 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): | 1240 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): |
1185 def testUpdateUpdate(self): | 1241 def testUpdateUpdate(self): |
1186 if not self.enabled: | 1242 if not self.enabled: |
1187 return | 1243 return |
1188 options = self.Options() | 1244 options = self.Options() |
1189 expected_file_list = [] | 1245 expected_file_list = [] |
1190 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 1246 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
1191 relpath=self.relpath) | 1247 relpath=self.relpath) |
1192 file_list = [] | 1248 file_list = [] |
1193 options.revision = 'unmanaged' | 1249 options.revision = 'unmanaged' |
1194 scm.update(options, (), file_list) | 1250 scm.update(options, (), file_list) |
1195 self.assertEquals(file_list, expected_file_list) | 1251 self.assertEquals(file_list, expected_file_list) |
1196 self.assertEquals(scm.revinfo(options, (), None), | 1252 self.assertEquals(scm.revinfo(options, (), None), |
1197 '069c602044c5388d2d15c3f875b057c852003458') | 1253 '069c602044c5388d2d15c3f875b057c852003458') |
1198 self.checkstdout('________ unmanaged solution; skipping .\n') | 1254 self.checkstdout('________ unmanaged solution; skipping .\n') |
1199 | 1255 |
1200 | 1256 |
1201 if __name__ == '__main__': | 1257 if __name__ == '__main__': |
1202 if '-v' in sys.argv: | 1258 if '-v' in sys.argv: |
1203 logging.basicConfig( | 1259 logging.basicConfig( |
1204 level=logging.DEBUG, | 1260 level=logging.DEBUG, |
1205 format='%(asctime).19s %(levelname)s %(filename)s:' | 1261 format='%(asctime).19s %(levelname)s %(filename)s:' |
1206 '%(lineno)s %(message)s') | 1262 '%(lineno)s %(message)s') |
1207 unittest.main() | 1263 unittest.main() |
1208 | 1264 |
1209 # vim: ts=2:sw=2:tw=80:et: | 1265 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |