| 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) |
| 165 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 166 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 166 | 167 |
| 167 self.mox.ReplayAll() | 168 self.mox.ReplayAll() |
| 168 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, |
| 169 relpath=self.relpath) | 170 relpath=self.relpath) |
| 170 exception = "Unsupported argument(s): %s" % ','.join(self.args) | 171 exception = "Unsupported argument(s): %s" % ','.join(self.args) |
| 171 self.assertRaisesError(exception, scm.RunCommand, | 172 self.assertRaisesError(exception, scm.RunCommand, |
| 172 'update', options, self.args) | 173 'update', options, self.args) |
| 173 | 174 |
| 174 def testRunCommandUnknown(self): | 175 def testRunCommandUnknown(self): |
| 175 # TODO(maruel): if ever used. | 176 # TODO(maruel): if ever used. |
| 176 pass | 177 pass |
| 177 | 178 |
| 178 def testRevertMissing(self): | 179 def testRevertMissing(self): |
| 179 options = self.Options(verbose=True) | 180 options = self.Options(verbose=True) |
| 180 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 181 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
| 181 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 182 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
| 182 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 183 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
| 183 ).AndReturn('1.5.1') | 184 ).AndReturn('1.5.1') |
| 184 # 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) |
| 185 # Checkout. | 188 # Checkout. |
| 186 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 189 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
| 187 parent = gclient_scm.os.path.dirname(self.base_path) | 190 parent = gclient_scm.os.path.dirname(self.base_path) |
| 188 gclient_scm.os.path.exists(parent).AndReturn(False) | 191 gclient_scm.os.path.exists(parent).AndReturn(False) |
| 189 gclient_scm.os.makedirs(parent) | 192 gclient_scm.os.makedirs(parent) |
| 190 gclient_scm.os.path.exists(parent).AndReturn(True) | 193 gclient_scm.os.path.exists(parent).AndReturn(True) |
| 191 files_list = self.mox.CreateMockAnything() | 194 files_list = self.mox.CreateMockAnything() |
| 192 gclient_scm.scm.SVN.RunAndGetFileList( | 195 gclient_scm.scm.SVN.RunAndGetFileList( |
| 193 options.verbose, | 196 options.verbose, |
| 194 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 197 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
| 195 cwd=self.root_dir, | 198 cwd=self.root_dir, |
| 196 file_list=files_list) | 199 file_list=files_list) |
| 197 | 200 |
| 198 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 201 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 199 ).AndReturn({'Revision': 100}) | 202 ).AndReturn({'Revision': 100}) |
| 200 | 203 |
| 201 self.mox.ReplayAll() | 204 self.mox.ReplayAll() |
| 202 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, |
| 203 relpath=self.relpath) | 206 relpath=self.relpath) |
| 204 scm.revert(options, self.args, files_list) | 207 scm.revert(options, self.args, files_list) |
| 205 self.checkstdout( | 208 self.checkstdout( |
| 206 ('\n_____ %s is missing, synching instead\n' % self.relpath)) | 209 ('\n_____ %s is missing, synching instead\n' % self.relpath)) |
| 207 | 210 |
| 208 def testRevertNoDotSvn(self): | 211 def testRevertNoDotSvn(self): |
| 209 options = self.Options(verbose=True, force=True) | 212 options = self.Options(verbose=True, force=True) |
| 210 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 213 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
| 211 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) |
| 212 # 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) |
| 213 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 220 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
| 214 parent = gclient_scm.os.path.dirname(self.base_path) | 221 parent = gclient_scm.os.path.dirname(self.base_path) |
| 215 gclient_scm.os.path.exists(parent).AndReturn(False) | 222 gclient_scm.os.path.exists(parent).AndReturn(False) |
| 216 gclient_scm.os.makedirs(parent) | 223 gclient_scm.os.makedirs(parent) |
| 217 gclient_scm.os.path.exists(parent).AndReturn(True) | 224 gclient_scm.os.path.exists(parent).AndReturn(True) |
| 218 files_list = self.mox.CreateMockAnything() | 225 files_list = self.mox.CreateMockAnything() |
| 219 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 226 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
| 220 ).AndReturn('1.6') | 227 ).AndReturn('1.6') |
| 221 gclient_scm.scm.SVN.RunAndGetFileList( | 228 gclient_scm.scm.SVN.RunAndGetFileList( |
| 222 options.verbose, | 229 options.verbose, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 334 |
| 328 # TODO(maruel): TEST REVISIONS!!! | 335 # TODO(maruel): TEST REVISIONS!!! |
| 329 # TODO(maruel): TEST RELOCATE!!! | 336 # TODO(maruel): TEST RELOCATE!!! |
| 330 def testUpdateCheckout(self): | 337 def testUpdateCheckout(self): |
| 331 options = self.Options(verbose=True) | 338 options = self.Options(verbose=True) |
| 332 file_info = gclient_scm.gclient_utils.PrintableObject() | 339 file_info = gclient_scm.gclient_utils.PrintableObject() |
| 333 file_info.root = 'blah' | 340 file_info.root = 'blah' |
| 334 file_info.url = self.url | 341 file_info.url = self.url |
| 335 file_info.uuid = 'ABC' | 342 file_info.uuid = 'ABC' |
| 336 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) |
| 337 # Checkout. | 346 # Checkout. |
| 338 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 347 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
| 339 parent = gclient_scm.os.path.dirname(self.base_path) | 348 parent = gclient_scm.os.path.dirname(self.base_path) |
| 340 gclient_scm.os.path.exists(parent).AndReturn(False) | 349 gclient_scm.os.path.exists(parent).AndReturn(False) |
| 341 gclient_scm.os.makedirs(parent) | 350 gclient_scm.os.makedirs(parent) |
| 342 gclient_scm.os.path.exists(parent).AndReturn(True) | 351 gclient_scm.os.path.exists(parent).AndReturn(True) |
| 343 files_list = self.mox.CreateMockAnything() | 352 files_list = self.mox.CreateMockAnything() |
| 344 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 353 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
| 345 ).AndReturn('1.5.1') | 354 ).AndReturn('1.5.1') |
| 346 gclient_scm.scm.SVN.RunAndGetFileList( | 355 gclient_scm.scm.SVN.RunAndGetFileList( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 358 def testUpdateUpdate(self): | 367 def testUpdateUpdate(self): |
| 359 options = self.Options(verbose=True) | 368 options = self.Options(verbose=True) |
| 360 options.force = True | 369 options.force = True |
| 361 options.nohooks = False | 370 options.nohooks = False |
| 362 file_info = { | 371 file_info = { |
| 363 'Repository Root': 'blah', | 372 'Repository Root': 'blah', |
| 364 'URL': self.url, | 373 'URL': self.url, |
| 365 'UUID': 'ABC', | 374 'UUID': 'ABC', |
| 366 'Revision': 42, | 375 'Revision': 42, |
| 367 } | 376 } |
| 377 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 378 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 368 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 379 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 369 | 380 |
| 370 # Checkout or update. | 381 # Checkout or update. |
| 371 dotted_path = join(self.base_path, '.') | 382 dotted_path = join(self.base_path, '.') |
| 372 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 383 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
| 373 | 384 |
| 374 # Verify no locked files. | 385 # Verify no locked files. |
| 375 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) | 386 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) |
| 376 | 387 |
| 377 # Cheat a bit here. | 388 # Cheat a bit here. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 402 | 413 |
| 403 def testUpdateReset(self): | 414 def testUpdateReset(self): |
| 404 options = self.Options(verbose=True) | 415 options = self.Options(verbose=True) |
| 405 options.reset = True | 416 options.reset = True |
| 406 file_info = { | 417 file_info = { |
| 407 'Repository Root': 'blah', | 418 'Repository Root': 'blah', |
| 408 'URL': self.url, | 419 'URL': self.url, |
| 409 'UUID': 'ABC', | 420 'UUID': 'ABC', |
| 410 'Revision': 42, | 421 'Revision': 42, |
| 411 } | 422 } |
| 423 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 424 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 412 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 425 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 413 | 426 |
| 414 # Checkout or update. | 427 # Checkout or update. |
| 415 dotted_path = join(self.base_path, '.') | 428 dotted_path = join(self.base_path, '.') |
| 416 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 429 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
| 417 | 430 |
| 418 # Create an untracked file and directory. | 431 # Create an untracked file and directory. |
| 419 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | 432 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path |
| 420 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 433 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) |
| 421 | 434 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 436 options = self.Options(verbose=True) | 449 options = self.Options(verbose=True) |
| 437 options.reset = True | 450 options.reset = True |
| 438 options.delete_unversioned_trees = True | 451 options.delete_unversioned_trees = True |
| 439 | 452 |
| 440 file_info = { | 453 file_info = { |
| 441 'Repository Root': 'blah', | 454 'Repository Root': 'blah', |
| 442 'URL': self.url, | 455 'URL': self.url, |
| 443 'UUID': 'ABC', | 456 'UUID': 'ABC', |
| 444 'Revision': 42, | 457 'Revision': 42, |
| 445 } | 458 } |
| 459 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 460 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 446 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 461 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 447 | 462 |
| 448 # Checkout or update. | 463 # Checkout or update. |
| 449 dotted_path = join(self.base_path, '.') | 464 dotted_path = join(self.base_path, '.') |
| 450 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 465 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
| 451 | 466 |
| 452 # Create an untracked file and directory. | 467 # Create an untracked file and directory. |
| 453 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | 468 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path |
| 454 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 469 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) |
| 455 | 470 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 515 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
| 501 always=True, | 516 always=True, |
| 502 cwd=self.root_dir) | 517 cwd=self.root_dir) |
| 503 gclient_scm.scm.SVN.RunAndGetFileList( | 518 gclient_scm.scm.SVN.RunAndGetFileList( |
| 504 options.verbose, | 519 options.verbose, |
| 505 ['update', 'DEPS', '--ignore-externals'], | 520 ['update', 'DEPS', '--ignore-externals'], |
| 506 cwd=self.base_path, | 521 cwd=self.base_path, |
| 507 file_list=files_list) | 522 file_list=files_list) |
| 508 | 523 |
| 509 # Now we fall back on scm.update(). | 524 # Now we fall back on scm.update(). |
| 525 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 526 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 510 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 527 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 511 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 528 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
| 512 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 529 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 513 ).AndReturn(file_info) | 530 ).AndReturn(file_info) |
| 514 | 531 |
| 515 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 532 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 516 ).AndReturn({'Revision': 100}) | 533 ).AndReturn({'Revision': 100}) |
| 517 | 534 |
| 518 self.mox.ReplayAll() | 535 self.mox.ReplayAll() |
| 519 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... |
| 568 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 585 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
| 569 always=True, | 586 always=True, |
| 570 cwd=self.root_dir) | 587 cwd=self.root_dir) |
| 571 gclient_scm.scm.SVN.RunAndGetFileList( | 588 gclient_scm.scm.SVN.RunAndGetFileList( |
| 572 options.verbose, | 589 options.verbose, |
| 573 ['update', 'DEPS', '--ignore-externals'], | 590 ['update', 'DEPS', '--ignore-externals'], |
| 574 cwd=self.base_path, | 591 cwd=self.base_path, |
| 575 file_list=files_list) | 592 file_list=files_list) |
| 576 | 593 |
| 577 # Now we fall back on scm.update(). | 594 # Now we fall back on scm.update(). |
| 595 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 596 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 578 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 597 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 579 gclient_scm.scm.SVN._CaptureInfo( | 598 gclient_scm.scm.SVN._CaptureInfo( |
| 580 [], join(self.base_path, ".")).AndReturn(file_info) | 599 [], join(self.base_path, ".")).AndReturn(file_info) |
| 581 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 600 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 582 ).AndReturn(file_info) | 601 ).AndReturn(file_info) |
| 583 | 602 |
| 584 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 603 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 585 ).AndReturn({'Revision': 100}) | 604 ).AndReturn({'Revision': 100}) |
| 586 | 605 |
| 587 self.mox.ReplayAll() | 606 self.mox.ReplayAll() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 602 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 621 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None |
| 603 ).AndReturn('1.5.1') | 622 ).AndReturn('1.5.1') |
| 604 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) |
| 605 | 624 |
| 606 # Verify no locked files. | 625 # Verify no locked files. |
| 607 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') | 626 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') |
| 608 ).AndReturn([]) | 627 ).AndReturn([]) |
| 609 | 628 |
| 610 # Now we fall back on scm.update(). | 629 # Now we fall back on scm.update(). |
| 611 files_list = self.mox.CreateMockAnything() | 630 files_list = self.mox.CreateMockAnything() |
| 631 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 632 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 612 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 633 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 613 gclient_scm.scm.SVN._CaptureInfo( | 634 gclient_scm.scm.SVN._CaptureInfo( |
| 614 [], join(self.base_path, '.')).AndReturn(file_info) | 635 [], join(self.base_path, '.')).AndReturn(file_info) |
| 615 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 636 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 616 ).AndReturn(file_info) | 637 ).AndReturn(file_info) |
| 617 | 638 |
| 618 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 639 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' |
| 619 ).AndReturn({'Revision': 100}) | 640 ).AndReturn({'Revision': 100}) |
| 620 | 641 |
| 621 self.mox.ReplayAll() | 642 self.mox.ReplayAll() |
| 622 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, |
| 623 relpath=self.relpath) | 644 relpath=self.relpath) |
| 624 scm.updatesingle(options, ['DEPS'], files_list) | 645 scm.updatesingle(options, ['DEPS'], files_list) |
| 625 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 646 self.checkstdout('\n_____ %s at 42\n' % self.relpath) |
| 626 | 647 |
| 648 def testUpdateGit(self): |
| 649 options = self.Options(verbose=True) |
| 650 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
| 651 gclient_scm.os.path.exists(file_path).AndReturn(True) |
| 652 |
| 653 self.mox.ReplayAll() |
| 654 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 655 relpath=self.relpath) |
| 656 file_list = [] |
| 657 scm.update(options, self.args, file_list) |
| 658 self.checkstdout( |
| 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)) |
| 673 |
| 627 def testGetUsableRevSVN(self): | 674 def testGetUsableRevSVN(self): |
| 628 # pylint: disable=E1101 | 675 # pylint: disable=E1101 |
| 629 options = self.Options(verbose=True) | 676 options = self.Options(verbose=True) |
| 630 | 677 |
| 631 # Mock SVN revision validity checking. | 678 # Mock SVN revision validity checking. |
| 632 self.mox.StubOutWithMock( | 679 self.mox.StubOutWithMock( |
| 633 gclient_scm.scm.SVN, 'IsValidRevision', True) | 680 gclient_scm.scm.SVN, 'IsValidRevision', True) |
| 634 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 1) | 681 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 1) |
| 635 ).AndReturn(True) | 682 ).AndReturn(True) |
| 636 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 'fake') | 683 gclient_scm.scm.SVN.IsValidRevision(url='%s@%s' % (self.url, 'fake') |
| 637 ).AndReturn(False) | 684 ).AndReturn(False) |
| 638 | 685 |
| 639 self.mox.ReplayAll() | 686 self.mox.ReplayAll() |
| 640 | 687 |
| 641 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) |
| 642 # 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. |
| 643 self.assertEquals(svn_scm.GetUsableRev(1, options), 1) | 690 self.assertEquals(svn_scm.GetUsableRev(1, options), 1) |
| 644 # 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. |
| 645 self.assertRaises(gclient_scm.gclient_utils.Error, | 692 self.assertRaises(gclient_scm.gclient_utils.Error, |
| 646 svn_scm.GetUsableRev, 'fake', options) | 693 svn_scm.GetUsableRev, 'fake', options) |
| 647 | 694 |
| 648 def testGetRemoteURL(self): | |
| 649 self.mox.UnsetStubs() | |
| 650 options = self.Options(verbose=True) | |
| 651 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture', True) | |
| 652 svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
| 653 relpath=self.relpath) | |
| 654 | |
| 655 if svn_scm.relpath: | |
| 656 cwd = os.path.join(svn_scm._root_dir, svn_scm.relpath) | |
| 657 else: | |
| 658 cwd = svn_scm._root_dir | |
| 659 | |
| 660 gclient_scm.scm.SVN.Capture(['info', '--xml', os.curdir], cwd).AndReturn( | |
| 661 """<?xml version="1.0"?> | |
| 662 <info> | |
| 663 <entry | |
| 664 path="." | |
| 665 revision="1234" | |
| 666 kind="dir"> | |
| 667 <url>%s</url> | |
| 668 <repository> | |
| 669 <root>https://dummy.repo.com/svn</root> | |
| 670 <uuid>FAKE</uuid> | |
| 671 </repository> | |
| 672 <wc-info> | |
| 673 <schedule>normal</schedule> | |
| 674 <depth>infinity</depth> | |
| 675 </wc-info> | |
| 676 <commit | |
| 677 revision="1234"> | |
| 678 <author>fakedev@chromium.org</author> | |
| 679 <date>2013-11-14T15:08:21.757885Z</date> | |
| 680 </commit> | |
| 681 </entry> | |
| 682 </info> | |
| 683 """ % svn_scm.url) | |
| 684 | |
| 685 self.mox.ReplayAll() | |
| 686 | |
| 687 self.assertEquals(svn_scm.GetRemoteURL(options), self.url) | |
| 688 | |
| 689 | |
| 690 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, | 695 class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, |
| 691 unittest.TestCase): | 696 unittest.TestCase): |
| 692 """This class doesn't use pymox.""" | 697 """This class doesn't use pymox.""" |
| 693 class OptionsObject(object): | 698 class OptionsObject(object): |
| 694 def __init__(self, verbose=False, revision=None): | 699 def __init__(self, verbose=False, revision=None): |
| 695 self.verbose = verbose | 700 self.verbose = verbose |
| 696 self.revision = revision | 701 self.revision = revision |
| 697 self.manually_grab_svn_rev = True | 702 self.manually_grab_svn_rev = True |
| 698 self.deps_os = None | 703 self.deps_os = None |
| 699 self.force = False | 704 self.force = False |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists | 810 gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists |
| 806 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists | 811 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists |
| 807 | 812 |
| 808 | 813 |
| 809 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): | 814 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): |
| 810 def testDir(self): | 815 def testDir(self): |
| 811 members = [ | 816 members = [ |
| 812 'BinaryExists', | 817 'BinaryExists', |
| 813 'FullUrlForRelativeUrl', | 818 'FullUrlForRelativeUrl', |
| 814 'GetCheckoutRoot', | 819 'GetCheckoutRoot', |
| 815 'GetRemoteURL', | |
| 816 'GetRevisionDate', | 820 'GetRevisionDate', |
| 817 'GetUsableRev', | 821 'GetUsableRev', |
| 818 'RunCommand', | 822 'RunCommand', |
| 819 'cache_dir', | 823 'cache_dir', |
| 820 'cache_locks', | 824 'cache_locks', |
| 821 'cleanup', | 825 'cleanup', |
| 822 'diff', | 826 'diff', |
| 823 'name', | 827 'name', |
| 824 'pack', | 828 'pack', |
| 825 'UpdateSubmoduleConfig', | 829 'UpdateSubmoduleConfig', |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 self.assertEquals(git_svn_scm.GetUsableRev('3', options), | 1178 self.assertEquals(git_svn_scm.GetUsableRev('3', options), |
| 1175 self.fake_hash_2) | 1179 self.fake_hash_2) |
| 1176 # 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. |
| 1177 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), | 1181 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), |
| 1178 self.fake_hash_1) | 1182 self.fake_hash_1) |
| 1179 # 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 |
| 1180 # numbers, so assure that numeric revs >= 1000000 don't work. | 1184 # numbers, so assure that numeric revs >= 1000000 don't work. |
| 1181 self.assertRaises(gclient_scm.gclient_utils.Error, | 1185 self.assertRaises(gclient_scm.gclient_utils.Error, |
| 1182 git_svn_scm.GetUsableRev, too_big, options) | 1186 git_svn_scm.GetUsableRev, too_big, options) |
| 1183 | 1187 |
| 1184 def testGetRemoteURL(self): | |
| 1185 options = self.Options(verbose=True) | |
| 1186 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Capture', True) | |
| 1187 git_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
| 1188 relpath=self.relpath) | |
| 1189 git_scm._Capture(['config', 'remote.origin.url'], cwd='/tmp/fake' | |
| 1190 ).AndReturn('%s\n' % git_scm.url) | |
| 1191 | |
| 1192 self.mox.ReplayAll() | |
| 1193 | |
| 1194 self.assertEquals(git_scm.GetRemoteURL(options), self.url) | |
| 1195 | |
| 1196 | 1188 |
| 1197 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): | 1189 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): |
| 1198 def testUpdateUpdate(self): | 1190 def testUpdateUpdate(self): |
| 1199 if not self.enabled: | 1191 if not self.enabled: |
| 1200 return | 1192 return |
| 1201 options = self.Options() | 1193 options = self.Options() |
| 1202 expected_file_list = [] | 1194 expected_file_list = [] |
| 1203 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, |
| 1204 relpath=self.relpath) | 1196 relpath=self.relpath) |
| 1205 file_list = [] | 1197 file_list = [] |
| 1206 options.revision = 'unmanaged' | 1198 options.revision = 'unmanaged' |
| 1207 scm.update(options, (), file_list) | 1199 scm.update(options, (), file_list) |
| 1208 self.assertEquals(file_list, expected_file_list) | 1200 self.assertEquals(file_list, expected_file_list) |
| 1209 self.assertEquals(scm.revinfo(options, (), None), | 1201 self.assertEquals(scm.revinfo(options, (), None), |
| 1210 '069c602044c5388d2d15c3f875b057c852003458') | 1202 '069c602044c5388d2d15c3f875b057c852003458') |
| 1211 self.checkstdout('________ unmanaged solution; skipping .\n') | 1203 self.checkstdout('________ unmanaged solution; skipping .\n') |
| 1212 | 1204 |
| 1213 | 1205 |
| 1214 if __name__ == '__main__': | 1206 if __name__ == '__main__': |
| 1215 if '-v' in sys.argv: | 1207 if '-v' in sys.argv: |
| 1216 logging.basicConfig( | 1208 logging.basicConfig( |
| 1217 level=logging.DEBUG, | 1209 level=logging.DEBUG, |
| 1218 format='%(asctime).19s %(levelname)s %(filename)s:' | 1210 format='%(asctime).19s %(levelname)s %(filename)s:' |
| 1219 '%(lineno)s %(message)s') | 1211 '%(lineno)s %(message)s') |
| 1220 unittest.main() | 1212 unittest.main() |
| 1221 | 1213 |
| 1222 # vim: ts=2:sw=2:tw=80:et: | 1214 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |