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 json | 8 import json |
9 import os | 9 import os |
10 import StringIO | 10 import StringIO |
(...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), | 1982 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
1983 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), | 1983 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), |
1984 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), | 1984 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
1985 ((['git', 'config', 'rietveld.server'],), | 1985 ((['git', 'config', 'rietveld.server'],), |
1986 'https://codereview.chromium.org'), | 1986 'https://codereview.chromium.org'), |
1987 ((['git', 'config', 'branch.feature.rietveldserver'],), CERR1), | 1987 ((['git', 'config', 'branch.feature.rietveldserver'],), CERR1), |
1988 ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'), | 1988 ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'), |
1989 ] | 1989 ] |
1990 | 1990 |
1991 def _buildbucket_retry(*_, **kw): | 1991 def _buildbucket_retry(*_, **kw): |
1992 # self.maxDiff = 10000 | |
1993 body = json.loads(kw['body']) | 1992 body = json.loads(kw['body']) |
1994 self.assertEqual(len(body['builds']), 1) | 1993 self.assertEqual(len(body['builds']), 1) |
1995 build = body['builds'][0] | 1994 build = body['builds'][0] |
1996 params = json.loads(build.pop('parameters_json')) | 1995 params = json.loads(build.pop('parameters_json')) |
1997 self.assertEqual(params, { | 1996 self.assertEqual(params, { |
1998 u'builder_name': u'win', | 1997 u'builder_name': u'win', |
1999 u'changes': [{u'author': {u'email': u'owner@e.mail'}, | 1998 u'changes': [{u'author': {u'email': u'owner@e.mail'}, |
2000 u'revision': None}], | 1999 u'revision': None}], |
2001 u'properties': { | 2000 u'properties': { |
2002 u'category': u'git_cl_try', | 2001 u'category': u'git_cl_try', |
(...skipping 15 matching lines...) Expand all Loading... |
2018 | 2017 |
2019 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) | 2018 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) |
2020 | 2019 |
2021 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | 2020 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
2022 self.assertEqual(0, git_cl.main([ | 2021 self.assertEqual(0, git_cl.main([ |
2023 'try', '-B', 'test.bucket', '-b', 'win'])) | 2022 'try', '-B', 'test.bucket', '-b', 'win'])) |
2024 self.assertRegexpMatches( | 2023 self.assertRegexpMatches( |
2025 git_cl.sys.stdout.getvalue(), | 2024 git_cl.sys.stdout.getvalue(), |
2026 'Tried jobs on:\nBucket: test.bucket') | 2025 'Tried jobs on:\nBucket: test.bucket') |
2027 | 2026 |
| 2027 def test_git_cl_try_bots_on_multiple_masters(self): |
| 2028 self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda _: 20001) |
| 2029 self.calls = [ |
| 2030 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2031 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), |
| 2032 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2033 ((['git', 'config', 'rietveld.server'],), |
| 2034 'https://codereview.chromium.org'), |
| 2035 ((['git', 'config', 'branch.feature.rietveldserver'],), CERR1), |
| 2036 ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'), |
| 2037 ] |
| 2038 |
| 2039 def _buildbucket_retry(*_, **kw): |
| 2040 body = json.loads(kw['body']) |
| 2041 self.assertEqual(len(body['builds']), 2) |
| 2042 |
| 2043 first_build_params = json.loads(body['builds'][0]['parameters_json']) |
| 2044 self.assertEqual(first_build_params['builder_name'], 'builder1') |
| 2045 self.assertEqual(first_build_params['properties']['master'], 'master1') |
| 2046 |
| 2047 first_build_params = json.loads(body['builds'][1]['parameters_json']) |
| 2048 self.assertEqual(first_build_params['builder_name'], 'builder2') |
| 2049 self.assertEqual(first_build_params['properties']['master'], 'master2') |
| 2050 |
| 2051 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) |
| 2052 |
| 2053 self.mock(git_cl.urllib2, 'urlopen', lambda _: StringIO.StringIO( |
| 2054 json.dumps({'builder1': ['master1'], 'builder2': ['master2']}))) |
| 2055 |
| 2056 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2057 self.assertEqual( |
| 2058 0, git_cl.main(['try', '-b', 'builder1', '-b', 'builder2'])) |
| 2059 self.assertEqual( |
| 2060 git_cl.sys.stdout.getvalue(), |
| 2061 'Tried jobs on:\n' |
| 2062 'Bucket: master.master1\n' |
| 2063 ' builder1: []\n' |
| 2064 'Bucket: master.master2\n' |
| 2065 ' builder2: []\n' |
| 2066 'To see results here, run: git cl try-results\n' |
| 2067 'To see results in browser, run: git cl web\n') |
| 2068 |
2028 def _common_GerritCommitMsgHookCheck(self): | 2069 def _common_GerritCommitMsgHookCheck(self): |
2029 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | 2070 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
2030 self.mock(git_cl.os.path, 'abspath', | 2071 self.mock(git_cl.os.path, 'abspath', |
2031 lambda path: self._mocked_call(['abspath', path])) | 2072 lambda path: self._mocked_call(['abspath', path])) |
2032 self.mock(git_cl.os.path, 'exists', | 2073 self.mock(git_cl.os.path, 'exists', |
2033 lambda path: self._mocked_call(['exists', path])) | 2074 lambda path: self._mocked_call(['exists', path])) |
2034 self.mock(git_cl.gclient_utils, 'FileRead', | 2075 self.mock(git_cl.gclient_utils, 'FileRead', |
2035 lambda path: self._mocked_call(['FileRead', path])) | 2076 lambda path: self._mocked_call(['FileRead', path])) |
2036 self.mock(git_cl.gclient_utils, 'rm_file_or_tree', | 2077 self.mock(git_cl.gclient_utils, 'rm_file_or_tree', |
2037 lambda path: self._mocked_call(['rm_file_or_tree', path])) | 2078 lambda path: self._mocked_call(['rm_file_or_tree', path])) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning') | 2256 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning') |
2216 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') | 2257 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') |
2217 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') | 2258 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') |
2218 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') | 2259 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') |
2219 | 2260 |
2220 | 2261 |
2221 if __name__ == '__main__': | 2262 if __name__ == '__main__': |
2222 git_cl.logging.basicConfig( | 2263 git_cl.logging.basicConfig( |
2223 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 2264 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
2224 unittest.main() | 2265 unittest.main() |
OLD | NEW |