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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), | 568 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), |
569 'foo'), | 569 'foo'), |
570 ((['git', 'config', 'user.email'],), 'me@example.com'), | 570 ((['git', 'config', 'user.email'],), 'me@example.com'), |
571 ((['git', | 571 ((['git', |
572 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 572 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
573 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), | 573 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
574 '+dat'), | 574 '+dat'), |
575 ] | 575 ] |
576 | 576 |
577 @staticmethod | 577 @staticmethod |
578 def _gerrit_upload_calls(description, reviewers, squash): | 578 def _gerrit_upload_calls(description, reviewers, squash, |
579 expected_upstream_ref='origin/refs/heads/master'): | |
luqui
2015/04/28 23:56:24
Yes yes this is awful. My alternatives:
1. Dig i
Mike Wittman
2015/05/01 01:36:29
I went the same way attempting to get the GetTarge
| |
579 calls = [ | 580 calls = [ |
580 ((['git', 'log', '--pretty=format:%s\n\n%b', | 581 ((['git', 'log', '--pretty=format:%s\n\n%b', |
581 'fake_ancestor_sha..HEAD'],), | 582 'fake_ancestor_sha..HEAD'],), |
582 description) | 583 description) |
583 ] | 584 ] |
584 if git_cl.CHANGE_ID not in description: | 585 if git_cl.CHANGE_ID not in description: |
585 calls += [ | 586 calls += [ |
586 ((['git', 'log', '--pretty=format:%s\n\n%b', | 587 ((['git', 'log', '--pretty=format:%s\n\n%b', |
587 'fake_ancestor_sha..HEAD'],), | 588 'fake_ancestor_sha..HEAD'],), |
588 description), | 589 description), |
(...skipping 18 matching lines...) Expand all Loading... | |
607 ((['git', 'rev-parse', 'HEAD:'],), | 608 ((['git', 'rev-parse', 'HEAD:'],), |
608 '0123456789abcdef'), | 609 '0123456789abcdef'), |
609 ((['git', 'commit-tree', '0123456789abcdef', '-p', | 610 ((['git', 'commit-tree', '0123456789abcdef', '-p', |
610 'origin/master', '-m', 'd'],), | 611 'origin/master', '-m', 'd'],), |
611 ref_to_push), | 612 ref_to_push), |
612 ] | 613 ] |
613 else: | 614 else: |
614 ref_to_push = 'HEAD' | 615 ref_to_push = 'HEAD' |
615 | 616 |
616 calls += [ | 617 calls += [ |
617 ((['git', 'rev-list', 'origin/master..' + ref_to_push],), ''), | 618 ((['git', 'rev-list', expected_upstream_ref + '..' + ref_to_push],), '') , |
618 ((['git', 'config', 'rietveld.cc'],), '') | 619 ((['git', 'config', 'rietveld.cc'],), '') |
619 ] | 620 ] |
620 receive_pack = '--receive-pack=git receive-pack ' | 621 receive_pack = '--receive-pack=git receive-pack ' |
621 receive_pack += '--cc=joe@example.com' # from watch list | 622 receive_pack += '--cc=joe@example.com' # from watch list |
622 if reviewers: | 623 if reviewers: |
623 receive_pack += ' ' | 624 receive_pack += ' ' |
624 receive_pack += ' '.join( | 625 receive_pack += ' '.join( |
625 '--reviewer=' + email for email in sorted(reviewers)) | 626 '--reviewer=' + email for email in sorted(reviewers)) |
626 receive_pack += '' | 627 receive_pack += '' |
627 calls += [ | 628 calls += [ |
628 ((['git', | 629 ((['git', |
629 'push', receive_pack, 'origin', ref_to_push + ':refs/for/master'],), | 630 'push', receive_pack, 'origin', |
631 ref_to_push + ':refs/for/refs/heads/master'],), | |
630 '') | 632 '') |
631 ] | 633 ] |
632 if squash: | 634 if squash: |
633 calls += [ | 635 calls += [ |
634 ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'), | 636 ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'), |
635 ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789', | 637 ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789', |
636 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],), | 638 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],), |
637 '') | 639 '') |
638 ] | 640 ] |
639 | 641 |
640 return calls | 642 return calls |
641 | 643 |
642 def _run_gerrit_upload_test( | 644 def _run_gerrit_upload_test( |
643 self, | 645 self, |
644 upload_args, | 646 upload_args, |
645 description, | 647 description, |
646 reviewers, | 648 reviewers, |
647 squash=False): | 649 squash=False, |
650 expected_upstream_ref='origin/refs/heads/master'): | |
648 """Generic gerrit upload test framework.""" | 651 """Generic gerrit upload test framework.""" |
649 self.calls = self._gerrit_base_calls() | 652 self.calls = self._gerrit_base_calls() |
650 self.calls += self._gerrit_upload_calls(description, reviewers, squash) | 653 self.calls += self._gerrit_upload_calls( |
654 description, reviewers, squash, | |
655 expected_upstream_ref=expected_upstream_ref) | |
651 git_cl.main(['upload'] + upload_args) | 656 git_cl.main(['upload'] + upload_args) |
652 | 657 |
653 def test_gerrit_upload_without_change_id(self): | 658 def test_gerrit_upload_without_change_id(self): |
654 self._run_gerrit_upload_test( | 659 self._run_gerrit_upload_test( |
655 [], | 660 [], |
656 'desc\n\nBUG=\n', | 661 'desc\n\nBUG=\n', |
657 []) | 662 []) |
658 | 663 |
659 def test_gerrit_no_reviewer(self): | 664 def test_gerrit_no_reviewer(self): |
660 self._run_gerrit_upload_test( | 665 self._run_gerrit_upload_test( |
(...skipping 12 matching lines...) Expand all Loading... | |
673 [], | 678 [], |
674 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n' | 679 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n' |
675 'Change-Id:123456789\n', | 680 'Change-Id:123456789\n', |
676 ['reviewer@example.com', 'another@example.com']) | 681 ['reviewer@example.com', 'another@example.com']) |
677 | 682 |
678 def test_gerrit_upload_squash(self): | 683 def test_gerrit_upload_squash(self): |
679 self._run_gerrit_upload_test( | 684 self._run_gerrit_upload_test( |
680 ['--squash'], | 685 ['--squash'], |
681 'desc\n\nBUG=\nChange-Id:123456789\n', | 686 'desc\n\nBUG=\nChange-Id:123456789\n', |
682 [], | 687 [], |
683 squash=True) | 688 squash=True, |
689 expected_upstream_ref='origin/master') | |
684 | 690 |
685 def test_config_gerrit_download_hook(self): | 691 def test_config_gerrit_download_hook(self): |
686 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) | 692 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) |
687 def ParseCodereviewSettingsContent(content): | 693 def ParseCodereviewSettingsContent(content): |
688 keyvals = {} | 694 keyvals = {} |
689 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' | 695 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' |
690 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' | 696 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' |
691 keyvals['GERRIT_PORT'] = '29418' | 697 keyvals['GERRIT_PORT'] = '29418' |
692 return keyvals | 698 return keyvals |
693 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', | 699 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
850 # Check target refs for pending prefix. | 856 # Check target refs for pending prefix. |
851 self.assertEqual('prefix/heads/master', | 857 self.assertEqual('prefix/heads/master', |
852 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', | 858 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', |
853 None, 'prefix/')) | 859 None, 'prefix/')) |
854 | 860 |
855 | 861 |
856 if __name__ == '__main__': | 862 if __name__ == '__main__': |
857 git_cl.logging.basicConfig( | 863 git_cl.logging.basicConfig( |
858 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 864 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
859 unittest.main() | 865 unittest.main() |
OLD | NEW |