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

Side by Side Diff: tests/git_cl_test.py

Issue 2263103002: git cl issue: add --json switch for machine-readable output (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: tests Created 4 years, 4 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 | Annotate | Revision Log
« 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 self.mock(subprocess2, 'communicate', 244 self.mock(subprocess2, 'communicate',
245 lambda *a, **kw: ([self._mocked_call(*a, **kw), ''], 0)) 245 lambda *a, **kw: ([self._mocked_call(*a, **kw), ''], 0))
246 self.mock(git_cl.gclient_utils, 'CheckCallAndFilter', self._mocked_call) 246 self.mock(git_cl.gclient_utils, 'CheckCallAndFilter', self._mocked_call)
247 self.mock(git_common, 'is_dirty_git_tree', lambda x: False) 247 self.mock(git_common, 'is_dirty_git_tree', lambda x: False)
248 self.mock(git_common, 'get_or_create_merge_base', 248 self.mock(git_common, 'get_or_create_merge_base',
249 lambda *a: ( 249 lambda *a: (
250 self._mocked_call(['get_or_create_merge_base']+list(a)))) 250 self._mocked_call(['get_or_create_merge_base']+list(a))))
251 self.mock(git_cl, 'BranchExists', lambda _: True) 251 self.mock(git_cl, 'BranchExists', lambda _: True)
252 self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: '') 252 self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: '')
253 self.mock(git_cl, 'ask_for_data', self._mocked_call) 253 self.mock(git_cl, 'ask_for_data', self._mocked_call)
254 self.mock(git_cl, 'write_json', lambda path, contents:
255 self._mocked_call('write_json', path, contents))
254 self.mock(git_cl.presubmit_support, 'DoPresubmitChecks', PresubmitMock) 256 self.mock(git_cl.presubmit_support, 'DoPresubmitChecks', PresubmitMock)
255 self.mock(git_cl.rietveld, 'Rietveld', RietveldMock) 257 self.mock(git_cl.rietveld, 'Rietveld', RietveldMock)
256 self.mock(git_cl.rietveld, 'CachingRietveld', RietveldMock) 258 self.mock(git_cl.rietveld, 'CachingRietveld', RietveldMock)
257 self.mock(git_cl.upload, 'RealMain', self.fail) 259 self.mock(git_cl.upload, 'RealMain', self.fail)
258 self.mock(git_cl.watchlists, 'Watchlists', WatchlistsMock) 260 self.mock(git_cl.watchlists, 'Watchlists', WatchlistsMock)
259 self.mock(git_cl.auth, 'get_authenticator_for_host', AuthenticatorMock) 261 self.mock(git_cl.auth, 'get_authenticator_for_host', AuthenticatorMock)
260 self.mock(git_cl.gerrit_util.GceAuthenticator, 'is_gce', 262 self.mock(git_cl.gerrit_util.GceAuthenticator, 'is_gce',
261 classmethod(lambda _: False)) 263 classmethod(lambda _: False))
262 # It's important to reset settings to not have inter-tests interference. 264 # It's important to reset settings to not have inter-tests interference.
263 git_cl.settings = None 265 git_cl.settings = None
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],), 1754 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],),
1753 CERR1), 1755 CERR1),
1754 ((['git', 'config', '--unset', 'branch.feature.gerritissue'],), ''), 1756 ((['git', 'config', '--unset', 'branch.feature.gerritissue'],), ''),
1755 ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''), 1757 ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''),
1756 ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''), 1758 ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''),
1757 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],), 1759 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],),
1758 ''), 1760 ''),
1759 ] 1761 ]
1760 self.assertEqual(0, git_cl.main(['issue', '0'])) 1762 self.assertEqual(0, git_cl.main(['issue', '0']))
1761 1763
1764 def test_cmd_issue_json(self):
1765 out = StringIO.StringIO()
1766 self.mock(git_cl.sys, 'stdout', out)
1767 self.calls = [
1768 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1769 ((['git', 'config', '--int', 'branch.feature.rietveldissue'],), '123'),
1770 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1771 ((['git', 'config', 'rietveld.server'],),
1772 'https://codereview.chromium.org'),
1773 ((['git', 'config', 'branch.feature.rietveldserver'],), ''),
1774 (('write_json', 'output.json',
1775 {'issue': 123, 'issue_url': 'https://codereview.chromium.org/123'}),
1776 ''),
1777 ]
1778 self.assertEqual(0, git_cl.main(['issue', '--json', 'output.json']))
1779
1762 def test_git_cl_try_default(self): 1780 def test_git_cl_try_default(self):
1763 self.mock(git_cl.Changelist, 'GetChange', 1781 self.mock(git_cl.Changelist, 'GetChange',
1764 lambda _, *a: ( 1782 lambda _, *a: (
1765 self._mocked_call(['GetChange']+list(a)))) 1783 self._mocked_call(['GetChange']+list(a))))
1766 self.mock(git_cl.presubmit_support, 'DoGetTryMasters', 1784 self.mock(git_cl.presubmit_support, 'DoGetTryMasters',
1767 lambda *_, **__: ( 1785 lambda *_, **__: (
1768 self._mocked_call(['DoGetTryMasters']))) 1786 self._mocked_call(['DoGetTryMasters'])))
1769 self.mock(git_cl.presubmit_support, 'DoGetTrySlaves', 1787 self.mock(git_cl.presubmit_support, 'DoGetTrySlaves',
1770 lambda *_, **__: ( 1788 lambda *_, **__: (
1771 self._mocked_call(['DoGetTrySlaves']))) 1789 self._mocked_call(['DoGetTrySlaves'])))
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), 1857 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],),
1840 ''), 1858 ''),
1841 ] 1859 ]
1842 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) 1860 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True)
1843 1861
1844 1862
1845 if __name__ == '__main__': 1863 if __name__ == '__main__':
1846 git_cl.logging.basicConfig( 1864 git_cl.logging.basicConfig(
1847 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1865 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1848 unittest.main() 1866 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