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 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 # Pretend like the git-svn repo's HEAD is at r2. | 1031 # Pretend like the git-svn repo's HEAD is at r2. |
1032 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'GetGitSvnHeadRev', True) | 1032 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'GetGitSvnHeadRev', True) |
1033 gclient_scm.scm.GIT.GetGitSvnHeadRev(cwd=self.base_path).MultipleTimes( | 1033 gclient_scm.scm.GIT.GetGitSvnHeadRev(cwd=self.base_path).MultipleTimes( |
1034 ).AndReturn(2) | 1034 ).AndReturn(2) |
1035 | 1035 |
1036 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'GetSha1ForSvnRev', True) | 1036 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'GetSha1ForSvnRev', True) |
1037 # r1 -> first fake hash, r3 -> second fake hash. | 1037 # r1 -> first fake hash, r3 -> second fake hash. |
1038 gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='1' | 1038 gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='1' |
1039 ).AndReturn(self.fake_hash_1) | 1039 ).AndReturn(self.fake_hash_1) |
1040 gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='3' | 1040 gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='3' |
1041 ).AndReturn(self.fake_hash_2) | 1041 ).MultipleTimes().AndReturn(self.fake_hash_2) |
1042 | 1042 |
1043 # Ensure that we call git svn fetch if our LKGR is > the git-svn HEAD rev. | 1043 # Ensure that we call git svn fetch if our LKGR is > the git-svn HEAD rev. |
1044 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True) | 1044 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True) |
| 1045 gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], |
| 1046 cwd=self.base_path).AndReturn('blah') |
| 1047 gclient_scm.scm.GIT.Capture(['fetch'], cwd=self.base_path) |
| 1048 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path) |
| 1049 gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], |
| 1050 cwd=self.base_path).AndReturn('') |
1045 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path) | 1051 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path) |
1046 | 1052 |
1047 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 1053 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) |
1048 gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( | 1054 gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( |
1049 ).AndReturn(True) | 1055 ).AndReturn(True) |
1050 | 1056 |
1051 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) | 1057 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) |
1052 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 | 1058 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 |
1053 ).AndReturn(True) | 1059 ).AndReturn(True) |
1054 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=too_big | 1060 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=too_big |
1055 ).AndReturn(False) | 1061 ).AndReturn(False) |
1056 | 1062 |
1057 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 1063 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
1058 gclient_scm.os.path.isdir(self.base_path).MultipleTimes().AndReturn(True) | 1064 gclient_scm.os.path.isdir(self.base_path).MultipleTimes().AndReturn(True) |
1059 | 1065 |
1060 self.mox.ReplayAll() | 1066 self.mox.ReplayAll() |
1061 | 1067 |
1062 git_svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 1068 git_svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
1063 relpath=self.relpath) | 1069 relpath=self.relpath) |
1064 # Without an existing checkout, this should fail. TODO(dbeam) Fix this. | 1070 # Without an existing checkout, this should fail. |
| 1071 # TODO(dbeam) Fix this. http://crbug.com/109184 |
1065 self.assertRaises(gclient_scm.gclient_utils.Error, | 1072 self.assertRaises(gclient_scm.gclient_utils.Error, |
1066 git_svn_scm.GetUsableRev, '1', options) | 1073 git_svn_scm.GetUsableRev, '1', options) |
1067 # Given an SVN revision with a git-svn checkout, it should be translated to | 1074 # Given an SVN revision with a git-svn checkout, it should be translated to |
1068 # a git sha1 and be usable. | 1075 # a git sha1 and be usable. |
1069 self.assertEquals(git_svn_scm.GetUsableRev('1', options), | 1076 self.assertEquals(git_svn_scm.GetUsableRev('1', options), |
1070 self.fake_hash_1) | 1077 self.fake_hash_1) |
1071 # Our fake HEAD rev is r2, so this should call git svn fetch to get more | 1078 # Our fake HEAD rev is r2, so this should call git fetch and git svn fetch |
1072 # revs (pymox will complain if this doesn't happen). | 1079 # to get more revs (pymox will complain if this doesn't happen). We mock an |
| 1080 # optimized checkout the first time, so this run should call git fetch. |
| 1081 self.assertEquals(git_svn_scm.GetUsableRev('3', options), |
| 1082 self.fake_hash_2) |
| 1083 # The time we pretend we're not optimized, so no git fetch should fire. |
1073 self.assertEquals(git_svn_scm.GetUsableRev('3', options), | 1084 self.assertEquals(git_svn_scm.GetUsableRev('3', options), |
1074 self.fake_hash_2) | 1085 self.fake_hash_2) |
1075 # Given a git sha1 with a git-svn checkout, it should be used as is. | 1086 # Given a git sha1 with a git-svn checkout, it should be used as is. |
1076 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), | 1087 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), |
1077 self.fake_hash_1) | 1088 self.fake_hash_1) |
1078 # We currently check for seemingly valid SVN revisions by assuming 6 digit | 1089 # We currently check for seemingly valid SVN revisions by assuming 6 digit |
1079 # numbers, so assure that numeric revs >= 1000000 don't work. | 1090 # numbers, so assure that numeric revs >= 1000000 don't work. |
1080 self.assertRaises(gclient_scm.gclient_utils.Error, | 1091 self.assertRaises(gclient_scm.gclient_utils.Error, |
1081 git_svn_scm.GetUsableRev, too_big, options) | 1092 git_svn_scm.GetUsableRev, too_big, options) |
1082 | 1093 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 | 1154 |
1144 if __name__ == '__main__': | 1155 if __name__ == '__main__': |
1145 if '-v' in sys.argv: | 1156 if '-v' in sys.argv: |
1146 logging.basicConfig( | 1157 logging.basicConfig( |
1147 level=logging.DEBUG, | 1158 level=logging.DEBUG, |
1148 format='%(asctime).19s %(levelname)s %(filename)s:' | 1159 format='%(asctime).19s %(levelname)s %(filename)s:' |
1149 '%(lineno)s %(message)s') | 1160 '%(lineno)s %(message)s') |
1150 unittest.main() | 1161 unittest.main() |
1151 | 1162 |
1152 # vim: ts=2:sw=2:tw=80:et: | 1163 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |