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