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

Side by Side Diff: tests/git_cl_test.py

Issue 1191473002: [depot_tools] New "git cl upload" flag to traverse dependent branches and re-upload them (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Cleanup Created 5 years, 6 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
« git_cl.py ('K') | « git_cl.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 git_cl.py.""" 6 """Unit tests for git_cl.py."""
7 7
8 import os 8 import os
9 import StringIO 9 import StringIO
10 import stat 10 import stat
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 ['reviewer@example.com', 'another@example.com']) 688 ['reviewer@example.com', 'another@example.com'])
689 689
690 def test_gerrit_upload_squash(self): 690 def test_gerrit_upload_squash(self):
691 self._run_gerrit_upload_test( 691 self._run_gerrit_upload_test(
692 ['--squash'], 692 ['--squash'],
693 'desc\n\nBUG=\nChange-Id:123456789\n', 693 'desc\n\nBUG=\nChange-Id:123456789\n',
694 [], 694 [],
695 squash=True, 695 squash=True,
696 expected_upstream_ref='origin/master') 696 expected_upstream_ref='origin/master')
697 697
698 def test_upload_branch_deps(self):
699 def mock_run_git(*args, **_kwargs):
700 if args[0] == ['symbolic-ref', 'HEAD']:
701 return 'test1'
702 elif args[0] == ['for-each-ref',
703 '--format=%(refname:short) %(upstream:short)',
704 'refs/heads']:
705 # Create a local branch dependency tree that looks like this:
706 # test1 -> test2 -> test3 -> test4 -> test5
707 # -> test3.1
708 # test6 -> test0
709 branch_deps = [
710 'test2 test1', # test1 -> test2
711 'test3 test2', # test2 -> test3
712 'test3.1 test2', # test2 -> test3.1
713 'test4 test3', # test3 -> test4
714 'test5 test4', # test4 -> test5
715 'test6 test0', # test0 -> test6
716 ]
717 return '\n'.join(branch_deps)
718 self.mock(git_cl, 'RunGit', mock_run_git)
719
720 class RecordCalls:
721 times_called = 0
722 record_calls = RecordCalls()
723 def mock_CMDupload(*args, **_kwargs):
724 record_calls.times_called += 1
725 return 0
726
727 self.mock(git_cl, 'CMDupload', mock_CMDupload)
728 self.calls = [
729 (('[Press enter to dcommit or ctrl-C to quit]',), ''),
730 ]
731 ret = git_cl.main(['upload_branch_deps'])
732 # CMDupload should have been called 5 times because of 5 dependent branches.
733 self.assertEquals(5, record_calls.times_called)
734 self.assertEquals(0, ret)
735
698 def test_config_gerrit_download_hook(self): 736 def test_config_gerrit_download_hook(self):
699 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) 737 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock)
700 def ParseCodereviewSettingsContent(content): 738 def ParseCodereviewSettingsContent(content):
701 keyvals = {} 739 keyvals = {}
702 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' 740 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org'
703 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' 741 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org'
704 keyvals['GERRIT_PORT'] = '29418' 742 keyvals['GERRIT_PORT'] = '29418'
705 return keyvals 743 return keyvals
706 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', 744 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent',
707 ParseCodereviewSettingsContent) 745 ParseCodereviewSettingsContent)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 self.calls += [ 944 self.calls += [
907 ((['git', 'apply', '--index', '-p0', '--3way'],), '', 945 ((['git', 'apply', '--index', '-p0', '--3way'],), '',
908 subprocess2.CalledProcessError(1, '', '', '', '')), 946 subprocess2.CalledProcessError(1, '', '', '', '')),
909 ] 947 ]
910 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) 948 self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
911 949
912 if __name__ == '__main__': 950 if __name__ == '__main__':
913 git_cl.logging.basicConfig( 951 git_cl.logging.basicConfig(
914 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 952 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
915 unittest.main() 953 unittest.main()
OLDNEW
« git_cl.py ('K') | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698