Chromium Code Reviews| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 self.manually_grab_svn_rev = True | 126 self.manually_grab_svn_rev = True |
| 127 self.deps_os = None | 127 self.deps_os = None |
| 128 self.force = False | 128 self.force = False |
| 129 self.reset = False | 129 self.reset = False |
| 130 self.nohooks = False | 130 self.nohooks = False |
| 131 self.no_history = False | 131 self.no_history = False |
| 132 self.upstream = False | 132 self.upstream = False |
| 133 self.cache_dir = None | 133 self.cache_dir = None |
| 134 self.merge = False | 134 self.merge = False |
| 135 self.jobs = 1 | 135 self.jobs = 1 |
| 136 self.break_repo_locks = False | |
| 136 self.delete_unversioned_trees = False | 137 self.delete_unversioned_trees = False |
| 137 | 138 |
| 138 sample_git_import = """blob | 139 sample_git_import = """blob |
| 139 mark :1 | 140 mark :1 |
| 140 data 6 | 141 data 6 |
| 141 Hello | 142 Hello |
| 142 | 143 |
| 143 blob | 144 blob |
| 144 mark :2 | 145 mark :2 |
| 145 data 4 | 146 data 4 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 self.fail() | 495 self.fail() |
| 495 except (gclient_scm.gclient_utils.Error, subprocess2.CalledProcessError): | 496 except (gclient_scm.gclient_utils.Error, subprocess2.CalledProcessError): |
| 496 # The exact exception text varies across git versions so it's not worth | 497 # The exact exception text varies across git versions so it's not worth |
| 497 # verifying it. It's fine as long as it throws. | 498 # verifying it. It's fine as long as it throws. |
| 498 pass | 499 pass |
| 499 # Manually flush stdout since we can't verify it's content accurately across | 500 # Manually flush stdout since we can't verify it's content accurately across |
| 500 # git versions. | 501 # git versions. |
| 501 sys.stdout.getvalue() | 502 sys.stdout.getvalue() |
| 502 sys.stdout.close() | 503 sys.stdout.close() |
| 503 | 504 |
| 505 def testUpdateLocked(self): | |
| 506 if not self.enabled: | |
| 507 return | |
| 508 options = self.Options() | |
| 509 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | |
| 510 relpath=self.relpath) | |
| 511 file_path = join(self.base_path, '.git', 'index.lock') | |
| 512 with open(file_path, 'w'): | |
| 513 pass | |
| 514 with self.assertRaisesRegexp(subprocess2.CalledProcessError, | |
| 515 'Unable to create.*/index.lock'): | |
| 516 scm.update(options, (), []) | |
| 517 sys.stdout.close() | |
| 518 | |
| 519 def testUpdateLockedBreak(self): | |
| 520 if not self.enabled: | |
| 521 return | |
| 522 options = self.Options() | |
| 523 options.break_repo_locks = True | |
| 524 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | |
| 525 relpath=self.relpath) | |
| 526 file_path = join(self.base_path, '.git', 'index.lock') | |
| 527 with open(file_path, 'w'): | |
| 528 pass | |
| 529 scm.update(options, (), []) | |
| 530 self.assertRegexpMatches(sys.stdout.getvalue(), | |
| 531 "breaking lock.*\.git/index\.lock") | |
|
pgervais
2016/04/06 15:53:30
I would also check that the file has actually been
iannucci
2016/04/06 17:29:18
Done.
| |
| 532 sys.stdout.close() | |
| 533 | |
| 504 def testUpdateConflict(self): | 534 def testUpdateConflict(self): |
| 505 if not self.enabled: | 535 if not self.enabled: |
| 506 return | 536 return |
| 507 options = self.Options() | 537 options = self.Options() |
| 508 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 538 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 509 relpath=self.relpath) | 539 relpath=self.relpath) |
| 510 file_path = join(self.base_path, 'b') | 540 file_path = join(self.base_path, 'b') |
| 511 open(file_path, 'w').writelines('conflict\n') | 541 open(file_path, 'w').writelines('conflict\n') |
| 512 scm._Run(['commit', '-am', 'test'], options) | 542 scm._Run(['commit', '-am', 'test'], options) |
| 513 scm._AskForData = self._GetAskForDataCallback( | 543 scm._AskForData = self._GetAskForDataCallback( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 535 | 565 |
| 536 class ManagedGitWrapperTestCaseMox(BaseTestCase): | 566 class ManagedGitWrapperTestCaseMox(BaseTestCase): |
| 537 class OptionsObject(object): | 567 class OptionsObject(object): |
| 538 def __init__(self, verbose=False, revision=None, force=False): | 568 def __init__(self, verbose=False, revision=None, force=False): |
| 539 self.verbose = verbose | 569 self.verbose = verbose |
| 540 self.revision = revision | 570 self.revision = revision |
| 541 self.deps_os = None | 571 self.deps_os = None |
| 542 self.force = force | 572 self.force = force |
| 543 self.reset = False | 573 self.reset = False |
| 544 self.nohooks = False | 574 self.nohooks = False |
| 575 self.break_repo_locks = False | |
| 545 # TODO(maruel): Test --jobs > 1. | 576 # TODO(maruel): Test --jobs > 1. |
| 546 self.jobs = 1 | 577 self.jobs = 1 |
| 547 | 578 |
| 548 def Options(self, *args, **kwargs): | 579 def Options(self, *args, **kwargs): |
| 549 return self.OptionsObject(*args, **kwargs) | 580 return self.OptionsObject(*args, **kwargs) |
| 550 | 581 |
| 551 def checkstdout(self, expected): | 582 def checkstdout(self, expected): |
| 552 value = sys.stdout.getvalue() | 583 value = sys.stdout.getvalue() |
| 553 sys.stdout.close() | 584 sys.stdout.close() |
| 554 # pylint: disable=E1101 | 585 # pylint: disable=E1101 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 | 970 |
| 940 if __name__ == '__main__': | 971 if __name__ == '__main__': |
| 941 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL | 972 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL |
| 942 logging.basicConfig( | 973 logging.basicConfig( |
| 943 level=level, | 974 level=level, |
| 944 format='%(asctime).19s %(levelname)s %(filename)s:' | 975 format='%(asctime).19s %(levelname)s %(filename)s:' |
| 945 '%(lineno)s %(message)s') | 976 '%(lineno)s %(message)s') |
| 946 unittest.main() | 977 unittest.main() |
| 947 | 978 |
| 948 # vim: ts=2:sw=2:tw=80:et: | 979 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |