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

Side by Side Diff: tests/git_cl_test.py

Issue 1760063002: git cl: stop downloading Gerrit commit-hook with --squash mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@G0850
Patch Set: fix tests, for real this time. Created 4 years, 9 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
« no previous file with comments | « 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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 'foo'), 575 'foo'),
576 ((['git', 'config', 'user.email'],), 'me@example.com'), 576 ((['git', 'config', 'user.email'],), 'me@example.com'),
577 ((['git', 577 ((['git',
578 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', 578 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
579 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), 579 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],),
580 '+dat'), 580 '+dat'),
581 ] 581 ]
582 582
583 @classmethod 583 @classmethod
584 def _gerrit_upload_calls(cls, description, reviewers, squash, 584 def _gerrit_upload_calls(cls, description, reviewers, squash,
585 expected_upstream_ref='origin/refs/heads/master'): 585 expected_upstream_ref='origin/refs/heads/master',
586 post_amend_description=None):
587 if post_amend_description is None:
588 post_amend_description = description
586 calls = [ 589 calls = [
587 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), 590 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'),
588 ((['git', 'log', '--pretty=format:%s\n\n%b', 591 ((['git', 'log', '--pretty=format:%s\n\n%b',
589 'fake_ancestor_sha..HEAD'],), 592 'fake_ancestor_sha..HEAD'],),
590 description) 593 description)
591 ] 594 ]
592 if not git_footers.get_footer_change_id(description) and not squash: 595 if not git_footers.get_footer_change_id(description) and not squash:
596 # TODOOOOO
593 calls += [ 597 calls += [
598 # DownloadGerritHook(False)
599 ((False, ),
600 ''),
601 # Amending of commit message to get the Change-Id.
594 ((['git', 'log', '--pretty=format:%s\n\n%b', 602 ((['git', 'log', '--pretty=format:%s\n\n%b',
595 'fake_ancestor_sha..HEAD'],), 603 'fake_ancestor_sha..HEAD'],),
596 description), 604 description),
597 ((['git', 'commit', '--amend', '-m', description],), 605 ((['git', 'commit', '--amend', '-m', description],),
598 ''), 606 ''),
599 ((['git', 'log', '--pretty=format:%s\n\n%b', 607 ((['git', 'log', '--pretty=format:%s\n\n%b',
600 'fake_ancestor_sha..HEAD'],), 608 'fake_ancestor_sha..HEAD'],),
601 description) 609 post_amend_description)
602 ] 610 ]
603 if squash: 611 if squash:
604 ref_to_push = 'abcdef0123456789' 612 ref_to_push = 'abcdef0123456789'
605 calls += [ 613 calls += [
606 ((['git', 'show', '--format=%B', '-s', 614 ((['git', 'show', '--format=%B', '-s',
607 'refs/heads/git_cl_uploads/master'],), 615 'refs/heads/git_cl_uploads/master'],),
608 (description, 0)), 616 (description, 0)),
609 ((['git', 'config', 'branch.master.merge'],), 617 ((['git', 'config', 'branch.master.merge'],),
610 'refs/heads/master'), 618 'refs/heads/master'),
611 ((['git', 'config', 'branch.master.remote'],), 619 ((['git', 'config', 'branch.master.remote'],),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 ] 656 ]
649 calls += cls._git_post_upload_calls() 657 calls += cls._git_post_upload_calls()
650 return calls 658 return calls
651 659
652 def _run_gerrit_upload_test( 660 def _run_gerrit_upload_test(
653 self, 661 self,
654 upload_args, 662 upload_args,
655 description, 663 description,
656 reviewers, 664 reviewers,
657 squash=False, 665 squash=False,
658 expected_upstream_ref='origin/refs/heads/master'): 666 expected_upstream_ref='origin/refs/heads/master',
667 post_amend_description=None):
659 """Generic gerrit upload test framework.""" 668 """Generic gerrit upload test framework."""
660 self.calls = self._gerrit_base_calls() 669 self.calls = self._gerrit_base_calls()
661 self.calls += self._gerrit_upload_calls( 670 self.calls += self._gerrit_upload_calls(
662 description, reviewers, squash, 671 description, reviewers, squash,
663 expected_upstream_ref=expected_upstream_ref) 672 expected_upstream_ref=expected_upstream_ref,
673 post_amend_description=post_amend_description)
664 # Uncomment when debugging. 674 # Uncomment when debugging.
665 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) 675 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls)))
666 git_cl.main(['upload'] + upload_args) 676 git_cl.main(['upload'] + upload_args)
667 677
668 def test_gerrit_upload_without_change_id(self): 678 def test_gerrit_upload_without_change_id(self):
679 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call)
669 self._run_gerrit_upload_test( 680 self._run_gerrit_upload_test(
670 [], 681 [],
671 'desc\n\nBUG=\n', 682 'desc\n\nBUG=\n',
672 []) 683 [],
684 post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx')
673 685
674 def test_gerrit_no_reviewer(self): 686 def test_gerrit_no_reviewer(self):
675 self._run_gerrit_upload_test( 687 self._run_gerrit_upload_test(
676 [], 688 [],
677 'desc\n\nBUG=\n\nChange-Id: I123456789\n', 689 'desc\n\nBUG=\n\nChange-Id: I123456789\n',
678 []) 690 [])
679 691
680 def test_gerrit_reviewers_cmd_line(self): 692 def test_gerrit_reviewers_cmd_line(self):
681 self._run_gerrit_upload_test( 693 self._run_gerrit_upload_test(
682 ['-r', 'foo@example.com'], 694 ['-r', 'foo@example.com'],
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 'rietveld.force-https-commit-url'],), ''), 823 'rietveld.force-https-commit-url'],), ''),
812 ((['git', 'config', '--unset-all', 824 ((['git', 'config', '--unset-all',
813 'rietveld.cpplint-ignore-regex'],), ''), 825 'rietveld.cpplint-ignore-regex'],), ''),
814 ((['git', 'config', '--unset-all', 826 ((['git', 'config', '--unset-all',
815 'rietveld.project'],), ''), 827 'rietveld.project'],), ''),
816 ((['git', 'config', '--unset-all', 828 ((['git', 'config', '--unset-all',
817 'rietveld.pending-ref-prefix'],), ''), 829 'rietveld.pending-ref-prefix'],), ''),
818 ((['git', 'config', '--unset-all', 830 ((['git', 'config', '--unset-all',
819 'rietveld.run-post-upload-hook'],), ''), 831 'rietveld.run-post-upload-hook'],), ''),
820 ((['git', 'config', 'gerrit.host', 'True'],), ''), 832 ((['git', 'config', 'gerrit.host', 'True'],), ''),
821 # DownloadHooks(False)
822 ((['git', 'config', 'gerrit.host'],), 'True'),
823 ((['git', 'rev-parse', '--show-cdup'],), ''),
824 ((commit_msg_path, os.X_OK,), False),
825 (('https://gerrit-review.googlesource.com/tools/hooks/commit-msg',
826 commit_msg_path,), ''),
827 ((commit_msg_path,), True),
828 ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''),
829 # GetCodereviewSettingsInteractively 833 # GetCodereviewSettingsInteractively
830 ((['git', 'config', 'rietveld.server'],), 834 ((['git', 'config', 'rietveld.server'],),
831 'gerrit.chromium.org'), 835 'gerrit.chromium.org'),
832 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), 836 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',),
833 ''), 837 ''),
834 ((['git', 'config', 'rietveld.cc'],), ''), 838 ((['git', 'config', 'rietveld.cc'],), ''),
835 (('CC list:',), ''), 839 (('CC list:',), ''),
836 ((['git', 'config', 'rietveld.private'],), ''), 840 ((['git', 'config', 'rietveld.private'],), ''),
837 (('Private flag (rietveld only):',), ''), 841 (('Private flag (rietveld only):',), ''),
838 ((['git', 'config', 'rietveld.tree-status-url'],), ''), 842 ((['git', 'config', 'rietveld.tree-status-url'],), ''),
839 (('Tree status URL:',), ''), 843 (('Tree status URL:',), ''),
840 ((['git', 'config', 'rietveld.viewvc-url'],), ''), 844 ((['git', 'config', 'rietveld.viewvc-url'],), ''),
841 (('ViewVC URL:',), ''), 845 (('ViewVC URL:',), ''),
842 # DownloadHooks(True)
843 ((['git', 'config', 'rietveld.bug-prefix'],), ''), 846 ((['git', 'config', 'rietveld.bug-prefix'],), ''),
844 (('Bug Prefix:',), ''), 847 (('Bug Prefix:',), ''),
845 ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), 848 ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''),
846 (('Run Post Upload Hook:',), ''), 849 (('Run Post Upload Hook:',), ''),
847 ((commit_msg_path, os.X_OK,), True), 850 # DownloadGerritHook(False)
851 ((['git', 'config', 'gerrit.host'],), 'True'),
852 ((['git', 'rev-parse', '--show-cdup'],), ''),
853 ((commit_msg_path, os.X_OK,), False),
854 (('https://gerrit-review.googlesource.com/tools/hooks/commit-msg',
855 commit_msg_path,), ''),
856 ((commit_msg_path,), True),
857 ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''),
848 ] 858 ]
849 git_cl.main(['config']) 859 git_cl.main(['config'])
850 860
851 def test_update_reviewers(self): 861 def test_update_reviewers(self):
852 data = [ 862 data = [
853 ('foo', [], 'foo'), 863 ('foo', [], 'foo'),
854 ('foo\nR=xx', [], 'foo\nR=xx'), 864 ('foo\nR=xx', [], 'foo\nR=xx'),
855 ('foo\nTBR=xx', [], 'foo\nTBR=xx'), 865 ('foo\nTBR=xx', [], 'foo\nTBR=xx'),
856 ('foo', ['a@c'], 'foo\n\nR=a@c'), 866 ('foo', ['a@c'], 'foo\n\nR=a@c'),
857 ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'), 867 ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 self.calls += [ 983 self.calls += [
974 ((['git', 'apply', '--index', '-p0', '--3way'],), '', 984 ((['git', 'apply', '--index', '-p0', '--3way'],), '',
975 subprocess2.CalledProcessError(1, '', '', '', '')), 985 subprocess2.CalledProcessError(1, '', '', '', '')),
976 ] 986 ]
977 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) 987 self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
978 988
979 if __name__ == '__main__': 989 if __name__ == '__main__':
980 git_cl.logging.basicConfig( 990 git_cl.logging.basicConfig(
981 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 991 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
982 unittest.main() 992 unittest.main()
OLDNEW
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698