| 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 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 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 ((['git', 'commit-tree', '0123456789abcdef', '-p', | 877 ((['git', 'commit-tree', '0123456789abcdef', '-p', |
| 878 'origin/master', '-m', description],), | 878 'origin/master', '-m', description],), |
| 879 ref_to_push), | 879 ref_to_push), |
| 880 ] | 880 ] |
| 881 else: | 881 else: |
| 882 ref_to_push = 'HEAD' | 882 ref_to_push = 'HEAD' |
| 883 | 883 |
| 884 calls += [ | 884 calls += [ |
| 885 ((['git', 'rev-list', | 885 ((['git', 'rev-list', |
| 886 expected_upstream_ref + '..' + ref_to_push],), ''), | 886 expected_upstream_ref + '..' + ref_to_push],), ''), |
| 887 ((['git', 'config', 'rietveld.cc'],), '') |
| 887 ] | 888 ] |
| 888 | 889 |
| 889 notify_suffix = 'notify=%s' % ('ALL' if notify else 'NONE') | 890 notify_suffix = 'notify=%s' % ('ALL' if notify else 'NONE') |
| 890 if ref_suffix: | 891 if ref_suffix: |
| 891 ref_suffix += ',' + notify_suffix | 892 ref_suffix += ',' + notify_suffix |
| 892 else: | 893 else: |
| 893 ref_suffix = '%' + notify_suffix | 894 ref_suffix = '%' + notify_suffix |
| 894 | 895 |
| 896 # Add cc from watch list. |
| 897 ref_suffix += ',cc=joe@example.com' |
| 898 |
| 895 if reviewers: | 899 if reviewers: |
| 896 ref_suffix += ',' + ','.join('r=%s' % email | 900 ref_suffix += ',' + ','.join('r=%s' % email |
| 897 for email in sorted(reviewers)) | 901 for email in sorted(reviewers)) |
| 898 calls += [ | 902 calls += [ |
| 899 ((['git', 'push', 'origin', | 903 ((['git', 'push', 'origin', |
| 900 ref_to_push + ':refs/for/refs/heads/master' + ref_suffix],), | 904 ref_to_push + ':refs/for/refs/heads/master' + ref_suffix],), |
| 901 ('remote:\n' | 905 ('remote:\n' |
| 902 'remote: Processing changes: (\)\n' | 906 'remote: Processing changes: (\)\n' |
| 903 'remote: Processing changes: (|)\n' | 907 'remote: Processing changes: (|)\n' |
| 904 'remote: Processing changes: (/)\n' | 908 'remote: Processing changes: (/)\n' |
| 905 'remote: Processing changes: (-)\n' | 909 'remote: Processing changes: (-)\n' |
| 906 'remote: Processing changes: new: 1 (/)\n' | 910 'remote: Processing changes: new: 1 (/)\n' |
| 907 'remote: Processing changes: new: 1, done\n' | 911 'remote: Processing changes: new: 1, done\n' |
| 908 'remote:\n' | 912 'remote:\n' |
| 909 'remote: New Changes:\n' | 913 'remote: New Changes:\n' |
| 910 'remote: https://chromium-review.googlesource.com/123456 XXX.\n' | 914 'remote: https://chromium-review.googlesource.com/123456 XXX.\n' |
| 911 'remote:\n' | 915 'remote:\n' |
| 912 'To https://chromium.googlesource.com/yyy/zzz\n' | 916 'To https://chromium.googlesource.com/yyy/zzz\n' |
| 913 ' * [new branch] hhhh -> refs/for/refs/heads/master\n')), | 917 ' * [new branch] hhhh -> refs/for/refs/heads/master\n')), |
| 914 ] | 918 ] |
| 915 if squash: | 919 if squash: |
| 916 calls += [ | 920 calls += [ |
| 917 ((['git', 'config', 'branch.master.gerritissue', '123456'],), | 921 ((['git', 'config', 'branch.master.gerritissue', '123456'],), |
| 918 ''), | 922 ''), |
| 919 ((['git', 'config', 'branch.master.gerritserver', | 923 ((['git', 'config', 'branch.master.gerritserver', |
| 920 'https://chromium-review.googlesource.com'],), ''), | 924 'https://chromium-review.googlesource.com'],), ''), |
| 921 ((['git', 'config', 'branch.master.gerritsquashhash', | 925 ((['git', 'config', 'branch.master.gerritsquashhash', |
| 922 'abcdef0123456789'],), ''), | 926 'abcdef0123456789'],), ''), |
| 923 ] | 927 ] |
| 924 calls += [ | |
| 925 ((['git', 'config', 'rietveld.cc'],), ''), | |
| 926 ((['AddReviewers', 'chromium-review.googlesource.com', | |
| 927 123456 if squash else None, | |
| 928 ['joe@example.com'], False],), ''), | |
| 929 ] | |
| 930 calls += cls._git_post_upload_calls() | 928 calls += cls._git_post_upload_calls() |
| 931 return calls | 929 return calls |
| 932 | 930 |
| 933 def _run_gerrit_upload_test( | 931 def _run_gerrit_upload_test( |
| 934 self, | 932 self, |
| 935 upload_args, | 933 upload_args, |
| 936 description, | 934 description, |
| 937 reviewers=None, | 935 reviewers=None, |
| 938 squash=True, | 936 squash=True, |
| 939 squash_mode=None, | 937 squash_mode=None, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 953 | 951 |
| 954 reviewers = reviewers or [] | 952 reviewers = reviewers or [] |
| 955 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | 953 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 956 self.mock(git_cl.gerrit_util, 'CookiesAuthenticator', | 954 self.mock(git_cl.gerrit_util, 'CookiesAuthenticator', |
| 957 CookiesAuthenticatorMockFactory(same_cookie='same_cred')) | 955 CookiesAuthenticatorMockFactory(same_cookie='same_cred')) |
| 958 self.mock(git_cl._GerritChangelistImpl, '_GerritCommitMsgHookCheck', | 956 self.mock(git_cl._GerritChangelistImpl, '_GerritCommitMsgHookCheck', |
| 959 lambda _, offer_removal: None) | 957 lambda _, offer_removal: None) |
| 960 self.mock(git_cl.gclient_utils, 'RunEditor', | 958 self.mock(git_cl.gclient_utils, 'RunEditor', |
| 961 lambda *_, **__: self._mocked_call(['RunEditor'])) | 959 lambda *_, **__: self._mocked_call(['RunEditor'])) |
| 962 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call) | 960 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call) |
| 963 self.mock(git_cl.gerrit_util, 'AddReviewers', | |
| 964 lambda h, i, add, is_reviewer: self._mocked_call( | |
| 965 ['AddReviewers', h, i, add, is_reviewer])) | |
| 966 | 961 |
| 967 self.calls = self._gerrit_base_calls(issue=issue) | 962 self.calls = self._gerrit_base_calls(issue=issue) |
| 968 self.calls += self._gerrit_upload_calls( | 963 self.calls += self._gerrit_upload_calls( |
| 969 description, reviewers, squash, | 964 description, reviewers, squash, |
| 970 squash_mode=squash_mode, | 965 squash_mode=squash_mode, |
| 971 expected_upstream_ref=expected_upstream_ref, | 966 expected_upstream_ref=expected_upstream_ref, |
| 972 ref_suffix=ref_suffix, notify=notify, | 967 ref_suffix=ref_suffix, notify=notify, |
| 973 post_amend_description=post_amend_description, | 968 post_amend_description=post_amend_description, |
| 974 issue=issue) | 969 issue=issue) |
| 975 # Uncomment when debugging. | 970 # Uncomment when debugging. |
| (...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1965 out = StringIO.StringIO() | 1960 out = StringIO.StringIO() |
| 1966 self.mock(sys, 'stdout', out) | 1961 self.mock(sys, 'stdout', out) |
| 1967 self.assertEqual(0, cl.CMDLand(force=True, bypass_hooks=True, verbose=True)) | 1962 self.assertEqual(0, cl.CMDLand(force=True, bypass_hooks=True, verbose=True)) |
| 1968 self.assertRegexpMatches(out.getvalue(), 'Issue.*123 has been submitted') | 1963 self.assertRegexpMatches(out.getvalue(), 'Issue.*123 has been submitted') |
| 1969 | 1964 |
| 1970 | 1965 |
| 1971 if __name__ == '__main__': | 1966 if __name__ == '__main__': |
| 1972 git_cl.logging.basicConfig( | 1967 git_cl.logging.basicConfig( |
| 1973 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1968 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 1974 unittest.main() | 1969 unittest.main() |
| OLD | NEW |