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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 self.mox.ReplayAll() | 108 self.mox.ReplayAll() |
109 | 109 |
110 for _, answer in REMOTE_STRINGS: | 110 for _, answer in REMOTE_STRINGS: |
111 self.assertEquals(gclient_scm.SCMWrapper._get_first_remote_url(FAKE_PATH), | 111 self.assertEquals(gclient_scm.SCMWrapper._get_first_remote_url(FAKE_PATH), |
112 answer) | 112 answer) |
113 | 113 |
114 def tearDown(self): | 114 def tearDown(self): |
115 SuperMoxTestBase.tearDown(self) | 115 SuperMoxTestBase.tearDown(self) |
116 | 116 |
117 | 117 |
118 class SVNWrapperTestCase(BaseTestCase): | |
119 class OptionsObject(object): | |
120 def __init__(self, verbose=False, revision=None, force=False): | |
121 self.verbose = verbose | |
122 self.revision = revision | |
123 self.manually_grab_svn_rev = True | |
124 self.deps_os = None | |
125 self.force = force | |
126 self.reset = False | |
127 self.nohooks = False | |
128 # TODO(maruel): Test --jobs > 1. | |
129 self.jobs = 1 | |
130 self.delete_unversioned_trees = False | |
131 | |
132 def checkstdout(self, expected): | |
133 value = sys.stdout.getvalue() | |
134 sys.stdout.close() | |
135 # pylint: disable=E1101 | |
136 self.assertEquals(expected, strip_timestamps(value)) | |
137 | |
138 def Options(self, *args, **kwargs): | |
139 return self.OptionsObject(*args, **kwargs) | |
140 | |
141 def setUp(self): | |
142 BaseTestCase.setUp(self) | |
143 self.url = self.SvnUrl() | |
144 | |
145 def testUnsupportedSCM(self): | |
146 args = ['gopher://foo', self.root_dir, self.relpath] | |
147 exception_msg = 'No SCM found for url gopher://foo' | |
148 self.assertRaisesError(exception_msg, self._scm_wrapper, *args) | |
149 | |
150 def testSVNFullUrlForRelativeUrl(self): | |
151 self.url = 'svn://a/b/c/d' | |
152 | |
153 self.mox.ReplayAll() | |
154 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
155 relpath=self.relpath) | |
156 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') | |
157 | |
158 def testGITFullUrlForRelativeUrl(self): | |
159 self.url = 'git://a/b/c/d' | |
160 | |
161 self.mox.ReplayAll() | |
162 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
163 relpath=self.relpath) | |
164 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'git://a/b/c/crap') | |
165 | |
166 def testGITFakeHttpUrl(self): | |
167 self.url = 'git+http://foo' | |
168 | |
169 self.mox.ReplayAll() | |
170 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
171 relpath=self.relpath) | |
172 self.assertEqual(scm.url, 'http://foo') | |
173 | |
174 def testGITFakeHttpsUrl(self): | |
175 self.url = 'git+https://foo' | |
176 | |
177 self.mox.ReplayAll() | |
178 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
179 relpath=self.relpath) | |
180 self.assertEqual(scm.url, 'https://foo') | |
181 | |
182 def testRunCommandException(self): | |
183 options = self.Options(verbose=False) | |
184 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
185 | |
186 self.mox.ReplayAll() | |
187 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
188 relpath=self.relpath) | |
189 exception = "Unsupported argument(s): %s" % ','.join(self.args) | |
190 self.assertRaisesError(exception, scm.RunCommand, | |
191 'update', options, self.args) | |
192 | |
193 def testRunCommandUnknown(self): | |
194 # TODO(maruel): if ever used. | |
195 pass | |
196 | |
197 def testRevertMissing(self): | |
198 options = self.Options(verbose=True) | |
199 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | |
200 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | |
201 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
202 ).AndReturn('1.5.1') | |
203 # It'll to a checkout instead. | |
204 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
205 # Checkout. | |
206 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | |
207 parent = gclient_scm.os.path.dirname(self.base_path) | |
208 gclient_scm.os.path.exists(parent).AndReturn(False) | |
209 gclient_scm.os.makedirs(parent) | |
210 gclient_scm.os.path.exists(parent).AndReturn(True) | |
211 files_list = self.mox.CreateMockAnything() | |
212 gclient_scm.scm.SVN.RunAndGetFileList( | |
213 options.verbose, | |
214 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | |
215 cwd=self.root_dir, | |
216 file_list=files_list) | |
217 | |
218 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
219 ).AndReturn({'Revision': 100}) | |
220 | |
221 self.mox.ReplayAll() | |
222 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
223 relpath=self.relpath) | |
224 scm.revert(options, self.args, files_list) | |
225 self.checkstdout( | |
226 ('_____ %s is missing, synching instead\n' % self.relpath)) | |
227 | |
228 def testRevertNoDotSvn(self): | |
229 options = self.Options(verbose=True, force=True) | |
230 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
231 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) | |
232 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) | |
233 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) | |
234 # Checkout. | |
235 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
236 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | |
237 parent = gclient_scm.os.path.dirname(self.base_path) | |
238 gclient_scm.os.path.exists(parent).AndReturn(False) | |
239 gclient_scm.os.makedirs(parent) | |
240 gclient_scm.os.path.exists(parent).AndReturn(True) | |
241 files_list = self.mox.CreateMockAnything() | |
242 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
243 ).AndReturn('1.6') | |
244 gclient_scm.scm.SVN.RunAndGetFileList( | |
245 options.verbose, | |
246 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | |
247 cwd=self.root_dir, | |
248 file_list=files_list) | |
249 gclient_scm.gclient_utils.rmtree(self.base_path) | |
250 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
251 ).AndReturn({'Revision': 100}) | |
252 self.mox.ReplayAll() | |
253 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
254 relpath=self.relpath) | |
255 scm.revert(options, self.args, files_list) | |
256 self.checkstdout( | |
257 '\n_____ %s is not a valid svn checkout, synching instead\n' % | |
258 self.relpath) | |
259 | |
260 def testRevertNone(self): | |
261 options = self.Options(verbose=True) | |
262 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
263 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) | |
264 gclient_scm.scm.SVN.CaptureStatus( | |
265 None, self.base_path, no_ignore=False).AndReturn([]) | |
266 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
267 gclient_scm.scm.SVN.RunAndGetFileList( | |
268 options.verbose, | |
269 ['update', '--revision', 'BASE', '--ignore-externals'], | |
270 cwd=self.base_path, | |
271 file_list=mox.IgnoreArg()) | |
272 | |
273 self.mox.ReplayAll() | |
274 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
275 relpath=self.relpath) | |
276 file_list = [] | |
277 scm.revert(options, self.args, file_list) | |
278 | |
279 def testRevertDirectory(self): | |
280 options = self.Options(verbose=True) | |
281 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
282 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) | |
283 items = [ | |
284 ('~ ', 'a'), | |
285 ] | |
286 gclient_scm.scm.SVN.CaptureStatus( | |
287 None, self.base_path, no_ignore=False).AndReturn(items) | |
288 file_path = join(self.base_path, 'a') | |
289 gclient_scm.os.path.exists(file_path).AndReturn(True) | |
290 gclient_scm.os.path.isfile(file_path).AndReturn(False) | |
291 gclient_scm.os.path.islink(file_path).AndReturn(False) | |
292 gclient_scm.os.path.isdir(file_path).AndReturn(True) | |
293 gclient_scm.gclient_utils.rmtree(file_path) | |
294 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
295 gclient_scm.scm.SVN.RunAndGetFileList( | |
296 options.verbose, | |
297 ['update', '--revision', 'BASE', '--ignore-externals'], | |
298 cwd=self.base_path, | |
299 file_list=mox.IgnoreArg()) | |
300 | |
301 self.mox.ReplayAll() | |
302 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
303 relpath=self.relpath) | |
304 file_list2 = [] | |
305 scm.revert(options, self.args, file_list2) | |
306 self.checkstdout(('%s\n' % file_path)) | |
307 | |
308 def testRevertDot(self): | |
309 self.mox.StubOutWithMock(gclient_scm.SVNWrapper, 'update') | |
310 options = self.Options(verbose=True) | |
311 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
312 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) | |
313 items = [ | |
314 ('~ ', '.'), | |
315 ] | |
316 gclient_scm.scm.SVN.CaptureStatus( | |
317 None, self.base_path, no_ignore=False).AndReturn(items) | |
318 # gclient_utils.rmtree() doesn't work on path ending with '.', like 'foo/.'. | |
319 file_path = self.base_path | |
320 gclient_scm.os.path.exists(file_path).AndReturn(True) | |
321 gclient_scm.os.path.isfile(file_path).AndReturn(False) | |
322 gclient_scm.os.path.islink(file_path).AndReturn(False) | |
323 gclient_scm.os.path.isdir(file_path).AndReturn(True) | |
324 gclient_scm.gclient_utils.rmtree(file_path) | |
325 # pylint: disable=E1120 | |
326 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | |
327 gclient_scm.SVNWrapper.update(options, [], ['.']) | |
328 | |
329 self.mox.ReplayAll() | |
330 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
331 relpath=self.relpath) | |
332 file_list2 = [] | |
333 scm.revert(options, self.args, file_list2) | |
334 self.checkstdout(('%s\n' % os.path.join(file_path, '.'))) | |
335 | |
336 def testStatus(self): | |
337 options = self.Options(verbose=True) | |
338 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
339 gclient_scm.scm.SVN.RunAndGetFileList( | |
340 options.verbose, | |
341 ['status'] + self.args + ['--ignore-externals'], | |
342 cwd=self.base_path, | |
343 file_list=[]).AndReturn(None) | |
344 | |
345 self.mox.ReplayAll() | |
346 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
347 relpath=self.relpath) | |
348 file_list = [] | |
349 self.assertEqual(scm.status(options, self.args, file_list), None) | |
350 | |
351 # TODO(maruel): TEST REVISIONS!!! | |
352 # TODO(maruel): TEST RELOCATE!!! | |
353 def testUpdateCheckout(self): | |
354 options = self.Options(verbose=True) | |
355 file_info = gclient_scm.gclient_utils.PrintableObject() | |
356 file_info.root = 'blah' | |
357 file_info.url = self.url | |
358 file_info.uuid = 'ABC' | |
359 file_info.revision = 42 | |
360 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
361 # Checkout. | |
362 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | |
363 parent = gclient_scm.os.path.dirname(self.base_path) | |
364 gclient_scm.os.path.exists(parent).AndReturn(False) | |
365 gclient_scm.os.makedirs(parent) | |
366 gclient_scm.os.path.exists(parent).AndReturn(True) | |
367 files_list = self.mox.CreateMockAnything() | |
368 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
369 ).AndReturn('1.5.1') | |
370 gclient_scm.scm.SVN.RunAndGetFileList( | |
371 options.verbose, | |
372 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | |
373 cwd=self.root_dir, | |
374 file_list=files_list) | |
375 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
376 ).AndReturn({'Revision': 100}) | |
377 self.mox.ReplayAll() | |
378 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
379 relpath=self.relpath) | |
380 scm.update(options, (), files_list) | |
381 | |
382 def testUpdateUpdate(self): | |
383 options = self.Options(verbose=True) | |
384 options.force = True | |
385 options.nohooks = False | |
386 file_info = { | |
387 'Repository Root': 'blah', | |
388 'URL': self.url, | |
389 'UUID': 'ABC', | |
390 'Revision': 42, | |
391 } | |
392 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
393 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
394 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
395 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
396 | |
397 # Checkout or update. | |
398 dotted_path = join(self.base_path, '.') | |
399 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | |
400 | |
401 # Verify no locked files. | |
402 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) | |
403 | |
404 # Cheat a bit here. | |
405 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | |
406 ).AndReturn(file_info) | |
407 | |
408 # _AddAdditionalUpdateFlags() | |
409 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
410 ).AndReturn('1.5.1') | |
411 | |
412 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
413 ).AndReturn({'Revision': 100}) | |
414 | |
415 additional_args = [] | |
416 if options.manually_grab_svn_rev: | |
417 additional_args = ['--revision', str(file_info['Revision'])] | |
418 additional_args.extend(['--force', '--ignore-externals']) | |
419 files_list = [] | |
420 gclient_scm.scm.SVN.RunAndGetFileList( | |
421 options.verbose, | |
422 ['update', self.base_path] + additional_args, | |
423 cwd=self.root_dir, file_list=files_list) | |
424 | |
425 self.mox.ReplayAll() | |
426 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
427 relpath=self.relpath) | |
428 scm.update(options, (), files_list) | |
429 | |
430 def testUpdateReset(self): | |
431 options = self.Options(verbose=True) | |
432 options.reset = True | |
433 file_info = { | |
434 'Repository Root': 'blah', | |
435 'URL': self.url, | |
436 'UUID': 'ABC', | |
437 'Revision': 42, | |
438 } | |
439 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
440 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
441 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
442 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
443 | |
444 # Checkout or update. | |
445 dotted_path = join(self.base_path, '.') | |
446 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | |
447 | |
448 # Create an untracked file and directory. | |
449 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | |
450 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | |
451 | |
452 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | |
453 ).AndReturn(file_info) | |
454 | |
455 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
456 ).AndReturn({'Revision': 100}) | |
457 | |
458 self.mox.ReplayAll() | |
459 files_list = [] | |
460 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
461 relpath=self.relpath) | |
462 scm.update(options, (), files_list) | |
463 self.checkstdout('_____ %s at 42\n' % self.relpath) | |
464 | |
465 def testUpdateResetDeleteUnversionedTrees(self): | |
466 options = self.Options(verbose=True) | |
467 options.reset = True | |
468 options.delete_unversioned_trees = True | |
469 | |
470 file_info = { | |
471 'Repository Root': 'blah', | |
472 'URL': self.url, | |
473 'UUID': 'ABC', | |
474 'Revision': 42, | |
475 } | |
476 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
477 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
478 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
479 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
480 | |
481 # Checkout or update. | |
482 dotted_path = join(self.base_path, '.') | |
483 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | |
484 | |
485 # Create an untracked file and directory. | |
486 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | |
487 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | |
488 | |
489 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | |
490 ).AndReturn(file_info) | |
491 | |
492 # Confirm that the untracked file is removed. | |
493 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path | |
494 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | |
495 gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True) | |
496 gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False) | |
497 gclient_scm.os.path.islink(join(self.base_path, 'dir')).AndReturn(False) | |
498 gclient_scm.gclient_utils.rmtree(join(self.base_path, 'dir')) | |
499 | |
500 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
501 ).AndReturn({'Revision': 100}) | |
502 | |
503 self.mox.ReplayAll() | |
504 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
505 relpath=self.relpath) | |
506 files_list = [] | |
507 scm.update(options, (), files_list) | |
508 self.checkstdout( | |
509 ('_____ %s at 42\n' | |
510 '_____ removing unversioned directory dir\n') % self.relpath) | |
511 | |
512 def testUpdateSingleCheckout(self): | |
513 options = self.Options(verbose=True) | |
514 file_info = { | |
515 'URL': self.url, | |
516 'Revision': 42, | |
517 } | |
518 | |
519 # Checks to make sure that we support svn co --depth. | |
520 gclient_scm.scm.SVN.current_version = None | |
521 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
522 ).AndReturn('1.5.1') | |
523 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(False) | |
524 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(False) | |
525 | |
526 # Verify no locked files. | |
527 dotted_path = join(self.base_path, '.') | |
528 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) | |
529 | |
530 # When checking out a single file, we issue an svn checkout and svn update. | |
531 files_list = self.mox.CreateMockAnything() | |
532 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | |
533 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | |
534 always=True, | |
535 cwd=self.root_dir) | |
536 gclient_scm.scm.SVN.RunAndGetFileList( | |
537 options.verbose, | |
538 ['update', 'DEPS', '--ignore-externals'], | |
539 cwd=self.base_path, | |
540 file_list=files_list) | |
541 | |
542 # Now we fall back on scm.update(). | |
543 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
544 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
545 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
546 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
547 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | |
548 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | |
549 ).AndReturn(file_info) | |
550 | |
551 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
552 ).AndReturn({'Revision': 100}) | |
553 | |
554 self.mox.ReplayAll() | |
555 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
556 relpath=self.relpath) | |
557 scm.updatesingle(options, ['DEPS'], files_list) | |
558 self.checkstdout('_____ %s at 42\n' % self.relpath) | |
559 | |
560 def testUpdateSingleCheckoutSVN14(self): | |
561 options = self.Options(verbose=True) | |
562 | |
563 # Checks to make sure that we support svn co --depth. | |
564 gclient_scm.scm.SVN.current_version = None | |
565 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
566 ).AndReturn('1.4.4') | |
567 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
568 | |
569 # When checking out a single file with svn 1.4, we use svn export | |
570 files_list = self.mox.CreateMockAnything() | |
571 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | |
572 ['svn', 'export', join(self.url, 'DEPS'), join(self.base_path, 'DEPS')], | |
573 always=True, cwd=self.root_dir) | |
574 | |
575 self.mox.ReplayAll() | |
576 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
577 relpath=self.relpath) | |
578 scm.updatesingle(options, ['DEPS'], files_list) | |
579 | |
580 def testUpdateSingleCheckoutSVNUpgrade(self): | |
581 options = self.Options(verbose=True) | |
582 file_info = { | |
583 'URL': self.url, | |
584 'Revision': 42, | |
585 } | |
586 | |
587 # Checks to make sure that we support svn co --depth. | |
588 gclient_scm.scm.SVN.current_version = None | |
589 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
590 ).AndReturn('1.5.1') | |
591 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(False) | |
592 # If DEPS already exists, assume we're upgrading from svn1.4, so delete | |
593 # the old DEPS file. | |
594 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(True) | |
595 gclient_scm.os.remove(join(self.base_path, 'DEPS')) | |
596 | |
597 # Verify no locked files. | |
598 gclient_scm.scm.SVN.CaptureStatus( | |
599 None, join(self.base_path, '.')).AndReturn([]) | |
600 | |
601 # When checking out a single file, we issue an svn checkout and svn update. | |
602 files_list = self.mox.CreateMockAnything() | |
603 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | |
604 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | |
605 always=True, | |
606 cwd=self.root_dir) | |
607 gclient_scm.scm.SVN.RunAndGetFileList( | |
608 options.verbose, | |
609 ['update', 'DEPS', '--ignore-externals'], | |
610 cwd=self.base_path, | |
611 file_list=files_list) | |
612 | |
613 # Now we fall back on scm.update(). | |
614 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
615 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
616 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
617 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
618 gclient_scm.scm.SVN._CaptureInfo( | |
619 [], join(self.base_path, ".")).AndReturn(file_info) | |
620 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | |
621 ).AndReturn(file_info) | |
622 | |
623 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
624 ).AndReturn({'Revision': 100}) | |
625 | |
626 self.mox.ReplayAll() | |
627 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
628 relpath=self.relpath) | |
629 scm.updatesingle(options, ['DEPS'], files_list) | |
630 self.checkstdout( | |
631 ('_____ %s at 42\n' % self.relpath)) | |
632 | |
633 def testUpdateSingleUpdate(self): | |
634 options = self.Options(verbose=True) | |
635 file_info = { | |
636 'URL': self.url, | |
637 'Revision': 42, | |
638 } | |
639 # Checks to make sure that we support svn co --depth. | |
640 gclient_scm.scm.SVN.current_version = None | |
641 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
642 ).AndReturn('1.5.1') | |
643 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) | |
644 | |
645 # Verify no locked files. | |
646 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') | |
647 ).AndReturn([]) | |
648 | |
649 # Now we fall back on scm.update(). | |
650 files_list = self.mox.CreateMockAnything() | |
651 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | |
652 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
653 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
654 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
655 gclient_scm.scm.SVN._CaptureInfo( | |
656 [], join(self.base_path, '.')).AndReturn(file_info) | |
657 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | |
658 ).AndReturn(file_info) | |
659 | |
660 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
661 ).AndReturn({'Revision': 100}) | |
662 | |
663 self.mox.ReplayAll() | |
664 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
665 relpath=self.relpath) | |
666 scm.updatesingle(options, ['DEPS'], files_list) | |
667 self.checkstdout('_____ %s at 42\n' % self.relpath) | |
668 | |
669 def testUpdateGit(self): | |
670 options = self.Options(verbose=True) | |
671 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg') | |
672 gclient_scm.os.path.exists(file_path).AndReturn(False) | |
673 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
674 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
675 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
676 error = gclient_scm.subprocess2.CalledProcessError( | |
677 1, 'cmd', '/cwd', 'stdout', 'stderr') | |
678 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error) | |
679 | |
680 bad_scm_path = os.path.join(self.root_dir, '_bad_scm', | |
681 os.path.dirname(self.relpath)) | |
682 gclient_scm.os.makedirs(bad_scm_path) | |
683 dest_path = os.path.join(bad_scm_path, | |
684 os.path.basename(self.relpath) + 'ABCD') | |
685 self.mox.StubOutWithMock(gclient_scm.tempfile, 'mkdtemp', True) | |
686 gclient_scm.tempfile.mkdtemp( | |
687 prefix=os.path.basename(self.relpath), | |
688 dir=os.path.join(self.root_dir, '_bad_scm', | |
689 os.path.dirname(self.relpath))).AndReturn(dest_path) | |
690 self.mox.StubOutWithMock(gclient_scm.shutil, 'move', True) | |
691 gclient_scm.shutil.move(self.base_path, dest_path) | |
692 gclient_scm.os.path.exists(self.root_dir).AndReturn(True) | |
693 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
694 ).AndReturn('1.5.1') | |
695 gclient_scm.scm.SVN.RunAndGetFileList( | |
696 options.verbose, | |
697 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | |
698 cwd=self.root_dir, | |
699 file_list=[]) | |
700 | |
701 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
702 ).AndReturn({'Revision': 100}) | |
703 | |
704 self.mox.ReplayAll() | |
705 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
706 relpath=self.relpath) | |
707 scm.update(options, None, []) | |
708 self.checkstdout('_____ Conflicting directory found in %s. Moving to %s.\n' | |
709 % (self.base_path, dest_path)) | |
710 | |
711 def testUpdateGitForce(self): | |
712 options = self.Options(verbose=True, force=True) | |
713 old_environ = dict(gclient_scm.os.environ) | |
714 gclient_scm.os.environ['CHROME_HEADLESS'] = '1' | |
715 try: | |
716 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg') | |
717 gclient_scm.os.path.exists(file_path).AndReturn(False) | |
718 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
719 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
720 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
721 error = gclient_scm.subprocess2.CalledProcessError( | |
722 1, 'cmd', '/cwd', 'stdout', 'stderr') | |
723 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error) | |
724 gclient_scm.gclient_utils.rmtree(self.base_path) | |
725 gclient_scm.os.path.exists(self.root_dir).AndReturn(True) | |
726 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
727 ).AndReturn('1.5.1') | |
728 gclient_scm.scm.SVN.RunAndGetFileList( | |
729 options.verbose, | |
730 ['checkout', self.url, self.base_path, '--force', | |
731 '--ignore-externals'], | |
732 cwd=self.root_dir, | |
733 file_list=[]) | |
734 | |
735 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
736 ).AndReturn({'Revision': 100}) | |
737 | |
738 self.mox.ReplayAll() | |
739 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
740 relpath=self.relpath) | |
741 file_list = [] | |
742 scm.update(options, None, file_list) | |
743 self.checkstdout('_____ Conflicting directory found in %s. Removing.\n' | |
744 % self.base_path) | |
745 finally: | |
746 gclient_scm.os.environ = old_environ | |
747 | |
748 def testUpdateGitSvn(self): | |
749 options = self.Options(verbose=True) | |
750 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg') | |
751 gclient_scm.os.path.exists(file_path).AndReturn(False) | |
752 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
753 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
754 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True) | |
755 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True) | |
756 gclient_scm.scm.GIT.Capture(['config', '--local', '--get', | |
757 'svn-remote.svn.url'], | |
758 cwd=self.base_path).AndReturn(self.url) | |
759 | |
760 self.mox.ReplayAll() | |
761 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
762 relpath=self.relpath) | |
763 file_list = [] | |
764 scm.update(options, [], file_list) | |
765 self.checkstdout( | |
766 ('\n_____ %s looks like a git-svn checkout. Skipping.\n' % self.relpath) | |
767 ) | |
768 | |
769 def testUpdateHg(self): | |
770 options = self.Options(verbose=True) | |
771 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True) | |
772 | |
773 self.mox.ReplayAll() | |
774 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
775 relpath=self.relpath) | |
776 file_list = [] | |
777 scm.update(options, self.args, file_list) | |
778 self.checkstdout( | |
779 ('________ found .hg directory; skipping %s\n' % self.relpath)) | |
780 | |
781 def testGetUsableRevSVN(self): | |
782 # pylint: disable=E1101 | |
783 options = self.Options(verbose=True) | |
784 | |
785 # Mock SVN revision validity checking. | |
786 self.mox.StubOutWithMock( | |
787 gclient_scm.scm.SVN, 'IsValidRevision', True) | |
788 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 1) | |
789 ).AndReturn(True) | |
790 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 'fake') | |
791 ).AndReturn(False) | |
792 | |
793 self.mox.ReplayAll() | |
794 | |
795 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir) | |
796 # With an SVN checkout, 1 an example of a valid usable rev. | |
797 self.assertEquals(svn_scm.GetUsableRev(1, options), 1) | |
798 # With an SVN checkout, a fake or unknown rev should raise an excpetion. | |
799 self.assertRaises(gclient_scm.gclient_utils.Error, | |
800 svn_scm.GetUsableRev, 'fake', options) | |
801 | |
802 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, | 118 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, |
803 unittest.TestCase): | 119 unittest.TestCase): |
804 """This class doesn't use pymox.""" | 120 """This class doesn't use pymox.""" |
805 class OptionsObject(object): | 121 class OptionsObject(object): |
806 def __init__(self, verbose=False, revision=None): | 122 def __init__(self, verbose=False, revision=None): |
807 self.auto_rebase = False | 123 self.auto_rebase = False |
808 self.verbose = verbose | 124 self.verbose = verbose |
809 self.revision = revision | 125 self.revision = revision |
810 self.manually_grab_svn_rev = True | 126 self.manually_grab_svn_rev = True |
811 self.deps_os = None | 127 self.deps_os = None |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 | 939 |
1624 if __name__ == '__main__': | 940 if __name__ == '__main__': |
1625 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL | 941 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL |
1626 logging.basicConfig( | 942 logging.basicConfig( |
1627 level=level, | 943 level=level, |
1628 format='%(asctime).19s %(levelname)s %(filename)s:' | 944 format='%(asctime).19s %(levelname)s %(filename)s:' |
1629 '%(lineno)s %(message)s') | 945 '%(lineno)s %(message)s') |
1630 unittest.main() | 946 unittest.main() |
1631 | 947 |
1632 # vim: ts=2:sw=2:tw=80:et: | 948 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |