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

Side by Side Diff: tests/git_cl_test.py

Issue 2409223002: git cl try: make code less Rietveld-specific. (Closed)
Patch Set: Review. Created 4 years, 2 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 json
8 import os 9 import os
9 import StringIO 10 import StringIO
10 import stat
11 import sys 11 import sys
12 import unittest 12 import unittest
13 import urlparse 13 import urlparse
14 14
15 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 15 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
16 16
17 from testing_support.auto_stub import TestCase 17 from testing_support.auto_stub import TestCase
18 18
19 import git_cl 19 import git_cl
20 import git_common 20 import git_common
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 ((['git', 'config', 'rietveld.autoupdate'],), ''), 1829 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1830 ((['git', 'config', 'rietveld.server'],), 1830 ((['git', 'config', 'rietveld.server'],),
1831 'https://codereview.chromium.org'), 1831 'https://codereview.chromium.org'),
1832 ((['git', 'config', 'branch.feature.rietveldserver'],), ''), 1832 ((['git', 'config', 'branch.feature.rietveldserver'],), ''),
1833 (('write_json', 'output.json', 1833 (('write_json', 'output.json',
1834 {'issue': 123, 'issue_url': 'https://codereview.chromium.org/123'}), 1834 {'issue': 123, 'issue_url': 'https://codereview.chromium.org/123'}),
1835 ''), 1835 ''),
1836 ] 1836 ]
1837 self.assertEqual(0, git_cl.main(['issue', '--json', 'output.json'])) 1837 self.assertEqual(0, git_cl.main(['issue', '--json', 'output.json']))
1838 1838
1839 def test_git_cl_try_default(self): 1839 def test_git_cl_try_default_cq_dry_run(self):
1840 self.mock(git_cl.Changelist, 'GetChange', 1840 self.mock(git_cl.Changelist, 'GetChange',
1841 lambda _, *a: ( 1841 lambda _, *a: (
1842 self._mocked_call(['GetChange']+list(a)))) 1842 self._mocked_call(['GetChange']+list(a))))
1843 self.mock(git_cl.presubmit_support, 'DoGetTryMasters', 1843 self.mock(git_cl.presubmit_support, 'DoGetTryMasters',
1844 lambda *_, **__: ( 1844 lambda *_, **__: (
1845 self._mocked_call(['DoGetTryMasters']))) 1845 self._mocked_call(['DoGetTryMasters'])))
1846 self.mock(git_cl.presubmit_support, 'DoGetTrySlaves', 1846 self.mock(git_cl.presubmit_support, 'DoGetTrySlaves',
1847 lambda *_, **__: ( 1847 lambda *_, **__: (
1848 self._mocked_call(['DoGetTrySlaves']))) 1848 self._mocked_call(['DoGetTrySlaves'])))
1849 self.mock(git_cl._RietveldChangelistImpl, 'SetCQState', 1849 self.mock(git_cl._RietveldChangelistImpl, 'SetCQState',
(...skipping 17 matching lines...) Expand all
1867 ((['DoGetTrySlaves'], ), None), 1867 ((['DoGetTrySlaves'], ), None),
1868 ((['SetCQState', git_cl._CQState.DRY_RUN], ), None), 1868 ((['SetCQState', git_cl._CQState.DRY_RUN], ), None),
1869 ] 1869 ]
1870 out = StringIO.StringIO() 1870 out = StringIO.StringIO()
1871 self.mock(git_cl.sys, 'stdout', out) 1871 self.mock(git_cl.sys, 'stdout', out)
1872 self.assertEqual(0, git_cl.main(['try'])) 1872 self.assertEqual(0, git_cl.main(['try']))
1873 self.assertEqual( 1873 self.assertEqual(
1874 out.getvalue(), 1874 out.getvalue(),
1875 'scheduled CQ Dry Run on https://codereview.chromium.org/123\n') 1875 'scheduled CQ Dry Run on https://codereview.chromium.org/123\n')
1876 1876
1877 def test_git_cl_try_buildbucket_with_properties(self):
1878 self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda _: 20001)
1879 self.mock(git_cl.Changelist, 'GetIssueOwner', lambda _: 'owner@e.mail')
1880 self.mock(git_cl.Changelist, 'GetIssueProject', lambda _: 'depot_tools')
1881 self.mock(git_cl.uuid, 'uuid4', lambda: 'uuid4')
1882 self.calls = [
1883 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1884 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'),
1885 ((['git', 'config', 'rietveld.autoupdate'],), CERR1),
1886 ((['git', 'config', 'rietveld.server'],),
1887 'https://codereview.chromium.org'),
1888 ((['git', 'config', 'branch.feature.rietveldserver'],), CERR1),
1889 ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'),
1890 ]
1891
1892 def _buildbucket_retry(*_, **kw):
1893 # self.maxDiff = 10000
1894 body = json.loads(kw['body'])
1895 self.assertEqual(len(body['builds']), 1)
1896 build = body['builds'][0]
1897 params = json.loads(build.pop('parameters_json'))
1898 self.assertEqual(params, {
1899 u'builder_name': u'win',
1900 u'changes': [{u'author': {u'email': u'owner@e.mail'},
1901 u'revision': None}],
1902 u'properties': {
1903 u'category': u'git_cl_try',
1904 u'issue': 123,
1905 u'key': u'val',
1906 u'json': [{u'a': 1}, None],
1907 u'master': u'tryserver.chromium',
1908 u'patch_project': u'depot_tools',
1909 u'patch_storage': u'rietveld',
1910 u'patchset': 20001,
1911 u'reason': u'feature', # This is a branch name, but why?
1912 u'rietveld': u'https://codereview.chromium.org',
1913 }
1914 })
1915 self.assertEqual(build, {
1916 u'bucket': u'master.tryserver.chromium',
1917 u'client_operation_id': u'uuid4',
1918 u'tags': [u'builder:win',
1919 u'buildset:patch/rietveld/codereview.chromium.org/123/20001',
1920 u'master:tryserver.chromium',
1921 u'user_agent:git_cl_try'],
1922 })
1923
1924 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry)
1925
1926 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1927 self.assertEqual(0, git_cl.main([
1928 'try', '-m', 'tryserver.chromium', '-b', 'win',
1929 '-p', 'key=val', '-p', 'json=[{"a":1}, null]']))
1930 self.assertRegexpMatches(
1931 git_cl.sys.stdout.getvalue(),
1932 'Tried jobs on:\nMaster: tryserver.chromium')
1933
1877 def _common_GerritCommitMsgHookCheck(self): 1934 def _common_GerritCommitMsgHookCheck(self):
1878 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 1935 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1879 self.mock(git_cl.os.path, 'abspath', 1936 self.mock(git_cl.os.path, 'abspath',
1880 lambda path: self._mocked_call(['abspath', path])) 1937 lambda path: self._mocked_call(['abspath', path]))
1881 self.mock(git_cl.os.path, 'exists', 1938 self.mock(git_cl.os.path, 'exists',
1882 lambda path: self._mocked_call(['exists', path])) 1939 lambda path: self._mocked_call(['exists', path]))
1883 self.mock(git_cl.gclient_utils, 'FileRead', 1940 self.mock(git_cl.gclient_utils, 'FileRead',
1884 lambda path: self._mocked_call(['FileRead', path])) 1941 lambda path: self._mocked_call(['FileRead', path]))
1885 self.mock(git_cl.gclient_utils, 'rm_file_or_tree', 1942 self.mock(git_cl.gclient_utils, 'rm_file_or_tree',
1886 lambda path: self._mocked_call(['rm_file_or_tree', path])) 1943 lambda path: self._mocked_call(['rm_file_or_tree', path]))
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning') 2121 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning')
2065 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') 2122 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:')
2066 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') 2123 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:')
2067 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') 2124 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs')
2068 2125
2069 2126
2070 if __name__ == '__main__': 2127 if __name__ == '__main__':
2071 git_cl.logging.basicConfig( 2128 git_cl.logging.basicConfig(
2072 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 2129 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
2073 unittest.main() 2130 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