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 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 ((['git', 'config', 'user.email'],), 'me@example.com'), | 731 ((['git', 'config', 'user.email'],), 'me@example.com'), |
732 ((['git', | 732 ((['git', |
733 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 733 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
734 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), | 734 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
735 '+dat'), | 735 '+dat'), |
736 ] | 736 ] |
737 | 737 |
738 @classmethod | 738 @classmethod |
739 def _gerrit_upload_calls(cls, description, reviewers, squash, | 739 def _gerrit_upload_calls(cls, description, reviewers, squash, |
740 expected_upstream_ref='origin/refs/heads/master', | 740 expected_upstream_ref='origin/refs/heads/master', |
| 741 ref_suffix='', |
741 post_amend_description=None, issue=None): | 742 post_amend_description=None, issue=None): |
742 if post_amend_description is None: | 743 if post_amend_description is None: |
743 post_amend_description = description | 744 post_amend_description = description |
744 | 745 |
745 calls = [ | 746 calls = [ |
746 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), | 747 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), |
747 ] | 748 ] |
748 # If issue is given, then description is fetched from Gerrit instead. | 749 # If issue is given, then description is fetched from Gerrit instead. |
749 if issue is None: | 750 if issue is None: |
750 if squash: | 751 if squash: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 receive_pack = '--receive-pack=git receive-pack ' | 804 receive_pack = '--receive-pack=git receive-pack ' |
804 receive_pack += '--cc=joe@example.com' # from watch list | 805 receive_pack += '--cc=joe@example.com' # from watch list |
805 if reviewers: | 806 if reviewers: |
806 receive_pack += ' ' | 807 receive_pack += ' ' |
807 receive_pack += ' '.join( | 808 receive_pack += ' '.join( |
808 '--reviewer=' + email for email in sorted(reviewers)) | 809 '--reviewer=' + email for email in sorted(reviewers)) |
809 receive_pack += '' | 810 receive_pack += '' |
810 calls += [ | 811 calls += [ |
811 ((['git', | 812 ((['git', |
812 'push', receive_pack, 'origin', | 813 'push', receive_pack, 'origin', |
813 ref_to_push + ':refs/for/refs/heads/master'],), | 814 ref_to_push + ':refs/for/refs/heads/master' + ref_suffix],), |
814 ('remote:\n' | 815 ('remote:\n' |
815 'remote: Processing changes: (\)\n' | 816 'remote: Processing changes: (\)\n' |
816 'remote: Processing changes: (|)\n' | 817 'remote: Processing changes: (|)\n' |
817 'remote: Processing changes: (/)\n' | 818 'remote: Processing changes: (/)\n' |
818 'remote: Processing changes: (-)\n' | 819 'remote: Processing changes: (-)\n' |
819 'remote: Processing changes: new: 1 (/)\n' | 820 'remote: Processing changes: new: 1 (/)\n' |
820 'remote: Processing changes: new: 1, done\n' | 821 'remote: Processing changes: new: 1, done\n' |
821 'remote:\n' | 822 'remote:\n' |
822 'remote: New Changes:\n' | 823 'remote: New Changes:\n' |
823 'remote: https://chromium-review.googlesource.com/123456 XXX.\n' | 824 'remote: https://chromium-review.googlesource.com/123456 XXX.\n' |
824 'remote:\n' | 825 'remote:\n' |
825 'To https://chromium.googlesource.com/yyy/zzz\n' | 826 'To https://chromium.googlesource.com/yyy/zzz\n' |
826 ' * [new branch] hhhh -> refs/for/refs/heads/master\n')), | 827 ' * [new branch] hhhh -> refs/for/refs/heads/master\n')), |
827 ] | 828 ] |
828 if squash: | 829 if squash: |
829 calls += [ | 830 calls += [ |
830 ((['git', 'config', 'branch.master.gerritissue', '123456'],), ''), | 831 ((['git', 'config', 'branch.master.gerritissue', '123456'],), ''), |
831 ((['git', 'config', 'branch.master.gerritserver', | 832 ((['git', 'config', 'branch.master.gerritserver', |
832 'https://chromium-review.googlesource.com'],), ''), | 833 'https://chromium-review.googlesource.com'],), ''), |
833 ((['git', 'config', 'branch.master.gerritsquashhash', | 834 ((['git', 'config', 'branch.master.gerritsquashhash', |
834 'abcdef0123456789'],), ''), | 835 'abcdef0123456789'],), ''), |
835 ] | 836 ] |
836 calls += cls._git_post_upload_calls() | 837 calls += cls._git_post_upload_calls() |
837 return calls | 838 return calls |
838 | 839 |
839 def _run_gerrit_upload_test( | 840 def _run_gerrit_upload_test( |
840 self, | 841 self, |
841 upload_args, | 842 upload_args, |
842 description, | 843 description, |
843 reviewers, | 844 reviewers=None, |
844 squash=False, | 845 squash=False, |
845 expected_upstream_ref='origin/refs/heads/master', | 846 expected_upstream_ref='origin/refs/heads/master', |
| 847 ref_suffix='', |
846 post_amend_description=None, | 848 post_amend_description=None, |
847 issue=None): | 849 issue=None): |
848 """Generic gerrit upload test framework.""" | 850 """Generic gerrit upload test framework.""" |
| 851 reviewers = reviewers or [] |
849 self.mock(git_cl.gerrit_util, "CookiesAuthenticator", | 852 self.mock(git_cl.gerrit_util, "CookiesAuthenticator", |
850 CookiesAuthenticatorMockFactory(same_cookie='same_cred')) | 853 CookiesAuthenticatorMockFactory(same_cookie='same_cred')) |
851 self.calls = self._gerrit_base_calls(issue=issue) | 854 self.calls = self._gerrit_base_calls(issue=issue) |
852 self.calls += self._gerrit_upload_calls( | 855 self.calls += self._gerrit_upload_calls( |
853 description, reviewers, squash, | 856 description, reviewers, squash, |
854 expected_upstream_ref=expected_upstream_ref, | 857 expected_upstream_ref=expected_upstream_ref, |
| 858 ref_suffix=ref_suffix, |
855 post_amend_description=post_amend_description, | 859 post_amend_description=post_amend_description, |
856 issue=issue) | 860 issue=issue) |
857 # Uncomment when debugging. | 861 # Uncomment when debugging. |
858 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) | 862 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) |
859 git_cl.main(['upload'] + upload_args) | 863 git_cl.main(['upload'] + upload_args) |
860 | 864 |
861 def test_gerrit_upload_without_change_id(self): | 865 def test_gerrit_upload_without_change_id(self): |
862 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call) | 866 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call) |
863 self._run_gerrit_upload_test( | 867 self._run_gerrit_upload_test( |
864 [], | 868 [], |
865 'desc\n\nBUG=\n', | 869 'desc\n\nBUG=\n', |
866 [], | 870 [], |
867 post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx') | 871 post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx') |
868 | 872 |
869 def test_gerrit_no_reviewer(self): | 873 def test_gerrit_no_reviewer(self): |
870 self._run_gerrit_upload_test( | 874 self._run_gerrit_upload_test( |
871 [], | 875 [], |
872 'desc\n\nBUG=\n\nChange-Id: I123456789\n', | 876 'desc\n\nBUG=\n\nChange-Id: I123456789\n', |
873 []) | 877 []) |
874 | 878 |
| 879 def test_gerrit_patch_title(self): |
| 880 self._run_gerrit_upload_test( |
| 881 ['-t', 'Don\'t put under_scores as they become spaces'], |
| 882 'desc\n\nBUG=\n\nChange-Id: I123456789', |
| 883 ref_suffix='%m=Don\'t_put_under_scores_as_they_become_spaces') |
| 884 |
875 def test_gerrit_reviewers_cmd_line(self): | 885 def test_gerrit_reviewers_cmd_line(self): |
876 self._run_gerrit_upload_test( | 886 self._run_gerrit_upload_test( |
877 ['-r', 'foo@example.com'], | 887 ['-r', 'foo@example.com'], |
878 'desc\n\nBUG=\n\nChange-Id: I123456789', | 888 'desc\n\nBUG=\n\nChange-Id: I123456789', |
879 ['foo@example.com']) | 889 ['foo@example.com']) |
880 | 890 |
881 def test_gerrit_reviewer_multiple(self): | 891 def test_gerrit_reviewer_multiple(self): |
882 self._run_gerrit_upload_test( | 892 self._run_gerrit_upload_test( |
883 [], | 893 [], |
884 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n\n' | 894 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n\n' |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 'chromium.googlesource.com': 'same', | 1298 'chromium.googlesource.com': 'same', |
1289 'chromium-review.googlesource.com': 'same', | 1299 'chromium-review.googlesource.com': 'same', |
1290 }) | 1300 }) |
1291 self.assertIsNone(cl.EnsureAuthenticated(force=False)) | 1301 self.assertIsNone(cl.EnsureAuthenticated(force=False)) |
1292 | 1302 |
1293 | 1303 |
1294 if __name__ == '__main__': | 1304 if __name__ == '__main__': |
1295 git_cl.logging.basicConfig( | 1305 git_cl.logging.basicConfig( |
1296 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1306 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
1297 unittest.main() | 1307 unittest.main() |
OLD | NEW |