OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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=E1101,E1103,W0403 | 8 # pylint: disable=E1101,E1103,W0403 |
9 | 9 |
10 # Import before super_mox to keep valid references. | 10 # Import before super_mox to keep valid references. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 options = self.Options(verbose=True) | 131 options = self.Options(verbose=True) |
132 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 132 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
133 gclient_scm.scm.SVN.Capture(['--version'] | 133 gclient_scm.scm.SVN.Capture(['--version'] |
134 ).AndReturn('svn, version 1.5.1 (r32289)') | 134 ).AndReturn('svn, version 1.5.1 (r32289)') |
135 # It'll to a checkout instead. | 135 # It'll to a checkout instead. |
136 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 136 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
137 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 137 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
138 # Checkout. | 138 # Checkout. |
139 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 139 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
140 files_list = self.mox.CreateMockAnything() | 140 files_list = self.mox.CreateMockAnything() |
141 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 141 gclient_scm.scm.SVN.RunAndGetFileList( |
142 ['checkout', self.url, self.base_path, | 142 options.verbose, |
143 '--force'], | 143 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
144 cwd=self.root_dir, | 144 cwd=self.root_dir, |
145 file_list=files_list) | 145 file_list=files_list) |
146 | 146 |
147 self.mox.ReplayAll() | 147 self.mox.ReplayAll() |
148 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 148 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
149 relpath=self.relpath) | 149 relpath=self.relpath) |
150 scm.revert(options, self.args, files_list) | 150 scm.revert(options, self.args, files_list) |
151 self.checkstdout( | 151 self.checkstdout( |
152 ('\n_____ %s is missing, synching instead\n' % self.relpath)) | 152 ('\n_____ %s is missing, synching instead\n' % self.relpath)) |
153 | 153 |
154 def testRevertNone(self): | 154 def testRevertNone(self): |
155 options = self.Options(verbose=True) | 155 options = self.Options(verbose=True) |
156 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 156 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
157 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn([]) | 157 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn([]) |
158 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 158 gclient_scm.scm.SVN.RunAndGetFileList( |
159 ['update', '--revision', 'BASE'], | 159 options.verbose, |
160 cwd=self.base_path, | 160 ['update', '--revision', 'BASE', '--ignore-externals'], |
161 file_list=mox.IgnoreArg()) | 161 cwd=self.base_path, |
| 162 file_list=mox.IgnoreArg()) |
162 | 163 |
163 self.mox.ReplayAll() | 164 self.mox.ReplayAll() |
164 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 165 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
165 relpath=self.relpath) | 166 relpath=self.relpath) |
166 file_list = [] | 167 file_list = [] |
167 scm.revert(options, self.args, file_list) | 168 scm.revert(options, self.args, file_list) |
168 | 169 |
169 def testRevert2Files(self): | 170 def testRevert2Files(self): |
170 options = self.Options(verbose=True) | 171 options = self.Options(verbose=True) |
171 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 172 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
172 items = [ | 173 items = [ |
173 ('M ', 'a'), | 174 ('M ', 'a'), |
174 ('A ', 'b'), | 175 ('A ', 'b'), |
175 ] | 176 ] |
176 file_path1 = join(self.base_path, 'a') | 177 file_path1 = join(self.base_path, 'a') |
177 file_path2 = join(self.base_path, 'b') | 178 file_path2 = join(self.base_path, 'b') |
178 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) | 179 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) |
179 gclient_scm.os.path.exists(file_path1).AndReturn(True) | 180 gclient_scm.os.path.exists(file_path1).AndReturn(True) |
180 gclient_scm.os.path.isfile(file_path1).AndReturn(True) | 181 gclient_scm.os.path.isfile(file_path1).AndReturn(True) |
181 gclient_scm.os.remove(file_path1) | 182 gclient_scm.os.remove(file_path1) |
182 gclient_scm.os.path.exists(file_path2).AndReturn(True) | 183 gclient_scm.os.path.exists(file_path2).AndReturn(True) |
183 gclient_scm.os.path.isfile(file_path2).AndReturn(True) | 184 gclient_scm.os.path.isfile(file_path2).AndReturn(True) |
184 gclient_scm.os.remove(file_path2) | 185 gclient_scm.os.remove(file_path2) |
185 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 186 gclient_scm.scm.SVN.RunAndGetFileList( |
186 ['update', '--revision', 'BASE'], | 187 options.verbose, |
187 cwd=self.base_path, | 188 ['update', '--revision', 'BASE', '--ignore-externals'], |
188 file_list=mox.IgnoreArg()) | 189 cwd=self.base_path, |
| 190 file_list=mox.IgnoreArg()) |
189 | 191 |
190 self.mox.ReplayAll() | 192 self.mox.ReplayAll() |
191 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 193 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
192 relpath=self.relpath) | 194 relpath=self.relpath) |
193 file_list = [] | 195 file_list = [] |
194 scm.revert(options, self.args, file_list) | 196 scm.revert(options, self.args, file_list) |
195 self.checkstdout( | 197 self.checkstdout( |
196 ('%s\n%s\n' % (join(self.base_path, 'a'), | 198 ('%s\n%s\n' % (join(self.base_path, 'a'), |
197 join(self.base_path, 'b')))) | 199 join(self.base_path, 'b')))) |
198 | 200 |
199 def testRevertDirectory(self): | 201 def testRevertDirectory(self): |
200 options = self.Options(verbose=True) | 202 options = self.Options(verbose=True) |
201 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 203 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
202 items = [ | 204 items = [ |
203 ('~ ', 'a'), | 205 ('~ ', 'a'), |
204 ] | 206 ] |
205 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) | 207 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) |
206 file_path = join(self.base_path, 'a') | 208 file_path = join(self.base_path, 'a') |
207 gclient_scm.os.path.exists(file_path).AndReturn(True) | 209 gclient_scm.os.path.exists(file_path).AndReturn(True) |
208 gclient_scm.os.path.isfile(file_path).AndReturn(False) | 210 gclient_scm.os.path.isfile(file_path).AndReturn(False) |
209 gclient_scm.os.path.islink(file_path).AndReturn(False) | 211 gclient_scm.os.path.islink(file_path).AndReturn(False) |
210 gclient_scm.os.path.isdir(file_path).AndReturn(True) | 212 gclient_scm.os.path.isdir(file_path).AndReturn(True) |
211 gclient_scm.gclient_utils.RemoveDirectory(file_path) | 213 gclient_scm.gclient_utils.RemoveDirectory(file_path) |
212 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 214 gclient_scm.scm.SVN.RunAndGetFileList( |
213 ['update', '--revision', 'BASE'], | 215 options.verbose, |
214 cwd=self.base_path, | 216 ['update', '--revision', 'BASE', '--ignore-externals'], |
215 file_list=mox.IgnoreArg()) | 217 cwd=self.base_path, |
| 218 file_list=mox.IgnoreArg()) |
216 | 219 |
217 self.mox.ReplayAll() | 220 self.mox.ReplayAll() |
218 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 221 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
219 relpath=self.relpath) | 222 relpath=self.relpath) |
220 file_list2 = [] | 223 file_list2 = [] |
221 scm.revert(options, self.args, file_list2) | 224 scm.revert(options, self.args, file_list2) |
222 self.checkstdout(('%s\n' % file_path)) | 225 self.checkstdout(('%s\n' % file_path)) |
223 | 226 |
224 def testStatus(self): | 227 def testStatus(self): |
225 options = self.Options(verbose=True) | 228 options = self.Options(verbose=True) |
226 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 229 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
227 gclient_scm.scm.SVN.RunAndGetFileList( | 230 gclient_scm.scm.SVN.RunAndGetFileList( |
228 options.verbose, ['status'] + self.args, | 231 options.verbose, |
229 cwd=self.base_path, file_list=[]).AndReturn(None) | 232 ['status'] + self.args + ['--ignore-externals'], |
| 233 cwd=self.base_path, |
| 234 file_list=[]).AndReturn(None) |
230 | 235 |
231 self.mox.ReplayAll() | 236 self.mox.ReplayAll() |
232 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 237 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
233 relpath=self.relpath) | 238 relpath=self.relpath) |
234 file_list = [] | 239 file_list = [] |
235 self.assertEqual(scm.status(options, self.args, file_list), None) | 240 self.assertEqual(scm.status(options, self.args, file_list), None) |
236 | 241 |
237 # TODO(maruel): TEST REVISIONS!!! | 242 # TODO(maruel): TEST REVISIONS!!! |
238 # TODO(maruel): TEST RELOCATE!!! | 243 # TODO(maruel): TEST RELOCATE!!! |
239 def testUpdateCheckout(self): | 244 def testUpdateCheckout(self): |
240 options = self.Options(verbose=True) | 245 options = self.Options(verbose=True) |
241 file_info = gclient_scm.gclient_utils.PrintableObject() | 246 file_info = gclient_scm.gclient_utils.PrintableObject() |
242 file_info.root = 'blah' | 247 file_info.root = 'blah' |
243 file_info.url = self.url | 248 file_info.url = self.url |
244 file_info.uuid = 'ABC' | 249 file_info.uuid = 'ABC' |
245 file_info.revision = 42 | 250 file_info.revision = 42 |
246 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 251 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
247 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 252 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
248 # Checkout. | 253 # Checkout. |
249 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 254 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
250 files_list = self.mox.CreateMockAnything() | 255 files_list = self.mox.CreateMockAnything() |
251 gclient_scm.scm.SVN.Capture(['--version'] | 256 gclient_scm.scm.SVN.Capture(['--version'] |
252 ).AndReturn('svn, version 1.5.1 (r32289)') | 257 ).AndReturn('svn, version 1.5.1 (r32289)') |
253 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 258 gclient_scm.scm.SVN.RunAndGetFileList( |
254 ['checkout', self.url, self.base_path, | 259 options.verbose, |
255 '--force'], | 260 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
256 cwd=self.root_dir, | 261 cwd=self.root_dir, |
257 file_list=files_list) | 262 file_list=files_list) |
258 self.mox.ReplayAll() | 263 self.mox.ReplayAll() |
259 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 264 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
260 relpath=self.relpath) | 265 relpath=self.relpath) |
261 scm.update(options, (), files_list) | 266 scm.update(options, (), files_list) |
262 | 267 |
263 def testUpdateUpdate(self): | 268 def testUpdateUpdate(self): |
264 options = self.Options(verbose=True) | 269 options = self.Options(verbose=True) |
265 options.force = True | 270 options.force = True |
266 options.nohooks = False | 271 options.nohooks = False |
267 file_info = { | 272 file_info = { |
(...skipping 12 matching lines...) Expand all Loading... |
280 # Checkout or update. | 285 # Checkout or update. |
281 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 286 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
282 gclient_scm.scm.SVN.CaptureInfo(dotted_path).AndReturn(file_info) | 287 gclient_scm.scm.SVN.CaptureInfo(dotted_path).AndReturn(file_info) |
283 # Cheat a bit here. | 288 # Cheat a bit here. |
284 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 289 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
285 additional_args = [] | 290 additional_args = [] |
286 if options.manually_grab_svn_rev: | 291 if options.manually_grab_svn_rev: |
287 additional_args = ['--revision', str(file_info['Revision'])] | 292 additional_args = ['--revision', str(file_info['Revision'])] |
288 gclient_scm.scm.SVN.Capture(['--version'] | 293 gclient_scm.scm.SVN.Capture(['--version'] |
289 ).AndReturn('svn, version 1.5.1 (r32289)') | 294 ).AndReturn('svn, version 1.5.1 (r32289)') |
290 additional_args.append('--force') | 295 additional_args.extend(['--force', '--ignore-externals']) |
291 files_list = [] | 296 files_list = [] |
292 gclient_scm.scm.SVN.RunAndGetFileList( | 297 gclient_scm.scm.SVN.RunAndGetFileList( |
293 options.verbose, | 298 options.verbose, |
294 ['update', self.base_path] + additional_args, | 299 ['update', self.base_path] + additional_args, |
295 cwd=self.root_dir, file_list=files_list) | 300 cwd=self.root_dir, file_list=files_list) |
296 | 301 |
297 self.mox.ReplayAll() | 302 self.mox.ReplayAll() |
298 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 303 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
299 relpath=self.relpath) | 304 relpath=self.relpath) |
300 scm.update(options, (), files_list) | 305 scm.update(options, (), files_list) |
(...skipping 13 matching lines...) Expand all Loading... |
314 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(False) | 319 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(False) |
315 | 320 |
316 # Verify no locked files. | 321 # Verify no locked files. |
317 dotted_path = join(self.base_path, '.') | 322 dotted_path = join(self.base_path, '.') |
318 gclient_scm.scm.SVN.CaptureStatus(dotted_path).AndReturn([]) | 323 gclient_scm.scm.SVN.CaptureStatus(dotted_path).AndReturn([]) |
319 | 324 |
320 # When checking out a single file, we issue an svn checkout and svn update. | 325 # When checking out a single file, we issue an svn checkout and svn update. |
321 files_list = self.mox.CreateMockAnything() | 326 files_list = self.mox.CreateMockAnything() |
322 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | 327 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( |
323 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 328 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
324 always=True, cwd=self.root_dir) | 329 always=True, |
325 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], | 330 cwd=self.root_dir) |
326 cwd=self.base_path, file_list=files_list) | 331 gclient_scm.scm.SVN.RunAndGetFileList( |
| 332 options.verbose, |
| 333 ['update', 'DEPS', '--ignore-externals'], |
| 334 cwd=self.base_path, |
| 335 file_list=files_list) |
327 | 336 |
328 # Now we fall back on scm.update(). | 337 # Now we fall back on scm.update(). |
329 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 338 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
330 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 339 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
331 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 340 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
332 gclient_scm.scm.SVN.CaptureInfo(dotted_path).AndReturn(file_info) | 341 gclient_scm.scm.SVN.CaptureInfo(dotted_path).AndReturn(file_info) |
333 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 342 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
334 | 343 |
335 self.mox.ReplayAll() | 344 self.mox.ReplayAll() |
336 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 345 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(True) | 384 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(True) |
376 gclient_scm.os.remove(join(self.base_path, 'DEPS')) | 385 gclient_scm.os.remove(join(self.base_path, 'DEPS')) |
377 | 386 |
378 # Verify no locked files. | 387 # Verify no locked files. |
379 gclient_scm.scm.SVN.CaptureStatus(join(self.base_path, '.')).AndReturn([]) | 388 gclient_scm.scm.SVN.CaptureStatus(join(self.base_path, '.')).AndReturn([]) |
380 | 389 |
381 # When checking out a single file, we issue an svn checkout and svn update. | 390 # When checking out a single file, we issue an svn checkout and svn update. |
382 files_list = self.mox.CreateMockAnything() | 391 files_list = self.mox.CreateMockAnything() |
383 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | 392 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( |
384 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 393 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
385 always=True, cwd=self.root_dir) | 394 always=True, |
386 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], | 395 cwd=self.root_dir) |
387 cwd=self.base_path, file_list=files_list) | 396 gclient_scm.scm.SVN.RunAndGetFileList( |
| 397 options.verbose, |
| 398 ['update', 'DEPS', '--ignore-externals'], |
| 399 cwd=self.base_path, |
| 400 file_list=files_list) |
388 | 401 |
389 # Now we fall back on scm.update(). | 402 # Now we fall back on scm.update(). |
390 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 403 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
391 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 404 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
392 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 405 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
393 gclient_scm.scm.SVN.CaptureInfo( | 406 gclient_scm.scm.SVN.CaptureInfo( |
394 join(self.base_path, ".")).AndReturn(file_info) | 407 join(self.base_path, ".")).AndReturn(file_info) |
395 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 408 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
396 | 409 |
397 self.mox.ReplayAll() | 410 self.mox.ReplayAll() |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 829 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
817 relpath=self.relpath) | 830 relpath=self.relpath) |
818 rev_info = scm.revinfo(options, (), None) | 831 rev_info = scm.revinfo(options, (), None) |
819 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') | 832 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') |
820 | 833 |
821 | 834 |
822 if __name__ == '__main__': | 835 if __name__ == '__main__': |
823 unittest.main() | 836 unittest.main() |
824 | 837 |
825 # vim: ts=2:sw=2:tw=80:et: | 838 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |