OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright 2008-2009 Google Inc. All Rights Reserved. | 3 # Copyright 2008-2009 Google Inc. All Rights Reserved. |
4 # | 4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
8 # | 8 # |
9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
10 # | 10 # |
11 # Unless required by applicable law or agreed to in writing, software | 11 # Unless required by applicable law or agreed to in writing, software |
12 # distributed under the License is distributed on an "AS IS" BASIS, | 12 # distributed under the License is distributed on an "AS IS" BASIS, |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 # See the License for the specific language governing permissions and | 14 # See the License for the specific language governing permissions and |
15 # limitations under the License. | 15 # limitations under the License. |
16 | 16 |
17 """Unit tests for gclient_scm.py.""" | 17 """Unit tests for gclient_scm.py.""" |
18 | 18 |
19 import os | |
20 import shutil | 19 import shutil |
21 import subprocess | 20 # Import it before super_mox to keep a valid reference. |
| 21 from subprocess import Popen, PIPE, STDOUT |
22 import tempfile | 22 import tempfile |
23 import unittest | |
24 | 23 |
25 import gclient | |
26 import gclient_scm | 24 import gclient_scm |
27 import gclient_test | 25 from gclient_test import BaseTestCase as GCBaseTestCase |
28 import gclient_utils | 26 from super_mox import mox, SuperMoxBaseTestBase |
29 from super_mox import mox | |
30 | 27 |
31 | 28 |
32 class SVNWrapperTestCase(gclient_test.GClientBaseTestCase): | 29 class BaseTestCase(GCBaseTestCase): |
| 30 def setUp(self): |
| 31 GCBaseTestCase.setUp(self) |
| 32 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') |
| 33 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') |
| 34 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'SubprocessCall') |
| 35 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') |
| 36 self._CaptureSVNInfo = gclient_scm.CaptureSVNInfo |
| 37 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVN') |
| 38 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNInfo') |
| 39 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNStatus') |
| 40 self.mox.StubOutWithMock(gclient_scm, 'RunSVN') |
| 41 self.mox.StubOutWithMock(gclient_scm, 'RunSVNAndGetFileList') |
| 42 self._scm_wrapper = gclient_scm.CreateSCM |
| 43 |
| 44 |
| 45 class SVNWrapperTestCase(BaseTestCase): |
33 class OptionsObject(object): | 46 class OptionsObject(object): |
34 def __init__(self, test_case, verbose=False, revision=None): | 47 def __init__(self, test_case, verbose=False, revision=None): |
35 self.verbose = verbose | 48 self.verbose = verbose |
36 self.revision = revision | 49 self.revision = revision |
37 self.manually_grab_svn_rev = True | 50 self.manually_grab_svn_rev = True |
38 self.deps_os = None | 51 self.deps_os = None |
39 self.force = False | 52 self.force = False |
40 self.nohooks = False | 53 self.nohooks = False |
41 | 54 |
| 55 def Options(self, *args, **kwargs): |
| 56 return self.OptionsObject(self, *args, **kwargs) |
| 57 |
42 def setUp(self): | 58 def setUp(self): |
43 gclient_test.GClientBaseTestCase.setUp(self) | 59 BaseTestCase.setUp(self) |
44 self.root_dir = self.Dir() | 60 self.root_dir = self.Dir() |
45 self.args = self.Args() | 61 self.args = self.Args() |
46 self.url = self.Url() | 62 self.url = self.Url() |
47 self.relpath = 'asf' | 63 self.relpath = 'asf' |
48 | 64 |
49 def testDir(self): | 65 def testDir(self): |
50 members = [ | 66 members = [ |
51 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', | 67 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', |
52 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', | 68 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', |
53 'update', 'url', | 69 'update', 'url', |
(...skipping 11 matching lines...) Expand all Loading... |
65 def testFullUrlForRelativeUrl(self): | 81 def testFullUrlForRelativeUrl(self): |
66 self.url = 'svn://a/b/c/d' | 82 self.url = 'svn://a/b/c/d' |
67 | 83 |
68 self.mox.ReplayAll() | 84 self.mox.ReplayAll() |
69 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 85 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
70 relpath=self.relpath) | 86 relpath=self.relpath) |
71 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') | 87 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') |
72 | 88 |
73 def testRunCommandException(self): | 89 def testRunCommandException(self): |
74 options = self.Options(verbose=False) | 90 options = self.Options(verbose=False) |
75 file_path = os.path.join(self.root_dir, self.relpath, '.git') | 91 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
76 gclient.os.path.exists(file_path).AndReturn(False) | 92 gclient_scm.os.path.exists(file_path).AndReturn(False) |
77 | 93 |
78 self.mox.ReplayAll() | 94 self.mox.ReplayAll() |
79 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 95 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
80 relpath=self.relpath) | 96 relpath=self.relpath) |
81 exception = "Unsupported argument(s): %s" % ','.join(self.args) | 97 exception = "Unsupported argument(s): %s" % ','.join(self.args) |
82 self.assertRaisesError(exception, scm.RunCommand, | 98 self.assertRaisesError(exception, scm.RunCommand, |
83 'update', options, self.args) | 99 'update', options, self.args) |
84 | 100 |
85 def testRunCommandUnknown(self): | 101 def testRunCommandUnknown(self): |
86 # TODO(maruel): if ever used. | 102 # TODO(maruel): if ever used. |
87 pass | 103 pass |
88 | 104 |
89 def testRevertMissing(self): | 105 def testRevertMissing(self): |
90 options = self.Options(verbose=True) | 106 options = self.Options(verbose=True) |
91 base_path = os.path.join(self.root_dir, self.relpath) | 107 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
92 gclient.os.path.isdir(base_path).AndReturn(False) | 108 gclient_scm.os.path.isdir(base_path).AndReturn(False) |
93 # It'll to a checkout instead. | 109 # It'll to a checkout instead. |
94 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) | 110 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 111 ).AndReturn(False) |
95 print("\n_____ %s is missing, synching instead" % self.relpath) | 112 print("\n_____ %s is missing, synching instead" % self.relpath) |
96 # Checkout. | 113 # Checkout. |
97 gclient.os.path.exists(base_path).AndReturn(False) | 114 gclient_scm.os.path.exists(base_path).AndReturn(False) |
98 files_list = self.mox.CreateMockAnything() | 115 files_list = self.mox.CreateMockAnything() |
99 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, base_path], | 116 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, base_path], |
100 self.root_dir, files_list) | 117 self.root_dir, files_list) |
101 | 118 |
102 self.mox.ReplayAll() | 119 self.mox.ReplayAll() |
103 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 120 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
104 relpath=self.relpath) | 121 relpath=self.relpath) |
105 scm.revert(options, self.args, files_list) | 122 scm.revert(options, self.args, files_list) |
106 | 123 |
107 def testRevertNone(self): | 124 def testRevertNone(self): |
108 options = self.Options(verbose=True) | 125 options = self.Options(verbose=True) |
109 base_path = os.path.join(self.root_dir, self.relpath) | 126 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
110 gclient.os.path.isdir(base_path).AndReturn(True) | 127 gclient_scm.os.path.isdir(base_path).AndReturn(True) |
111 gclient_scm.CaptureSVNStatus(base_path).AndReturn([]) | 128 gclient_scm.CaptureSVNStatus(base_path).AndReturn([]) |
112 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], | 129 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], |
113 base_path, mox.IgnoreArg()) | 130 base_path, mox.IgnoreArg()) |
114 | 131 |
115 self.mox.ReplayAll() | 132 self.mox.ReplayAll() |
116 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 133 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
117 relpath=self.relpath) | 134 relpath=self.relpath) |
118 file_list = [] | 135 file_list = [] |
119 scm.revert(options, self.args, file_list) | 136 scm.revert(options, self.args, file_list) |
120 | 137 |
121 def testRevert2Files(self): | 138 def testRevert2Files(self): |
122 options = self.Options(verbose=True) | 139 options = self.Options(verbose=True) |
123 base_path = os.path.join(self.root_dir, self.relpath) | 140 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
124 gclient.os.path.isdir(base_path).AndReturn(True) | 141 gclient_scm.os.path.isdir(base_path).AndReturn(True) |
125 items = [ | 142 items = [ |
126 ('M ', 'a'), | 143 ('M ', 'a'), |
127 ('A ', 'b'), | 144 ('A ', 'b'), |
128 ] | 145 ] |
129 file_path1 = os.path.join(base_path, 'a') | 146 file_path1 = gclient_scm.os.path.join(base_path, 'a') |
130 file_path2 = os.path.join(base_path, 'b') | 147 file_path2 = gclient_scm.os.path.join(base_path, 'b') |
131 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) | 148 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) |
132 gclient_scm.os.path.exists(file_path1).AndReturn(True) | 149 gclient_scm.os.path.exists(file_path1).AndReturn(True) |
133 gclient_scm.os.path.isfile(file_path1).AndReturn(True) | 150 gclient_scm.os.path.isfile(file_path1).AndReturn(True) |
134 gclient_scm.os.remove(file_path1) | 151 gclient_scm.os.remove(file_path1) |
135 gclient_scm.os.path.exists(file_path2).AndReturn(True) | 152 gclient_scm.os.path.exists(file_path2).AndReturn(True) |
136 gclient_scm.os.path.isfile(file_path2).AndReturn(True) | 153 gclient_scm.os.path.isfile(file_path2).AndReturn(True) |
137 gclient_scm.os.remove(file_path2) | 154 gclient_scm.os.remove(file_path2) |
138 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], | 155 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], |
139 base_path, mox.IgnoreArg()) | 156 base_path, mox.IgnoreArg()) |
140 print(os.path.join(base_path, 'a')) | 157 print(gclient_scm.os.path.join(base_path, 'a')) |
141 print(os.path.join(base_path, 'b')) | 158 print(gclient_scm.os.path.join(base_path, 'b')) |
142 | 159 |
143 self.mox.ReplayAll() | 160 self.mox.ReplayAll() |
144 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 161 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
145 relpath=self.relpath) | 162 relpath=self.relpath) |
146 file_list = [] | 163 file_list = [] |
147 scm.revert(options, self.args, file_list) | 164 scm.revert(options, self.args, file_list) |
148 | 165 |
149 def testRevertDirectory(self): | 166 def testRevertDirectory(self): |
150 options = self.Options(verbose=True) | 167 options = self.Options(verbose=True) |
151 base_path = os.path.join(self.root_dir, self.relpath) | 168 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
152 gclient.os.path.isdir(base_path).AndReturn(True) | 169 gclient_scm.os.path.isdir(base_path).AndReturn(True) |
153 items = [ | 170 items = [ |
154 ('~ ', 'a'), | 171 ('~ ', 'a'), |
155 ] | 172 ] |
156 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) | 173 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) |
157 file_path = os.path.join(base_path, 'a') | 174 file_path = gclient_scm.os.path.join(base_path, 'a') |
158 print(file_path) | 175 print(file_path) |
159 gclient_scm.os.path.exists(file_path).AndReturn(True) | 176 gclient_scm.os.path.exists(file_path).AndReturn(True) |
160 gclient_scm.os.path.isfile(file_path).AndReturn(False) | 177 gclient_scm.os.path.isfile(file_path).AndReturn(False) |
161 gclient_scm.os.path.isdir(file_path).AndReturn(True) | 178 gclient_scm.os.path.isdir(file_path).AndReturn(True) |
162 gclient_utils.RemoveDirectory(file_path) | 179 gclient_scm.gclient_utils.RemoveDirectory(file_path) |
163 file_list1 = [] | 180 file_list1 = [] |
164 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], | 181 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], |
165 base_path, mox.IgnoreArg()) | 182 base_path, mox.IgnoreArg()) |
166 | 183 |
167 self.mox.ReplayAll() | 184 self.mox.ReplayAll() |
168 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 185 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
169 relpath=self.relpath) | 186 relpath=self.relpath) |
170 file_list2 = [] | 187 file_list2 = [] |
171 scm.revert(options, self.args, file_list2) | 188 scm.revert(options, self.args, file_list2) |
172 | 189 |
173 def testStatus(self): | 190 def testStatus(self): |
174 options = self.Options(verbose=True) | 191 options = self.Options(verbose=True) |
175 base_path = os.path.join(self.root_dir, self.relpath) | 192 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
176 gclient.os.path.isdir(base_path).AndReturn(True) | 193 gclient_scm.os.path.isdir(base_path).AndReturn(True) |
177 gclient_scm.RunSVNAndGetFileList(options, ['status'] + self.args, | 194 gclient_scm.RunSVNAndGetFileList(options, ['status'] + self.args, |
178 base_path, []).AndReturn(None) | 195 base_path, []).AndReturn(None) |
179 | 196 |
180 self.mox.ReplayAll() | 197 self.mox.ReplayAll() |
181 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 198 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
182 relpath=self.relpath) | 199 relpath=self.relpath) |
183 file_list = [] | 200 file_list = [] |
184 self.assertEqual(scm.status(options, self.args, file_list), None) | 201 self.assertEqual(scm.status(options, self.args, file_list), None) |
185 | 202 |
186 | 203 |
187 # TODO(maruel): TEST REVISIONS!!! | 204 # TODO(maruel): TEST REVISIONS!!! |
188 # TODO(maruel): TEST RELOCATE!!! | 205 # TODO(maruel): TEST RELOCATE!!! |
189 def testUpdateCheckout(self): | 206 def testUpdateCheckout(self): |
190 options = self.Options(verbose=True) | 207 options = self.Options(verbose=True) |
191 base_path = os.path.join(self.root_dir, self.relpath) | 208 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
192 file_info = gclient_utils.PrintableObject() | 209 file_info = gclient_scm.gclient_utils.PrintableObject() |
193 file_info.root = 'blah' | 210 file_info.root = 'blah' |
194 file_info.url = self.url | 211 file_info.url = self.url |
195 file_info.uuid = 'ABC' | 212 file_info.uuid = 'ABC' |
196 file_info.revision = 42 | 213 file_info.revision = 42 |
197 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) | 214 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 215 ).AndReturn(False) |
198 # Checkout. | 216 # Checkout. |
199 gclient.os.path.exists(base_path).AndReturn(False) | 217 gclient_scm.os.path.exists(base_path).AndReturn(False) |
200 files_list = self.mox.CreateMockAnything() | 218 files_list = self.mox.CreateMockAnything() |
201 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, | 219 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, |
202 base_path], self.root_dir, files_list) | 220 base_path], self.root_dir, files_list) |
203 self.mox.ReplayAll() | 221 self.mox.ReplayAll() |
204 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 222 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
205 relpath=self.relpath) | 223 relpath=self.relpath) |
206 scm.update(options, (), files_list) | 224 scm.update(options, (), files_list) |
207 | 225 |
208 def testUpdateUpdate(self): | 226 def testUpdateUpdate(self): |
209 options = self.Options(verbose=True) | 227 options = self.Options(verbose=True) |
210 base_path = os.path.join(self.root_dir, self.relpath) | 228 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
211 options.force = True | 229 options.force = True |
212 options.nohooks = False | 230 options.nohooks = False |
213 file_info = { | 231 file_info = { |
214 'Repository Root': 'blah', | 232 'Repository Root': 'blah', |
215 'URL': self.url, | 233 'URL': self.url, |
216 'UUID': 'ABC', | 234 'UUID': 'ABC', |
217 'Revision': 42, | 235 'Revision': 42, |
218 } | 236 } |
219 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) | 237 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 238 ).AndReturn(False) |
220 # Checkout or update. | 239 # Checkout or update. |
221 gclient.os.path.exists(base_path).AndReturn(True) | 240 gclient_scm.os.path.exists(base_path).AndReturn(True) |
222 gclient_scm.CaptureSVNInfo(os.path.join(base_path, "."), '.' | 241 gclient_scm.CaptureSVNInfo(gclient_scm.os.path.join(base_path, "."), '.' |
223 ).AndReturn(file_info) | 242 ).AndReturn(file_info) |
224 # Cheat a bit here. | 243 # Cheat a bit here. |
225 gclient_scm.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) | 244 gclient_scm.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) |
226 additional_args = [] | 245 additional_args = [] |
227 if options.manually_grab_svn_rev: | 246 if options.manually_grab_svn_rev: |
228 additional_args = ['--revision', str(file_info['Revision'])] | 247 additional_args = ['--revision', str(file_info['Revision'])] |
229 files_list = [] | 248 files_list = [] |
230 gclient_scm.RunSVNAndGetFileList(options, | 249 gclient_scm.RunSVNAndGetFileList(options, |
231 ['update', base_path] + additional_args, | 250 ['update', base_path] + additional_args, |
232 self.root_dir, files_list) | 251 self.root_dir, files_list) |
233 | 252 |
234 self.mox.ReplayAll() | 253 self.mox.ReplayAll() |
235 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 254 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
236 relpath=self.relpath) | 255 relpath=self.relpath) |
237 scm.update(options, (), files_list) | 256 scm.update(options, (), files_list) |
238 | 257 |
239 def testUpdateGit(self): | 258 def testUpdateGit(self): |
240 options = self.Options(verbose=True) | 259 options = self.Options(verbose=True) |
241 file_path = os.path.join(self.root_dir, self.relpath, '.git') | 260 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
242 gclient.os.path.exists(file_path).AndReturn(True) | 261 gclient_scm.os.path.exists(file_path).AndReturn(True) |
243 print("________ found .git directory; skipping %s" % self.relpath) | 262 print("________ found .git directory; skipping %s" % self.relpath) |
244 | 263 |
245 self.mox.ReplayAll() | 264 self.mox.ReplayAll() |
246 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 265 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
247 relpath=self.relpath) | 266 relpath=self.relpath) |
248 file_list = [] | 267 file_list = [] |
249 scm.update(options, self.args, file_list) | 268 scm.update(options, self.args, file_list) |
250 | 269 |
251 def testGetSVNFileInfo(self): | 270 def testGetSVNFileInfo(self): |
252 xml_text = r"""<?xml version="1.0"?> | 271 xml_text = r"""<?xml version="1.0"?> |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 <depth>infinity</depth> | 360 <depth>infinity</depth> |
342 </wc-info> | 361 </wc-info> |
343 <commit | 362 <commit |
344 revision="35"> | 363 revision="35"> |
345 <author>maruel</author> | 364 <author>maruel</author> |
346 <date>2008-12-04T20:12:19.685120Z</date> | 365 <date>2008-12-04T20:12:19.685120Z</date> |
347 </commit> | 366 </commit> |
348 </entry> | 367 </entry> |
349 </info> | 368 </info> |
350 """ % (self.url, self.root_dir) | 369 """ % (self.url, self.root_dir) |
351 gclient_scm.CaptureSVN(['info', '--xml', | 370 gclient_scm.os.getcwd().AndReturn('bleh') |
352 self.url], os.getcwd()).AndReturn(xml_text) | 371 gclient_scm.CaptureSVN(['info', '--xml', self.url], 'bleh' |
| 372 ).AndReturn(xml_text) |
353 self.mox.ReplayAll() | 373 self.mox.ReplayAll() |
354 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 374 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
355 relpath=self.relpath) | 375 relpath=self.relpath) |
356 rev_info = scm.revinfo(options, self.args, None) | 376 rev_info = scm.revinfo(options, self.args, None) |
357 self.assertEqual(rev_info, '35') | 377 self.assertEqual(rev_info, '35') |
358 | 378 |
359 | 379 |
360 class GitWrapperTestCase(gclient_test.GClientBaseTestCase): | 380 class GitWrapperTestCase(SuperMoxBaseTestBase): |
| 381 """This class doesn't use pymox.""" |
361 class OptionsObject(object): | 382 class OptionsObject(object): |
362 def __init__(self, test_case, verbose=False, revision=None): | 383 def __init__(self, test_case, verbose=False, revision=None): |
363 self.verbose = verbose | 384 self.verbose = verbose |
364 self.revision = revision | 385 self.revision = revision |
365 self.manually_grab_svn_rev = True | 386 self.manually_grab_svn_rev = True |
366 self.deps_os = None | 387 self.deps_os = None |
367 self.force = False | 388 self.force = False |
368 self.nohooks = False | 389 self.nohooks = False |
369 | 390 |
370 sample_git_import = """blob | 391 sample_git_import = """blob |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 M 100644 :5 b | 431 M 100644 :5 b |
411 | 432 |
412 reset refs/heads/master | 433 reset refs/heads/master |
413 from :3 | 434 from :3 |
414 """ | 435 """ |
415 def Options(self, *args, **kwargs): | 436 def Options(self, *args, **kwargs): |
416 return self.OptionsObject(self, *args, **kwargs) | 437 return self.OptionsObject(self, *args, **kwargs) |
417 | 438 |
418 def CreateGitRepo(self, git_import, path): | 439 def CreateGitRepo(self, git_import, path): |
419 try: | 440 try: |
420 subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE, | 441 Popen(['git', 'init'], stdout=PIPE, stderr=STDOUT, |
421 stderr=subprocess.STDOUT, cwd=path).communicate() | 442 cwd=path).communicate() |
422 except WindowsError: | 443 except OSError: |
423 # git is not available, skip this test. | 444 # git is not available, skip this test. |
424 return False | 445 return False |
425 subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE, | 446 Popen(['git', 'fast-import'], stdin=PIPE, stdout=PIPE, stderr=STDOUT, |
426 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | 447 cwd=path).communicate(input=git_import) |
427 cwd=path).communicate(input=git_import) | 448 Popen(['git', 'checkout'], stdout=PIPE, stderr=STDOUT, |
428 subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE, | 449 cwd=path).communicate() |
429 stderr=subprocess.STDOUT, cwd=path).communicate() | |
430 return True | 450 return True |
431 | 451 |
432 def setUp(self): | 452 def setUp(self): |
433 gclient_test.BaseTestCase.setUp(self) | |
434 self.args = self.Args() | 453 self.args = self.Args() |
435 self.url = 'git://foo' | 454 self.url = 'git://foo' |
436 self.root_dir = tempfile.mkdtemp() | 455 self.root_dir = tempfile.mkdtemp() |
437 self.relpath = '.' | 456 self.relpath = '.' |
438 self.base_path = os.path.join(self.root_dir, self.relpath) | 457 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
439 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) | 458 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) |
| 459 SuperMoxBaseTestBase.setUp(self) |
440 | 460 |
441 def tearDown(self): | 461 def tearDown(self): |
| 462 SuperMoxBaseTestBase.tearDown(self) |
442 shutil.rmtree(self.root_dir) | 463 shutil.rmtree(self.root_dir) |
443 gclient_test.BaseTestCase.tearDown(self) | |
444 | 464 |
445 def testDir(self): | 465 def testDir(self): |
446 members = [ | 466 members = [ |
447 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', | 467 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', |
448 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', | 468 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', |
449 'update', 'url', | 469 'update', 'url', |
450 ] | 470 ] |
451 | 471 |
452 # If you add a member, be sure to add the relevant test! | 472 # If you add a member, be sure to add the relevant test! |
453 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) | 473 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) |
454 | 474 |
455 def testRevertMissing(self): | 475 def testRevertMissing(self): |
456 if not self.enabled: | 476 if not self.enabled: |
457 return | 477 return |
458 options = self.Options() | 478 options = self.Options() |
459 file_path = os.path.join(self.base_path, 'a') | 479 file_path = gclient_scm.os.path.join(self.base_path, 'a') |
460 os.remove(file_path) | 480 gclient_scm.os.remove(file_path) |
461 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 481 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
462 relpath=self.relpath) | 482 relpath=self.relpath) |
463 file_list = [] | 483 file_list = [] |
464 scm.revert(options, self.args, file_list) | 484 scm.revert(options, self.args, file_list) |
465 self.assertEquals(file_list, [file_path]) | 485 self.assertEquals(file_list, [file_path]) |
466 file_list = [] | 486 file_list = [] |
467 scm.diff(options, self.args, file_list) | 487 scm.diff(options, self.args, file_list) |
468 self.assertEquals(file_list, []) | 488 self.assertEquals(file_list, []) |
469 | 489 |
470 def testRevertNone(self): | 490 def testRevertNone(self): |
471 if not self.enabled: | 491 if not self.enabled: |
472 return | 492 return |
473 options = self.Options() | 493 options = self.Options() |
474 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 494 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
475 relpath=self.relpath) | 495 relpath=self.relpath) |
476 file_list = [] | 496 file_list = [] |
477 scm.revert(options, self.args, file_list) | 497 scm.revert(options, self.args, file_list) |
478 self.assertEquals(file_list, []) | 498 self.assertEquals(file_list, []) |
479 self.assertEquals(scm.revinfo(options, self.args, None), | 499 self.assertEquals(scm.revinfo(options, self.args, None), |
480 '069c602044c5388d2d15c3f875b057c852003458') | 500 '069c602044c5388d2d15c3f875b057c852003458') |
481 | 501 |
482 | 502 |
483 def testRevertModified(self): | 503 def testRevertModified(self): |
484 if not self.enabled: | 504 if not self.enabled: |
485 return | 505 return |
486 options = self.Options() | 506 options = self.Options() |
487 file_path = os.path.join(self.base_path, 'a') | 507 file_path = gclient_scm.os.path.join(self.base_path, 'a') |
488 open(file_path, 'a').writelines('touched\n') | 508 open(file_path, 'a').writelines('touched\n') |
489 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 509 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
490 relpath=self.relpath) | 510 relpath=self.relpath) |
491 file_list = [] | 511 file_list = [] |
492 scm.revert(options, self.args, file_list) | 512 scm.revert(options, self.args, file_list) |
493 self.assertEquals(file_list, [file_path]) | 513 self.assertEquals(file_list, [file_path]) |
494 file_list = [] | 514 file_list = [] |
495 scm.diff(options, self.args, file_list) | 515 scm.diff(options, self.args, file_list) |
496 self.assertEquals(file_list, []) | 516 self.assertEquals(file_list, []) |
497 self.assertEquals(scm.revinfo(options, self.args, None), | 517 self.assertEquals(scm.revinfo(options, self.args, None), |
498 '069c602044c5388d2d15c3f875b057c852003458') | 518 '069c602044c5388d2d15c3f875b057c852003458') |
499 | 519 |
500 def testRevertNew(self): | 520 def testRevertNew(self): |
501 if not self.enabled: | 521 if not self.enabled: |
502 return | 522 return |
503 options = self.Options() | 523 options = self.Options() |
504 file_path = os.path.join(self.base_path, 'c') | 524 file_path = gclient_scm.os.path.join(self.base_path, 'c') |
505 f = open(file_path, 'w') | 525 f = open(file_path, 'w') |
506 f.writelines('new\n') | 526 f.writelines('new\n') |
507 f.close() | 527 f.close() |
508 subprocess.Popen(['git', 'add', 'c'], stdout=subprocess.PIPE, | 528 Popen(['git', 'add', 'c'], stdout=PIPE, |
509 stderr=subprocess.STDOUT, cwd=self.base_path).communicate() | 529 stderr=STDOUT, cwd=self.base_path).communicate() |
510 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 530 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
511 relpath=self.relpath) | 531 relpath=self.relpath) |
512 file_list = [] | 532 file_list = [] |
513 scm.revert(options, self.args, file_list) | 533 scm.revert(options, self.args, file_list) |
514 self.assertEquals(file_list, [file_path]) | 534 self.assertEquals(file_list, [file_path]) |
515 file_list = [] | 535 file_list = [] |
516 scm.diff(options, self.args, file_list) | 536 scm.diff(options, self.args, file_list) |
517 self.assertEquals(file_list, []) | 537 self.assertEquals(file_list, []) |
518 self.assertEquals(scm.revinfo(options, self.args, None), | 538 self.assertEquals(scm.revinfo(options, self.args, None), |
519 '069c602044c5388d2d15c3f875b057c852003458') | 539 '069c602044c5388d2d15c3f875b057c852003458') |
520 | 540 |
521 def testStatusNew(self): | 541 def testStatusNew(self): |
522 if not self.enabled: | 542 if not self.enabled: |
523 return | 543 return |
524 options = self.Options() | 544 options = self.Options() |
525 file_path = os.path.join(self.base_path, 'a') | 545 file_path = gclient_scm.os.path.join(self.base_path, 'a') |
526 open(file_path, 'a').writelines('touched\n') | 546 open(file_path, 'a').writelines('touched\n') |
527 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 547 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
528 relpath=self.relpath) | 548 relpath=self.relpath) |
529 file_list = [] | 549 file_list = [] |
530 scm.status(options, self.args, file_list) | 550 scm.status(options, self.args, file_list) |
531 self.assertEquals(file_list, [file_path]) | 551 self.assertEquals(file_list, [file_path]) |
532 | 552 |
533 def testStatus2New(self): | 553 def testStatus2New(self): |
534 if not self.enabled: | 554 if not self.enabled: |
535 return | 555 return |
536 options = self.Options() | 556 options = self.Options() |
537 expected_file_list = [] | 557 expected_file_list = [] |
538 for f in ['a', 'b']: | 558 for f in ['a', 'b']: |
539 file_path = os.path.join(self.base_path, f) | 559 file_path = gclient_scm.os.path.join(self.base_path, f) |
540 open(file_path, 'a').writelines('touched\n') | 560 open(file_path, 'a').writelines('touched\n') |
541 expected_file_list.extend([file_path]) | 561 expected_file_list.extend([file_path]) |
542 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 562 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
543 relpath=self.relpath) | 563 relpath=self.relpath) |
544 file_list = [] | 564 file_list = [] |
545 scm.status(options, self.args, file_list) | 565 scm.status(options, self.args, file_list) |
546 expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] | 566 expected_file_list = [gclient_scm.os.path.join(self.base_path, x) |
| 567 for x in ['a', 'b']] |
547 self.assertEquals(sorted(file_list), expected_file_list) | 568 self.assertEquals(sorted(file_list), expected_file_list) |
548 | 569 |
549 def testUpdateCheckout(self): | 570 def testUpdateCheckout(self): |
550 if not self.enabled: | 571 if not self.enabled: |
551 return | 572 return |
552 options = self.Options(verbose=True) | 573 options = self.Options(verbose=True) |
553 root_dir = tempfile.mkdtemp() | 574 root_dir = tempfile.mkdtemp() |
554 relpath = 'foo' | 575 relpath = 'foo' |
555 base_path = os.path.join(root_dir, relpath) | 576 base_path = gclient_scm.os.path.join(root_dir, relpath) |
556 url = os.path.join(self.root_dir, self.relpath, '.git') | 577 url = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
557 try: | 578 try: |
558 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, | 579 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, |
559 relpath=relpath) | 580 relpath=relpath) |
560 file_list = [] | 581 file_list = [] |
561 scm.update(options, (), file_list) | 582 scm.update(options, (), file_list) |
562 self.assertEquals(len(file_list), 2) | 583 self.assertEquals(len(file_list), 2) |
563 self.assert_(os.path.isfile(os.path.join(base_path, 'a'))) | 584 self.assert_(gclient_scm.os.path.isfile( |
| 585 gclient_scm.os.path.join(base_path, 'a'))) |
564 self.assertEquals(scm.revinfo(options, (), None), | 586 self.assertEquals(scm.revinfo(options, (), None), |
565 '069c602044c5388d2d15c3f875b057c852003458') | 587 '069c602044c5388d2d15c3f875b057c852003458') |
566 finally: | 588 finally: |
567 shutil.rmtree(root_dir) | 589 shutil.rmtree(root_dir) |
568 | 590 |
569 def testUpdateUpdate(self): | 591 def testUpdateUpdate(self): |
570 if not self.enabled: | 592 if not self.enabled: |
571 return | 593 return |
572 options = self.Options() | 594 options = self.Options() |
573 expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] | 595 expected_file_list = [gclient_scm.os.path.join(self.base_path, x) |
| 596 for x in ['a', 'b']] |
574 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 597 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
575 relpath=self.relpath) | 598 relpath=self.relpath) |
576 file_list = [] | 599 file_list = [] |
577 scm.update(options, (), file_list) | 600 scm.update(options, (), file_list) |
578 self.assertEquals(file_list, expected_file_list) | 601 self.assertEquals(file_list, expected_file_list) |
579 self.assertEquals(scm.revinfo(options, (), None), | 602 self.assertEquals(scm.revinfo(options, (), None), |
580 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 603 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
581 | 604 |
582 def testRevinfo(self): | 605 def testRevinfo(self): |
583 if not self.enabled: | 606 if not self.enabled: |
584 return | 607 return |
585 options = self.Options() | 608 options = self.Options() |
586 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 609 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
587 relpath=self.relpath) | 610 relpath=self.relpath) |
588 rev_info = scm.revinfo(options, (), None) | 611 rev_info = scm.revinfo(options, (), None) |
589 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') | 612 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') |
590 | 613 |
591 | 614 |
592 class RunSVNTestCase(gclient_test.BaseTestCase): | 615 class RunSVNTestCase(BaseTestCase): |
593 def testRunSVN(self): | 616 def testRunSVN(self): |
| 617 self.UnMock(gclient_scm, 'RunSVN') |
594 param2 = 'bleh' | 618 param2 = 'bleh' |
595 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') | 619 gclient_scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], |
596 gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) | 620 param2).AndReturn(None) |
597 self.mox.ReplayAll() | 621 self.mox.ReplayAll() |
598 gclient_scm.RunSVN(['foo', 'bar'], param2) | 622 gclient_scm.RunSVN(['foo', 'bar'], param2) |
599 | 623 |
600 | 624 |
601 if __name__ == '__main__': | 625 if __name__ == '__main__': |
| 626 import unittest |
602 unittest.main() | 627 unittest.main() |
603 | 628 |
604 # vim: ts=2:sw=2:tw=80:et: | 629 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |