| 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 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 ((['git', 'var', 'GIT_AUTHOR_IDENT'], ), | 770 ((['git', 'var', 'GIT_AUTHOR_IDENT'], ), |
| 771 'A B <a@b.org> 1456848326 +0100'), | 771 'A B <a@b.org> 1456848326 +0100'), |
| 772 ((['git', 'var', 'GIT_COMMITTER_IDENT'], ), | 772 ((['git', 'var', 'GIT_COMMITTER_IDENT'], ), |
| 773 'C D <c@d.org> 1456858326 +0100'), | 773 'C D <c@d.org> 1456858326 +0100'), |
| 774 ((['git', 'hash-object', '-t', 'commit', '--stdin'], ), | 774 ((['git', 'hash-object', '-t', 'commit', '--stdin'], ), |
| 775 'hashchange'), | 775 'hashchange'), |
| 776 ] | 776 ] |
| 777 change_id = git_cl.GenerateGerritChangeId('line1\nline2\n') | 777 change_id = git_cl.GenerateGerritChangeId('line1\nline2\n') |
| 778 self.assertEqual(change_id, 'Ihashchange') | 778 self.assertEqual(change_id, 'Ihashchange') |
| 779 | 779 |
| 780 def test_config_gerrit_download_hook(self): | |
| 781 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) | |
| 782 def ParseCodereviewSettingsContent(content): | |
| 783 keyvals = {} | |
| 784 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' | |
| 785 keyvals['GERRIT_HOST'] = 'True' | |
| 786 return keyvals | |
| 787 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', | |
| 788 ParseCodereviewSettingsContent) | |
| 789 self.mock(git_cl.os, 'access', self._mocked_call) | |
| 790 self.mock(git_cl.os, 'chmod', self._mocked_call) | |
| 791 src_dir = os.path.join(os.path.sep, 'usr', 'local', 'src') | |
| 792 def AbsPath(path): | |
| 793 if not path.startswith(os.path.sep): | |
| 794 return os.path.join(src_dir, path) | |
| 795 return path | |
| 796 self.mock(git_cl.os.path, 'abspath', AbsPath) | |
| 797 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') | |
| 798 def Exists(path): | |
| 799 if path == commit_msg_path: | |
| 800 return False | |
| 801 # others paths, such as /usr/share/locale/.... | |
| 802 return True | |
| 803 self.mock(git_cl.os.path, 'exists', Exists) | |
| 804 self.mock(git_cl, 'urlretrieve', self._mocked_call) | |
| 805 self.mock(git_cl, 'hasSheBang', self._mocked_call) | |
| 806 self.calls = [ | |
| 807 ((['git', 'config', 'rietveld.autoupdate'],), | |
| 808 ''), | |
| 809 ((['git', 'config', 'rietveld.server', | |
| 810 'gerrit.chromium.org'],), ''), | |
| 811 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), | |
| 812 ((['git', 'config', '--unset-all', | |
| 813 'rietveld.private'],), ''), | |
| 814 ((['git', 'config', '--unset-all', | |
| 815 'rietveld.tree-status-url'],), ''), | |
| 816 ((['git', 'config', '--unset-all', | |
| 817 'rietveld.viewvc-url'],), ''), | |
| 818 ((['git', 'config', '--unset-all', | |
| 819 'rietveld.bug-prefix'],), ''), | |
| 820 ((['git', 'config', '--unset-all', | |
| 821 'rietveld.cpplint-regex'],), ''), | |
| 822 ((['git', 'config', '--unset-all', | |
| 823 'rietveld.force-https-commit-url'],), ''), | |
| 824 ((['git', 'config', '--unset-all', | |
| 825 'rietveld.cpplint-ignore-regex'],), ''), | |
| 826 ((['git', 'config', '--unset-all', | |
| 827 'rietveld.project'],), ''), | |
| 828 ((['git', 'config', '--unset-all', | |
| 829 'rietveld.pending-ref-prefix'],), ''), | |
| 830 ((['git', 'config', '--unset-all', | |
| 831 'rietveld.run-post-upload-hook'],), ''), | |
| 832 ((['git', 'config', 'gerrit.host', 'True'],), ''), | |
| 833 # GetCodereviewSettingsInteractively | |
| 834 ((['git', 'config', 'rietveld.server'],), | |
| 835 'gerrit.chromium.org'), | |
| 836 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), | |
| 837 ''), | |
| 838 ((['git', 'config', 'rietveld.cc'],), ''), | |
| 839 (('CC list:',), ''), | |
| 840 ((['git', 'config', 'rietveld.private'],), ''), | |
| 841 (('Private flag (rietveld only):',), ''), | |
| 842 ((['git', 'config', 'rietveld.tree-status-url'],), ''), | |
| 843 (('Tree status URL:',), ''), | |
| 844 ((['git', 'config', 'rietveld.viewvc-url'],), ''), | |
| 845 (('ViewVC URL:',), ''), | |
| 846 ((['git', 'config', 'rietveld.bug-prefix'],), ''), | |
| 847 (('Bug Prefix:',), ''), | |
| 848 ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), | |
| 849 (('Run Post Upload Hook:',), ''), | |
| 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,), ''), | |
| 858 ] | |
| 859 git_cl.main(['config']) | |
| 860 | |
| 861 def test_update_reviewers(self): | 780 def test_update_reviewers(self): |
| 862 data = [ | 781 data = [ |
| 863 ('foo', [], 'foo'), | 782 ('foo', [], 'foo'), |
| 864 ('foo\nR=xx', [], 'foo\nR=xx'), | 783 ('foo\nR=xx', [], 'foo\nR=xx'), |
| 865 ('foo\nTBR=xx', [], 'foo\nTBR=xx'), | 784 ('foo\nTBR=xx', [], 'foo\nTBR=xx'), |
| 866 ('foo', ['a@c'], 'foo\n\nR=a@c'), | 785 ('foo', ['a@c'], 'foo\n\nR=a@c'), |
| 867 ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'), | 786 ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'), |
| 868 ('foo\nTBR=xx', ['a@c'], 'foo\n\nR=a@c\nTBR=xx'), | 787 ('foo\nTBR=xx', ['a@c'], 'foo\n\nR=a@c\nTBR=xx'), |
| 869 ('foo\nTBR=xx\nR=yy', ['a@c'], 'foo\n\nR=a@c, yy\nTBR=xx'), | 788 ('foo\nTBR=xx\nR=yy', ['a@c'], 'foo\n\nR=a@c, yy\nTBR=xx'), |
| 870 ('foo\nBUG=', ['a@c'], 'foo\nBUG=\nR=a@c'), | 789 ('foo\nBUG=', ['a@c'], 'foo\nBUG=\nR=a@c'), |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 self.calls += [ | 902 self.calls += [ |
| 984 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 903 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
| 985 subprocess2.CalledProcessError(1, '', '', '', '')), | 904 subprocess2.CalledProcessError(1, '', '', '', '')), |
| 986 ] | 905 ] |
| 987 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 906 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
| 988 | 907 |
| 989 if __name__ == '__main__': | 908 if __name__ == '__main__': |
| 990 git_cl.logging.basicConfig( | 909 git_cl.logging.basicConfig( |
| 991 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 910 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 992 unittest.main() | 911 unittest.main() |
| OLD | NEW |