| 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 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), | 574 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), |
| 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 @staticmethod | 583 @staticmethod |
| 584 def _gerrit_upload_calls(description, reviewers, squash): | 584 def _gerrit_upload_calls(description, reviewers, squash, |
| 585 expected_upstream_ref='origin/refs/heads/master'): |
| 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) |
| 589 ] | 590 ] |
| 590 if git_cl.CHANGE_ID not in description: | 591 if git_cl.CHANGE_ID not in description: |
| 591 calls += [ | 592 calls += [ |
| 592 ((['git', 'log', '--pretty=format:%s\n\n%b', | 593 ((['git', 'log', '--pretty=format:%s\n\n%b', |
| 593 'fake_ancestor_sha..HEAD'],), | 594 'fake_ancestor_sha..HEAD'],), |
| 594 description), | 595 description), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 613 ((['git', 'rev-parse', 'HEAD:'],), | 614 ((['git', 'rev-parse', 'HEAD:'],), |
| 614 '0123456789abcdef'), | 615 '0123456789abcdef'), |
| 615 ((['git', 'commit-tree', '0123456789abcdef', '-p', | 616 ((['git', 'commit-tree', '0123456789abcdef', '-p', |
| 616 'origin/master', '-m', 'd'],), | 617 'origin/master', '-m', 'd'],), |
| 617 ref_to_push), | 618 ref_to_push), |
| 618 ] | 619 ] |
| 619 else: | 620 else: |
| 620 ref_to_push = 'HEAD' | 621 ref_to_push = 'HEAD' |
| 621 | 622 |
| 622 calls += [ | 623 calls += [ |
| 623 ((['git', 'rev-list', 'origin/master..' + ref_to_push],), ''), | 624 ((['git', 'rev-list', |
| 625 expected_upstream_ref + '..' + ref_to_push],), ''), |
| 624 ((['git', 'config', 'rietveld.cc'],), '') | 626 ((['git', 'config', 'rietveld.cc'],), '') |
| 625 ] | 627 ] |
| 626 receive_pack = '--receive-pack=git receive-pack ' | 628 receive_pack = '--receive-pack=git receive-pack ' |
| 627 receive_pack += '--cc=joe@example.com' # from watch list | 629 receive_pack += '--cc=joe@example.com' # from watch list |
| 628 if reviewers: | 630 if reviewers: |
| 629 receive_pack += ' ' | 631 receive_pack += ' ' |
| 630 receive_pack += ' '.join( | 632 receive_pack += ' '.join( |
| 631 '--reviewer=' + email for email in sorted(reviewers)) | 633 '--reviewer=' + email for email in sorted(reviewers)) |
| 632 receive_pack += '' | 634 receive_pack += '' |
| 633 calls += [ | 635 calls += [ |
| 634 ((['git', | 636 ((['git', |
| 635 'push', receive_pack, 'origin', ref_to_push + ':refs/for/master'],), | 637 'push', receive_pack, 'origin', |
| 638 ref_to_push + ':refs/for/refs/heads/master'],), |
| 636 '') | 639 '') |
| 637 ] | 640 ] |
| 638 if squash: | 641 if squash: |
| 639 calls += [ | 642 calls += [ |
| 640 ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'), | 643 ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'), |
| 641 ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789', | 644 ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789', |
| 642 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],), | 645 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],), |
| 643 '') | 646 '') |
| 644 ] | 647 ] |
| 645 | 648 |
| 646 return calls | 649 return calls |
| 647 | 650 |
| 648 def _run_gerrit_upload_test( | 651 def _run_gerrit_upload_test( |
| 649 self, | 652 self, |
| 650 upload_args, | 653 upload_args, |
| 651 description, | 654 description, |
| 652 reviewers, | 655 reviewers, |
| 653 squash=False): | 656 squash=False, |
| 657 expected_upstream_ref='origin/refs/heads/master'): |
| 654 """Generic gerrit upload test framework.""" | 658 """Generic gerrit upload test framework.""" |
| 655 self.calls = self._gerrit_base_calls() | 659 self.calls = self._gerrit_base_calls() |
| 656 self.calls += self._gerrit_upload_calls(description, reviewers, squash) | 660 self.calls += self._gerrit_upload_calls( |
| 661 description, reviewers, squash, |
| 662 expected_upstream_ref=expected_upstream_ref) |
| 657 git_cl.main(['upload'] + upload_args) | 663 git_cl.main(['upload'] + upload_args) |
| 658 | 664 |
| 659 def test_gerrit_upload_without_change_id(self): | 665 def test_gerrit_upload_without_change_id(self): |
| 660 self._run_gerrit_upload_test( | 666 self._run_gerrit_upload_test( |
| 661 [], | 667 [], |
| 662 'desc\n\nBUG=\n', | 668 'desc\n\nBUG=\n', |
| 663 []) | 669 []) |
| 664 | 670 |
| 665 def test_gerrit_no_reviewer(self): | 671 def test_gerrit_no_reviewer(self): |
| 666 self._run_gerrit_upload_test( | 672 self._run_gerrit_upload_test( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 679 [], | 685 [], |
| 680 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n' | 686 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n' |
| 681 'Change-Id:123456789\n', | 687 'Change-Id:123456789\n', |
| 682 ['reviewer@example.com', 'another@example.com']) | 688 ['reviewer@example.com', 'another@example.com']) |
| 683 | 689 |
| 684 def test_gerrit_upload_squash(self): | 690 def test_gerrit_upload_squash(self): |
| 685 self._run_gerrit_upload_test( | 691 self._run_gerrit_upload_test( |
| 686 ['--squash'], | 692 ['--squash'], |
| 687 'desc\n\nBUG=\nChange-Id:123456789\n', | 693 'desc\n\nBUG=\nChange-Id:123456789\n', |
| 688 [], | 694 [], |
| 689 squash=True) | 695 squash=True, |
| 696 expected_upstream_ref='origin/master') |
| 690 | 697 |
| 691 def test_config_gerrit_download_hook(self): | 698 def test_config_gerrit_download_hook(self): |
| 692 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) | 699 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) |
| 693 def ParseCodereviewSettingsContent(content): | 700 def ParseCodereviewSettingsContent(content): |
| 694 keyvals = {} | 701 keyvals = {} |
| 695 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' | 702 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' |
| 696 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' | 703 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' |
| 697 keyvals['GERRIT_PORT'] = '29418' | 704 keyvals['GERRIT_PORT'] = '29418' |
| 698 return keyvals | 705 return keyvals |
| 699 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', | 706 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 self.calls += [ | 904 self.calls += [ |
| 898 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 905 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
| 899 subprocess2.CalledProcessError(1, '', '', '', '')), | 906 subprocess2.CalledProcessError(1, '', '', '', '')), |
| 900 ] | 907 ] |
| 901 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 908 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
| 902 | 909 |
| 903 if __name__ == '__main__': | 910 if __name__ == '__main__': |
| 904 git_cl.logging.basicConfig( | 911 git_cl.logging.basicConfig( |
| 905 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 912 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 906 unittest.main() | 913 unittest.main() |
| OLD | NEW |