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

Side by Side Diff: tests/git_cl_test.py

Issue 2419113002: Add -B/--bucket flag to git-cl try (Closed)
Patch Set: Fix indent 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 json
9 import os 9 import os
10 import StringIO 10 import StringIO
(...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 u'patchset': 20001, 1934 u'patchset': 20001,
1935 u'reason': u'feature', # This is a branch name, but why? 1935 u'reason': u'feature', # This is a branch name, but why?
1936 u'rietveld': u'https://codereview.chromium.org', 1936 u'rietveld': u'https://codereview.chromium.org',
1937 } 1937 }
1938 }) 1938 })
1939 self.assertEqual(build, { 1939 self.assertEqual(build, {
1940 u'bucket': u'master.tryserver.chromium', 1940 u'bucket': u'master.tryserver.chromium',
1941 u'client_operation_id': u'uuid4', 1941 u'client_operation_id': u'uuid4',
1942 u'tags': [u'builder:win', 1942 u'tags': [u'builder:win',
1943 u'buildset:patch/rietveld/codereview.chromium.org/123/20001', 1943 u'buildset:patch/rietveld/codereview.chromium.org/123/20001',
1944 u'master:tryserver.chromium', 1944 u'user_agent:git_cl_try',
1945 u'user_agent:git_cl_try'], 1945 u'master:tryserver.chromium'],
1946 }) 1946 })
1947 1947
1948 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) 1948 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry)
1949 1949
1950 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 1950 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1951 self.assertEqual(0, git_cl.main([ 1951 self.assertEqual(0, git_cl.main([
1952 'try', '-m', 'tryserver.chromium', '-b', 'win', 1952 'try', '-m', 'tryserver.chromium', '-b', 'win',
1953 '-p', 'key=val', '-p', 'json=[{"a":1}, null]'])) 1953 '-p', 'key=val', '-p', 'json=[{"a":1}, null]']))
1954 self.assertRegexpMatches( 1954 self.assertRegexpMatches(
1955 git_cl.sys.stdout.getvalue(), 1955 git_cl.sys.stdout.getvalue(),
1956 'Tried jobs on:\nMaster: tryserver.chromium') 1956 'Tried jobs on:\nBucket: master.tryserver.chromium')
1957
1958 def test_git_cl_try_buildbucket_bucket_flag(self):
1959 self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda _: 20001)
1960 self.mock(git_cl.Changelist, 'GetIssueOwner', lambda _: 'owner@e.mail')
1961 self.mock(git_cl.Changelist, 'GetIssueProject', lambda _: 'depot_tools')
1962 self.mock(git_cl.uuid, 'uuid4', lambda: 'uuid4')
1963 self.calls = [
1964 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1965 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'),
1966 ((['git', 'config', 'rietveld.autoupdate'],), CERR1),
1967 ((['git', 'config', 'rietveld.server'],),
1968 'https://codereview.chromium.org'),
1969 ((['git', 'config', 'branch.feature.rietveldserver'],), CERR1),
1970 ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'),
1971 ]
1972
1973 def _buildbucket_retry(*_, **kw):
1974 # self.maxDiff = 10000
1975 body = json.loads(kw['body'])
1976 self.assertEqual(len(body['builds']), 1)
1977 build = body['builds'][0]
1978 params = json.loads(build.pop('parameters_json'))
1979 self.assertEqual(params, {
1980 u'builder_name': u'win',
1981 u'changes': [{u'author': {u'email': u'owner@e.mail'},
1982 u'revision': None}],
1983 u'properties': {
1984 u'category': u'git_cl_try',
1985 u'issue': 123,
1986 u'patch_project': u'depot_tools',
1987 u'patch_storage': u'rietveld',
1988 u'patchset': 20001,
1989 u'reason': u'feature', # This is a branch name, but why?
1990 u'rietveld': u'https://codereview.chromium.org',
1991 }
1992 })
1993 self.assertEqual(build, {
1994 u'bucket': u'test.bucket',
1995 u'client_operation_id': u'uuid4',
1996 u'tags': [u'builder:win',
1997 u'buildset:patch/rietveld/codereview.chromium.org/123/20001',
1998 u'user_agent:git_cl_try'],
1999 })
2000
2001 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry)
2002
2003 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
2004 self.assertEqual(0, git_cl.main([
2005 'try', '-B', 'test.bucket', '-b', 'win']))
2006 self.assertRegexpMatches(
2007 git_cl.sys.stdout.getvalue(),
2008 'Tried jobs on:\nBucket: test.bucket')
1957 2009
1958 def _common_GerritCommitMsgHookCheck(self): 2010 def _common_GerritCommitMsgHookCheck(self):
1959 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 2011 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1960 self.mock(git_cl.os.path, 'abspath', 2012 self.mock(git_cl.os.path, 'abspath',
1961 lambda path: self._mocked_call(['abspath', path])) 2013 lambda path: self._mocked_call(['abspath', path]))
1962 self.mock(git_cl.os.path, 'exists', 2014 self.mock(git_cl.os.path, 'exists',
1963 lambda path: self._mocked_call(['exists', path])) 2015 lambda path: self._mocked_call(['exists', path]))
1964 self.mock(git_cl.gclient_utils, 'FileRead', 2016 self.mock(git_cl.gclient_utils, 'FileRead',
1965 lambda path: self._mocked_call(['FileRead', path])) 2017 lambda path: self._mocked_call(['FileRead', path]))
1966 self.mock(git_cl.gclient_utils, 'rm_file_or_tree', 2018 self.mock(git_cl.gclient_utils, 'rm_file_or_tree',
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
2145 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning') 2197 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning')
2146 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') 2198 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:')
2147 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') 2199 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:')
2148 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') 2200 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs')
2149 2201
2150 2202
2151 if __name__ == '__main__': 2203 if __name__ == '__main__':
2152 git_cl.logging.basicConfig( 2204 git_cl.logging.basicConfig(
2153 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 2205 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
2154 unittest.main() 2206 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