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

Side by Side Diff: tests/git_cl_test.py

Issue 2045973002: Gerrit git cl upload: warn and offer to remove Gerrit commit-msg hook. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: review Created 4 years, 6 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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 reviewers=None, 871 reviewers=None,
872 squash=False, 872 squash=False,
873 expected_upstream_ref='origin/refs/heads/master', 873 expected_upstream_ref='origin/refs/heads/master',
874 ref_suffix='', 874 ref_suffix='',
875 notify=False, 875 notify=False,
876 post_amend_description=None, 876 post_amend_description=None,
877 issue=None): 877 issue=None):
878 """Generic gerrit upload test framework.""" 878 """Generic gerrit upload test framework."""
879 reviewers = reviewers or [] 879 reviewers = reviewers or []
880 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 880 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
881 self.mock(git_cl.gerrit_util, "CookiesAuthenticator", 881 self.mock(git_cl.gerrit_util, 'CookiesAuthenticator',
882 CookiesAuthenticatorMockFactory(same_cookie='same_cred')) 882 CookiesAuthenticatorMockFactory(same_cookie='same_cred'))
883 self.mock(git_cl._GerritChangelistImpl, '_GerritCommitMsgHookCheck',
884 lambda _, offer_removal: None)
883 self.calls = self._gerrit_base_calls(issue=issue) 885 self.calls = self._gerrit_base_calls(issue=issue)
884 self.calls += self._gerrit_upload_calls( 886 self.calls += self._gerrit_upload_calls(
885 description, reviewers, squash, 887 description, reviewers, squash,
886 expected_upstream_ref=expected_upstream_ref, 888 expected_upstream_ref=expected_upstream_ref,
887 ref_suffix=ref_suffix, notify=notify, 889 ref_suffix=ref_suffix, notify=notify,
888 post_amend_description=post_amend_description, 890 post_amend_description=post_amend_description,
889 issue=issue) 891 issue=issue)
890 # Uncomment when debugging. 892 # Uncomment when debugging.
891 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) 893 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls)))
892 git_cl.main(['upload'] + upload_args) 894 git_cl.main(['upload'] + upload_args)
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''), 1519 ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''),
1518 # Let this command raise exception (retcode=1) - it should be ignored. 1520 # Let this command raise exception (retcode=1) - it should be ignored.
1519 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],), 1521 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],),
1520 '', subprocess2.CalledProcessError(1, '', '', '', '')), 1522 '', subprocess2.CalledProcessError(1, '', '', '', '')),
1521 ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''), 1523 ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''),
1522 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],), 1524 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],),
1523 ''), 1525 ''),
1524 ] 1526 ]
1525 self.assertEqual(0, git_cl.main(['issue', '0'])) 1527 self.assertEqual(0, git_cl.main(['issue', '0']))
1526 1528
1529 def _common_GerritCommitMsgHookCheck(self):
1530 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1531 self.mock(git_cl.os.path, 'abspath',
1532 lambda path: self._mocked_call(['abspath', path]))
1533 self.mock(git_cl.os.path, 'exists',
1534 lambda path: self._mocked_call(['exists', path]))
1535 self.mock(git_cl.gclient_utils, 'FileRead',
1536 lambda path: self._mocked_call(['FileRead', path]))
1537 self.mock(git_cl.gclient_utils, 'rm_file_or_tree',
1538 lambda path: self._mocked_call(['rm_file_or_tree', path]))
1539 self.calls = [
1540 ((['git', 'rev-parse', '--show-cdup'],), '../'),
1541 ((['abspath', '../'],), '/abs/git_repo_root'),
1542 ]
1543 return git_cl.Changelist(codereview='gerrit', issue=123)
1544
1545 def test_GerritCommitMsgHookCheck_custom_hook(self):
1546 cl = self._common_GerritCommitMsgHookCheck()
1547 self.calls += [
1548 ((['exists', '/abs/git_repo_root/.git/hooks/commit-msg'],), True),
1549 ((['FileRead', '/abs/git_repo_root/.git/hooks/commit-msg'],),
1550 '#!/bin/sh\necho "custom hook"')
1551 ]
1552 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True)
1553
1554 def test_GerritCommitMsgHookCheck_not_exists(self):
1555 cl = self._common_GerritCommitMsgHookCheck()
1556 self.calls += [
1557 ((['exists', '/abs/git_repo_root/.git/hooks/commit-msg'],), False),
1558 ]
1559 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True)
1560
1561 def test_GerritCommitMsgHookCheck(self):
1562 cl = self._common_GerritCommitMsgHookCheck()
1563 self.calls += [
1564 ((['exists', '/abs/git_repo_root/.git/hooks/commit-msg'],), True),
1565 ((['FileRead', '/abs/git_repo_root/.git/hooks/commit-msg'],),
1566 '...\n# From Gerrit Code Review\n...\nadd_ChangeId()\n'),
1567 (('Do you want to remove it now? [Yes/No]',), 'Yes'),
1568 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],),
1569 ''),
1570 ]
1571 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True)
1572
1527 1573
1528 if __name__ == '__main__': 1574 if __name__ == '__main__':
1529 git_cl.logging.basicConfig( 1575 git_cl.logging.basicConfig(
1530 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1576 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1531 unittest.main() 1577 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