Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1323)

Side by Side Diff: tests/gclient_scm_test.py

Issue 1867843003: Revert of Revert "Add (another) argument to break git locks in gclient." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gclient_scm.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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")
532 self.assertFalse(os.path.exists(file_path))
533 sys.stdout.close()
534
504 def testUpdateConflict(self): 535 def testUpdateConflict(self):
505 if not self.enabled: 536 if not self.enabled:
506 return 537 return
507 options = self.Options() 538 options = self.Options()
508 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 539 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
509 relpath=self.relpath) 540 relpath=self.relpath)
510 file_path = join(self.base_path, 'b') 541 file_path = join(self.base_path, 'b')
511 open(file_path, 'w').writelines('conflict\n') 542 open(file_path, 'w').writelines('conflict\n')
512 scm._Run(['commit', '-am', 'test'], options) 543 scm._Run(['commit', '-am', 'test'], options)
513 scm._AskForData = self._GetAskForDataCallback( 544 scm._AskForData = self._GetAskForDataCallback(
(...skipping 21 matching lines...) Expand all
535 566
536 class ManagedGitWrapperTestCaseMox(BaseTestCase): 567 class ManagedGitWrapperTestCaseMox(BaseTestCase):
537 class OptionsObject(object): 568 class OptionsObject(object):
538 def __init__(self, verbose=False, revision=None, force=False): 569 def __init__(self, verbose=False, revision=None, force=False):
539 self.verbose = verbose 570 self.verbose = verbose
540 self.revision = revision 571 self.revision = revision
541 self.deps_os = None 572 self.deps_os = None
542 self.force = force 573 self.force = force
543 self.reset = False 574 self.reset = False
544 self.nohooks = False 575 self.nohooks = False
576 self.break_repo_locks = False
545 # TODO(maruel): Test --jobs > 1. 577 # TODO(maruel): Test --jobs > 1.
546 self.jobs = 1 578 self.jobs = 1
547 579
548 def Options(self, *args, **kwargs): 580 def Options(self, *args, **kwargs):
549 return self.OptionsObject(*args, **kwargs) 581 return self.OptionsObject(*args, **kwargs)
550 582
551 def checkstdout(self, expected): 583 def checkstdout(self, expected):
552 value = sys.stdout.getvalue() 584 value = sys.stdout.getvalue()
553 sys.stdout.close() 585 sys.stdout.close()
554 # pylint: disable=E1101 586 # pylint: disable=E1101
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 971
940 if __name__ == '__main__': 972 if __name__ == '__main__':
941 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL 973 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL
942 logging.basicConfig( 974 logging.basicConfig(
943 level=level, 975 level=level,
944 format='%(asctime).19s %(levelname)s %(filename)s:' 976 format='%(asctime).19s %(levelname)s %(filename)s:'
945 '%(lineno)s %(message)s') 977 '%(lineno)s %(message)s')
946 unittest.main() 978 unittest.main()
947 979
948 # vim: ts=2:sw=2:tw=80:et: 980 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient_scm.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698