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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 def setUp(self): | 96 def setUp(self): |
97 BaseTestCase.setUp(self) | 97 BaseTestCase.setUp(self) |
98 self.url = self.SvnUrl() | 98 self.url = self.SvnUrl() |
99 | 99 |
100 def testDir(self): | 100 def testDir(self): |
101 members = [ | 101 members = [ |
102 'BinaryExists', | 102 'BinaryExists', |
103 'FullUrlForRelativeUrl', | 103 'FullUrlForRelativeUrl', |
104 'GetCheckoutRoot', | 104 'GetCheckoutRoot', |
105 'GetRemoteURL', | |
106 'GetRevisionDate', | 105 'GetRevisionDate', |
107 'GetUsableRev', | 106 'GetUsableRev', |
108 'Svnversion', | 107 'Svnversion', |
109 'RunCommand', | 108 'RunCommand', |
110 'cleanup', | 109 'cleanup', |
111 'diff', | 110 'diff', |
112 'name', | 111 'name', |
113 'pack', | 112 'pack', |
114 'relpath', | 113 'relpath', |
115 'revert', | 114 'revert', |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 def testGITFakeHttpsUrl(self): | 155 def testGITFakeHttpsUrl(self): |
157 self.url = 'git+https://foo' | 156 self.url = 'git+https://foo' |
158 | 157 |
159 self.mox.ReplayAll() | 158 self.mox.ReplayAll() |
160 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 159 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
161 relpath=self.relpath) | 160 relpath=self.relpath) |
162 self.assertEqual(scm.url, 'https://foo') | 161 self.assertEqual(scm.url, 'https://foo') |
163 | 162 |
164 def testRunCommandException(self): | 163 def testRunCommandException(self): |
165 options = self.Options(verbose=False) | 164 options = self.Options(verbose=False) |
166 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 165 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
167 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 166 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
168 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | 167 |
169 self.mox.ReplayAll() | 168 self.mox.ReplayAll() |
170 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 169 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
171 relpath=self.relpath) | 170 relpath=self.relpath) |
172 exception = "Unsupported argument(s): %s" % ','.join(self.args) | 171 exception = "Unsupported argument(s): %s" % ','.join(self.args) |
173 self.assertRaisesError(exception, scm.RunCommand, | 172 self.assertRaisesError(exception, scm.RunCommand, |
174 'update', options, self.args) | 173 'update', options, self.args) |
175 | 174 |
176 def testRunCommandUnknown(self): | 175 def testRunCommandUnknown(self): |
177 # TODO(maruel): if ever used. | 176 # TODO(maruel): if ever used. |
178 pass | 177 pass |
179 | 178 |
180 def testRevertMissing(self): | 179 def testRevertMissing(self): |
181 options = self.Options(verbose=True) | 180 options = self.Options(verbose=True) |
182 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 181 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
183 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 182 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
184 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 183 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
185 ).AndReturn('1.5.1') | 184 ).AndReturn('1.5.1') |
186 # It'll to a checkout instead. | 185 # It'll to a checkout instead. |
| 186 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 187 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
187 # Checkout. | 188 # Checkout. |
188 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 189 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
189 parent = gclient_scm.os.path.dirname(self.base_path) | 190 parent = gclient_scm.os.path.dirname(self.base_path) |
190 gclient_scm.os.path.exists(parent).AndReturn(False) | 191 gclient_scm.os.path.exists(parent).AndReturn(False) |
191 gclient_scm.os.makedirs(parent) | 192 gclient_scm.os.makedirs(parent) |
192 gclient_scm.os.path.exists(parent).AndReturn(True) | 193 gclient_scm.os.path.exists(parent).AndReturn(True) |
193 files_list = self.mox.CreateMockAnything() | 194 files_list = self.mox.CreateMockAnything() |
194 gclient_scm.scm.SVN.RunAndGetFileList( | 195 gclient_scm.scm.SVN.RunAndGetFileList( |
195 options.verbose, | 196 options.verbose, |
196 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 197 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
197 cwd=self.root_dir, | 198 cwd=self.root_dir, |
198 file_list=files_list) | 199 file_list=files_list) |
199 | 200 |
200 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 201 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
201 ).AndReturn({'Revision': 100}) | 202 ).AndReturn({'Revision': 100}) |
202 | 203 |
203 self.mox.ReplayAll() | 204 self.mox.ReplayAll() |
204 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 205 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
205 relpath=self.relpath) | 206 relpath=self.relpath) |
206 scm.revert(options, self.args, files_list) | 207 scm.revert(options, self.args, files_list) |
207 self.checkstdout( | 208 self.checkstdout( |
208 ('\n_____ %s is missing, synching instead\n' % self.relpath)) | 209 ('\n_____ %s is missing, synching instead\n' % self.relpath)) |
209 | 210 |
210 def testRevertNoDotSvn(self): | 211 def testRevertNoDotSvn(self): |
211 options = self.Options(verbose=True, force=True) | 212 options = self.Options(verbose=True, force=True) |
212 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 213 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
213 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) | 214 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) |
| 215 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) |
| 216 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) |
214 # Checkout. | 217 # Checkout. |
| 218 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 219 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
215 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 220 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
216 parent = gclient_scm.os.path.dirname(self.base_path) | 221 parent = gclient_scm.os.path.dirname(self.base_path) |
217 gclient_scm.os.path.exists(parent).AndReturn(False) | 222 gclient_scm.os.path.exists(parent).AndReturn(False) |
218 gclient_scm.os.makedirs(parent) | 223 gclient_scm.os.makedirs(parent) |
219 gclient_scm.os.path.exists(parent).AndReturn(True) | 224 gclient_scm.os.path.exists(parent).AndReturn(True) |
220 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
221 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
222 files_list = self.mox.CreateMockAnything() | 225 files_list = self.mox.CreateMockAnything() |
223 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 226 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
224 ).AndReturn('1.6') | 227 ).AndReturn('1.6') |
225 gclient_scm.scm.SVN.RunAndGetFileList( | 228 gclient_scm.scm.SVN.RunAndGetFileList( |
226 options.verbose, | 229 options.verbose, |
227 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 230 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
228 cwd=self.root_dir, | 231 cwd=self.root_dir, |
229 file_list=files_list) | 232 file_list=files_list) |
230 gclient_scm.gclient_utils.rmtree(self.base_path) | 233 gclient_scm.gclient_utils.rmtree(self.base_path) |
231 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 234 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 334 |
332 # TODO(maruel): TEST REVISIONS!!! | 335 # TODO(maruel): TEST REVISIONS!!! |
333 # TODO(maruel): TEST RELOCATE!!! | 336 # TODO(maruel): TEST RELOCATE!!! |
334 def testUpdateCheckout(self): | 337 def testUpdateCheckout(self): |
335 options = self.Options(verbose=True) | 338 options = self.Options(verbose=True) |
336 file_info = gclient_scm.gclient_utils.PrintableObject() | 339 file_info = gclient_scm.gclient_utils.PrintableObject() |
337 file_info.root = 'blah' | 340 file_info.root = 'blah' |
338 file_info.url = self.url | 341 file_info.url = self.url |
339 file_info.uuid = 'ABC' | 342 file_info.uuid = 'ABC' |
340 file_info.revision = 42 | 343 file_info.revision = 42 |
| 344 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 345 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
341 # Checkout. | 346 # Checkout. |
342 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 347 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
343 parent = gclient_scm.os.path.dirname(self.base_path) | 348 parent = gclient_scm.os.path.dirname(self.base_path) |
344 gclient_scm.os.path.exists(parent).AndReturn(False) | 349 gclient_scm.os.path.exists(parent).AndReturn(False) |
345 gclient_scm.os.makedirs(parent) | 350 gclient_scm.os.makedirs(parent) |
346 gclient_scm.os.path.exists(parent).AndReturn(True) | 351 gclient_scm.os.path.exists(parent).AndReturn(True) |
347 files_list = self.mox.CreateMockAnything() | 352 files_list = self.mox.CreateMockAnything() |
348 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 353 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
349 ).AndReturn('1.5.1') | 354 ).AndReturn('1.5.1') |
350 gclient_scm.scm.SVN.RunAndGetFileList( | 355 gclient_scm.scm.SVN.RunAndGetFileList( |
(...skipping 11 matching lines...) Expand all Loading... |
362 def testUpdateUpdate(self): | 367 def testUpdateUpdate(self): |
363 options = self.Options(verbose=True) | 368 options = self.Options(verbose=True) |
364 options.force = True | 369 options.force = True |
365 options.nohooks = False | 370 options.nohooks = False |
366 file_info = { | 371 file_info = { |
367 'Repository Root': 'blah', | 372 'Repository Root': 'blah', |
368 'URL': self.url, | 373 'URL': self.url, |
369 'UUID': 'ABC', | 374 'UUID': 'ABC', |
370 'Revision': 42, | 375 'Revision': 42, |
371 } | 376 } |
372 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 377 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
373 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | 378 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
374 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 379 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
375 | 380 |
376 # Checkout or update. | 381 # Checkout or update. |
377 dotted_path = join(self.base_path, '.') | 382 dotted_path = join(self.base_path, '.') |
378 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 383 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
379 | 384 |
380 # Verify no locked files. | 385 # Verify no locked files. |
381 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) | 386 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) |
382 | 387 |
383 # Cheat a bit here. | 388 # Cheat a bit here. |
(...skipping 24 matching lines...) Expand all Loading... |
408 | 413 |
409 def testUpdateReset(self): | 414 def testUpdateReset(self): |
410 options = self.Options(verbose=True) | 415 options = self.Options(verbose=True) |
411 options.reset = True | 416 options.reset = True |
412 file_info = { | 417 file_info = { |
413 'Repository Root': 'blah', | 418 'Repository Root': 'blah', |
414 'URL': self.url, | 419 'URL': self.url, |
415 'UUID': 'ABC', | 420 'UUID': 'ABC', |
416 'Revision': 42, | 421 'Revision': 42, |
417 } | 422 } |
418 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 423 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
419 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | 424 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
420 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 425 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
421 | 426 |
422 # Checkout or update. | 427 # Checkout or update. |
423 dotted_path = join(self.base_path, '.') | 428 dotted_path = join(self.base_path, '.') |
424 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 429 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
425 | 430 |
426 # Create an untracked file and directory. | 431 # Create an untracked file and directory. |
427 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | 432 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path |
428 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 433 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) |
429 | 434 |
(...skipping 14 matching lines...) Expand all Loading... |
444 options = self.Options(verbose=True) | 449 options = self.Options(verbose=True) |
445 options.reset = True | 450 options.reset = True |
446 options.delete_unversioned_trees = True | 451 options.delete_unversioned_trees = True |
447 | 452 |
448 file_info = { | 453 file_info = { |
449 'Repository Root': 'blah', | 454 'Repository Root': 'blah', |
450 'URL': self.url, | 455 'URL': self.url, |
451 'UUID': 'ABC', | 456 'UUID': 'ABC', |
452 'Revision': 42, | 457 'Revision': 42, |
453 } | 458 } |
454 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 459 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
455 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | 460 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
456 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 461 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
457 | 462 |
458 # Checkout or update. | 463 # Checkout or update. |
459 dotted_path = join(self.base_path, '.') | 464 dotted_path = join(self.base_path, '.') |
460 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 465 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
461 | 466 |
462 # Create an untracked file and directory. | 467 # Create an untracked file and directory. |
463 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | 468 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path |
464 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 469 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) |
465 | 470 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 515 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
511 always=True, | 516 always=True, |
512 cwd=self.root_dir) | 517 cwd=self.root_dir) |
513 gclient_scm.scm.SVN.RunAndGetFileList( | 518 gclient_scm.scm.SVN.RunAndGetFileList( |
514 options.verbose, | 519 options.verbose, |
515 ['update', 'DEPS', '--ignore-externals'], | 520 ['update', 'DEPS', '--ignore-externals'], |
516 cwd=self.base_path, | 521 cwd=self.base_path, |
517 file_list=files_list) | 522 file_list=files_list) |
518 | 523 |
519 # Now we fall back on scm.update(). | 524 # Now we fall back on scm.update(). |
520 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 525 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
521 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | 526 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
522 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 527 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
523 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 528 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
524 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 529 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
525 ).AndReturn(file_info) | 530 ).AndReturn(file_info) |
526 | 531 |
527 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 532 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
528 ).AndReturn({'Revision': 100}) | 533 ).AndReturn({'Revision': 100}) |
529 | 534 |
530 self.mox.ReplayAll() | 535 self.mox.ReplayAll() |
531 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 536 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 585 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
581 always=True, | 586 always=True, |
582 cwd=self.root_dir) | 587 cwd=self.root_dir) |
583 gclient_scm.scm.SVN.RunAndGetFileList( | 588 gclient_scm.scm.SVN.RunAndGetFileList( |
584 options.verbose, | 589 options.verbose, |
585 ['update', 'DEPS', '--ignore-externals'], | 590 ['update', 'DEPS', '--ignore-externals'], |
586 cwd=self.base_path, | 591 cwd=self.base_path, |
587 file_list=files_list) | 592 file_list=files_list) |
588 | 593 |
589 # Now we fall back on scm.update(). | 594 # Now we fall back on scm.update(). |
590 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 595 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
591 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | 596 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
592 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 597 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
593 gclient_scm.scm.SVN._CaptureInfo( | 598 gclient_scm.scm.SVN._CaptureInfo( |
594 [], join(self.base_path, ".")).AndReturn(file_info) | 599 [], join(self.base_path, ".")).AndReturn(file_info) |
595 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 600 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
596 ).AndReturn(file_info) | 601 ).AndReturn(file_info) |
597 | 602 |
598 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 603 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
599 ).AndReturn({'Revision': 100}) | 604 ).AndReturn({'Revision': 100}) |
600 | 605 |
601 self.mox.ReplayAll() | 606 self.mox.ReplayAll() |
(...skipping 14 matching lines...) Expand all Loading... |
616 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 621 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
617 ).AndReturn('1.5.1') | 622 ).AndReturn('1.5.1') |
618 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) | 623 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) |
619 | 624 |
620 # Verify no locked files. | 625 # Verify no locked files. |
621 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') | 626 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') |
622 ).AndReturn([]) | 627 ).AndReturn([]) |
623 | 628 |
624 # Now we fall back on scm.update(). | 629 # Now we fall back on scm.update(). |
625 files_list = self.mox.CreateMockAnything() | 630 files_list = self.mox.CreateMockAnything() |
626 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 631 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
627 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | 632 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
628 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 633 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
629 gclient_scm.scm.SVN._CaptureInfo( | 634 gclient_scm.scm.SVN._CaptureInfo( |
630 [], join(self.base_path, '.')).AndReturn(file_info) | 635 [], join(self.base_path, '.')).AndReturn(file_info) |
631 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 636 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
632 ).AndReturn(file_info) | 637 ).AndReturn(file_info) |
633 | 638 |
634 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 639 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
635 ).AndReturn({'Revision': 100}) | 640 ).AndReturn({'Revision': 100}) |
636 | 641 |
637 self.mox.ReplayAll() | 642 self.mox.ReplayAll() |
638 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 643 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
639 relpath=self.relpath) | 644 relpath=self.relpath) |
640 scm.updatesingle(options, ['DEPS'], files_list) | 645 scm.updatesingle(options, ['DEPS'], files_list) |
641 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 646 self.checkstdout('\n_____ %s at 42\n' % self.relpath) |
642 | 647 |
643 def testUpdateGitSvn(self): | 648 def testUpdateGit(self): |
644 options = self.Options(verbose=True) | 649 options = self.Options(verbose=True) |
645 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 650 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
646 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 651 gclient_scm.os.path.exists(file_path).AndReturn(True) |
647 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True) | |
648 | 652 |
649 self.mox.ReplayAll() | 653 self.mox.ReplayAll() |
650 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 654 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
651 relpath=self.relpath) | 655 relpath=self.relpath) |
652 file_list = [] | 656 file_list = [] |
653 scm.update(options, self.args, file_list) | 657 scm.update(options, self.args, file_list) |
654 self.checkstdout( | 658 self.checkstdout( |
655 ('________ %s looks like git-svn; skipping.\n' % self.relpath)) | 659 ('________ found .git directory; skipping %s\n' % self.relpath)) |
| 660 |
| 661 def testUpdateHg(self): |
| 662 options = self.Options(verbose=True) |
| 663 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 664 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True) |
| 665 |
| 666 self.mox.ReplayAll() |
| 667 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 668 relpath=self.relpath) |
| 669 file_list = [] |
| 670 scm.update(options, self.args, file_list) |
| 671 self.checkstdout( |
| 672 ('________ found .hg directory; skipping %s\n' % self.relpath)) |
656 | 673 |
657 def testGetUsableRevSVN(self): | 674 def testGetUsableRevSVN(self): |
658 # pylint: disable=E1101 | 675 # pylint: disable=E1101 |
659 options = self.Options(verbose=True) | 676 options = self.Options(verbose=True) |
660 | 677 |
661 # Mock SVN revision validity checking. | 678 # Mock SVN revision validity checking. |
662 self.mox.StubOutWithMock( | 679 self.mox.StubOutWithMock( |
663 gclient_scm.scm.SVN, 'IsValidRevision', True) | 680 gclient_scm.scm.SVN, 'IsValidRevision', True) |
664 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 1) | 681 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 1) |
665 ).AndReturn(True) | 682 ).AndReturn(True) |
666 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 'fake') | 683 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 'fake') |
667 ).AndReturn(False) | 684 ).AndReturn(False) |
668 | 685 |
669 self.mox.ReplayAll() | 686 self.mox.ReplayAll() |
670 | 687 |
671 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir) | 688 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir) |
672 # With an SVN checkout, 1 an example of a valid usable rev. | 689 # With an SVN checkout, 1 an example of a valid usable rev. |
673 self.assertEquals(svn_scm.GetUsableRev(1, options), 1) | 690 self.assertEquals(svn_scm.GetUsableRev(1, options), 1) |
674 # With an SVN checkout, a fake or unknown rev should raise an excpetion. | 691 # With an SVN checkout, a fake or unknown rev should raise an excpetion. |
675 self.assertRaises(gclient_scm.gclient_utils.Error, | 692 self.assertRaises(gclient_scm.gclient_utils.Error, |
676 svn_scm.GetUsableRev, 'fake', options) | 693 svn_scm.GetUsableRev, 'fake', options) |
677 | 694 |
678 def testGetRemoteURL(self): | |
679 self.mox.UnsetStubs() | |
680 options = self.Options(verbose=True) | |
681 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture', True) | |
682 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
683 relpath=self.relpath) | |
684 | |
685 if svn_scm.relpath: | |
686 cwd = os.path.join(svn_scm._root_dir, svn_scm.relpath) | |
687 else: | |
688 cwd = svn_scm._root_dir | |
689 | |
690 gclient_scm.scm.SVN.Capture(['info', '--xml', os.curdir], cwd).AndReturn( | |
691 """<?xml version="1.0"?> | |
692 <info> | |
693 <entry | |
694 path="." | |
695 revision="1234" | |
696 kind="dir"> | |
697 <url>%s</url> | |
698 <repository> | |
699 <root>https://dummy.repo.com/svn</root> | |
700 <uuid>FAKE</uuid> | |
701 </repository> | |
702 <wc-info> | |
703 <schedule>normal</schedule> | |
704 <depth>infinity</depth> | |
705 </wc-info> | |
706 <commit | |
707 revision="1234"> | |
708 <author>fakedev@chromium.org</author> | |
709 <date>2013-11-14T15:08:21.757885Z</date> | |
710 </commit> | |
711 </entry> | |
712 </info> | |
713 """ % svn_scm.url) | |
714 | |
715 self.mox.ReplayAll() | |
716 | |
717 self.assertEquals(svn_scm.GetRemoteURL(options), self.url) | |
718 | |
719 | |
720 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, | 695 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, |
721 unittest.TestCase): | 696 unittest.TestCase): |
722 """This class doesn't use pymox.""" | 697 """This class doesn't use pymox.""" |
723 class OptionsObject(object): | 698 class OptionsObject(object): |
724 def __init__(self, verbose=False, revision=None): | 699 def __init__(self, verbose=False, revision=None): |
725 self.verbose = verbose | 700 self.verbose = verbose |
726 self.revision = revision | 701 self.revision = revision |
727 self.manually_grab_svn_rev = True | 702 self.manually_grab_svn_rev = True |
728 self.deps_os = None | 703 self.deps_os = None |
729 self.force = False | 704 self.force = False |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists | 810 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists |
836 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists | 811 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists |
837 | 812 |
838 | 813 |
839 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): | 814 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): |
840 def testDir(self): | 815 def testDir(self): |
841 members = [ | 816 members = [ |
842 'BinaryExists', | 817 'BinaryExists', |
843 'FullUrlForRelativeUrl', | 818 'FullUrlForRelativeUrl', |
844 'GetCheckoutRoot', | 819 'GetCheckoutRoot', |
845 'GetRemoteURL', | |
846 'GetRevisionDate', | 820 'GetRevisionDate', |
847 'GetUsableRev', | 821 'GetUsableRev', |
848 'RunCommand', | 822 'RunCommand', |
849 'cache_dir', | 823 'cache_dir', |
850 'cache_locks', | 824 'cache_locks', |
851 'cleanup', | 825 'cleanup', |
852 'diff', | 826 'diff', |
853 'name', | 827 'name', |
854 'pack', | 828 'pack', |
855 'UpdateSubmoduleConfig', | 829 'UpdateSubmoduleConfig', |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 self.assertEquals(git_svn_scm.GetUsableRev('3', options), | 1178 self.assertEquals(git_svn_scm.GetUsableRev('3', options), |
1205 self.fake_hash_2) | 1179 self.fake_hash_2) |
1206 # Given a git sha1 with a git-svn checkout, it should be used as is. | 1180 # Given a git sha1 with a git-svn checkout, it should be used as is. |
1207 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), | 1181 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), |
1208 self.fake_hash_1) | 1182 self.fake_hash_1) |
1209 # We currently check for seemingly valid SVN revisions by assuming 6 digit | 1183 # We currently check for seemingly valid SVN revisions by assuming 6 digit |
1210 # numbers, so assure that numeric revs >= 1000000 don't work. | 1184 # numbers, so assure that numeric revs >= 1000000 don't work. |
1211 self.assertRaises(gclient_scm.gclient_utils.Error, | 1185 self.assertRaises(gclient_scm.gclient_utils.Error, |
1212 git_svn_scm.GetUsableRev, too_big, options) | 1186 git_svn_scm.GetUsableRev, too_big, options) |
1213 | 1187 |
1214 def testGetRemoteURL(self): | |
1215 options = self.Options(verbose=True) | |
1216 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Capture', True) | |
1217 git_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
1218 relpath=self.relpath) | |
1219 git_scm._Capture(['config', 'remote.origin.url'], cwd='/tmp/fake' | |
1220 ).AndReturn('%s\n' % git_scm.url) | |
1221 | |
1222 self.mox.ReplayAll() | |
1223 | |
1224 self.assertEquals(git_scm.GetRemoteURL(options), self.url) | |
1225 | |
1226 | 1188 |
1227 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): | 1189 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): |
1228 def testUpdateUpdate(self): | 1190 def testUpdateUpdate(self): |
1229 if not self.enabled: | 1191 if not self.enabled: |
1230 return | 1192 return |
1231 options = self.Options() | 1193 options = self.Options() |
1232 expected_file_list = [] | 1194 expected_file_list = [] |
1233 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 1195 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
1234 relpath=self.relpath) | 1196 relpath=self.relpath) |
1235 file_list = [] | 1197 file_list = [] |
1236 options.revision = 'unmanaged' | 1198 options.revision = 'unmanaged' |
1237 scm.update(options, (), file_list) | 1199 scm.update(options, (), file_list) |
1238 self.assertEquals(file_list, expected_file_list) | 1200 self.assertEquals(file_list, expected_file_list) |
1239 self.assertEquals(scm.revinfo(options, (), None), | 1201 self.assertEquals(scm.revinfo(options, (), None), |
1240 '069c602044c5388d2d15c3f875b057c852003458') | 1202 '069c602044c5388d2d15c3f875b057c852003458') |
1241 self.checkstdout('________ unmanaged solution; skipping .\n') | 1203 self.checkstdout('________ unmanaged solution; skipping .\n') |
1242 | 1204 |
1243 | 1205 |
1244 if __name__ == '__main__': | 1206 if __name__ == '__main__': |
1245 if '-v' in sys.argv: | 1207 if '-v' in sys.argv: |
1246 logging.basicConfig( | 1208 logging.basicConfig( |
1247 level=logging.DEBUG, | 1209 level=logging.DEBUG, |
1248 format='%(asctime).19s %(levelname)s %(filename)s:' | 1210 format='%(asctime).19s %(levelname)s %(filename)s:' |
1249 '%(lineno)s %(message)s') | 1211 '%(lineno)s %(message)s') |
1250 unittest.main() | 1212 unittest.main() |
1251 | 1213 |
1252 # vim: ts=2:sw=2:tw=80:et: | 1214 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |