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