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 1899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 u'patchset': 20001, | 1910 u'patchset': 20001, |
1911 u'reason': u'feature', # This is a branch name, but why? | 1911 u'reason': u'feature', # This is a branch name, but why? |
1912 u'rietveld': u'https://codereview.chromium.org', | 1912 u'rietveld': u'https://codereview.chromium.org', |
1913 } | 1913 } |
1914 }) | 1914 }) |
1915 self.assertEqual(build, { | 1915 self.assertEqual(build, { |
1916 u'bucket': u'master.tryserver.chromium', | 1916 u'bucket': u'master.tryserver.chromium', |
1917 u'client_operation_id': u'uuid4', | 1917 u'client_operation_id': u'uuid4', |
1918 u'tags': [u'builder:win', | 1918 u'tags': [u'builder:win', |
1919 u'buildset:patch/rietveld/codereview.chromium.org/123/20001', | 1919 u'buildset:patch/rietveld/codereview.chromium.org/123/20001', |
1920 u'master:tryserver.chromium', | 1920 u'user_agent:git_cl_try', |
1921 u'user_agent:git_cl_try'], | 1921 u'master:tryserver.chromium'], |
1922 }) | 1922 }) |
1923 | 1923 |
1924 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) | 1924 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) |
1925 | 1925 |
1926 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | 1926 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
1927 self.assertEqual(0, git_cl.main([ | 1927 self.assertEqual(0, git_cl.main([ |
1928 'try', '-m', 'tryserver.chromium', '-b', 'win', | 1928 'try', '-m', 'tryserver.chromium', '-b', 'win', |
1929 '-p', 'key=val', '-p', 'json=[{"a":1}, null]'])) | 1929 '-p', 'key=val', '-p', 'json=[{"a":1}, null]'])) |
1930 self.assertRegexpMatches( | 1930 self.assertRegexpMatches( |
1931 git_cl.sys.stdout.getvalue(), | 1931 git_cl.sys.stdout.getvalue(), |
1932 'Tried jobs on:\nMaster: tryserver.chromium') | 1932 'Tried jobs on:\nBucket: master.tryserver.chromium') |
| 1933 |
| 1934 def test_git_cl_try_buildbucket_bucket_flag(self): |
| 1935 self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda _: 20001) |
| 1936 self.mock(git_cl.Changelist, 'GetIssueOwner', lambda _: 'owner@e.mail') |
| 1937 self.mock(git_cl.Changelist, 'GetIssueProject', lambda _: 'depot_tools') |
| 1938 self.mock(git_cl.uuid, 'uuid4', lambda: 'uuid4') |
| 1939 self.calls = [ |
| 1940 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 1941 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), |
| 1942 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 1943 ((['git', 'config', 'rietveld.server'],), |
| 1944 'https://codereview.chromium.org'), |
| 1945 ((['git', 'config', 'branch.feature.rietveldserver'],), CERR1), |
| 1946 ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'), |
| 1947 ] |
| 1948 |
| 1949 def _buildbucket_retry(*_, **kw): |
| 1950 # self.maxDiff = 10000 |
| 1951 body = json.loads(kw['body']) |
| 1952 self.assertEqual(len(body['builds']), 1) |
| 1953 build = body['builds'][0] |
| 1954 params = json.loads(build.pop('parameters_json')) |
| 1955 self.assertEqual(params, { |
| 1956 u'builder_name': u'win', |
| 1957 u'changes': [{u'author': {u'email': u'owner@e.mail'}, |
| 1958 u'revision': None}], |
| 1959 u'properties': { |
| 1960 u'category': u'git_cl_try', |
| 1961 u'issue': 123, |
| 1962 u'patch_project': u'depot_tools', |
| 1963 u'patch_storage': u'rietveld', |
| 1964 u'patchset': 20001, |
| 1965 u'reason': u'feature', # This is a branch name, but why? |
| 1966 u'rietveld': u'https://codereview.chromium.org', |
| 1967 } |
| 1968 }) |
| 1969 self.assertEqual(build, { |
| 1970 u'bucket': u'test.bucket', |
| 1971 u'client_operation_id': u'uuid4', |
| 1972 u'tags': [u'builder:win', |
| 1973 u'buildset:patch/rietveld/codereview.chromium.org/123/20001', |
| 1974 u'user_agent:git_cl_try'], |
| 1975 }) |
| 1976 |
| 1977 self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) |
| 1978 |
| 1979 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 1980 self.assertEqual(0, git_cl.main([ |
| 1981 'try', '-B', 'test.bucket', '-b', 'win'])) |
| 1982 self.assertRegexpMatches( |
| 1983 git_cl.sys.stdout.getvalue(), |
| 1984 'Tried jobs on:\nBucket: test.bucket') |
1933 | 1985 |
1934 def _common_GerritCommitMsgHookCheck(self): | 1986 def _common_GerritCommitMsgHookCheck(self): |
1935 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | 1987 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
1936 self.mock(git_cl.os.path, 'abspath', | 1988 self.mock(git_cl.os.path, 'abspath', |
1937 lambda path: self._mocked_call(['abspath', path])) | 1989 lambda path: self._mocked_call(['abspath', path])) |
1938 self.mock(git_cl.os.path, 'exists', | 1990 self.mock(git_cl.os.path, 'exists', |
1939 lambda path: self._mocked_call(['exists', path])) | 1991 lambda path: self._mocked_call(['exists', path])) |
1940 self.mock(git_cl.gclient_utils, 'FileRead', | 1992 self.mock(git_cl.gclient_utils, 'FileRead', |
1941 lambda path: self._mocked_call(['FileRead', path])) | 1993 lambda path: self._mocked_call(['FileRead', path])) |
1942 self.mock(git_cl.gclient_utils, 'rm_file_or_tree', | 1994 self.mock(git_cl.gclient_utils, 'rm_file_or_tree', |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2121 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning') | 2173 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning') |
2122 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') | 2174 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') |
2123 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') | 2175 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') |
2124 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') | 2176 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') |
2125 | 2177 |
2126 | 2178 |
2127 if __name__ == '__main__': | 2179 if __name__ == '__main__': |
2128 git_cl.logging.basicConfig( | 2180 git_cl.logging.basicConfig( |
2129 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 2181 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
2130 unittest.main() | 2182 unittest.main() |
OLD | NEW |