Chromium Code Reviews| Index: recipe_modules/properties/test_api.py |
| diff --git a/recipe_modules/properties/test_api.py b/recipe_modules/properties/test_api.py |
| index cd5ac312909fc35409c300f3939ea267d0df5e3f..fe94564f0ecfe424adb782116b435af901c16fb8 100644 |
| --- a/recipe_modules/properties/test_api.py |
| +++ b/recipe_modules/properties/test_api.py |
| @@ -2,6 +2,9 @@ |
| # Use of this source code is governed under the Apache License, Version 2.0 |
| # that can be found in the LICENSE file. |
| +import re |
| +import urlparse |
| + |
| from recipe_engine import recipe_test_api |
| class PropertiesTestApi(recipe_test_api.RecipeTestApi): |
| @@ -54,27 +57,82 @@ class PropertiesTestApi(recipe_test_api.RecipeTestApi): |
| ret.properties.update(kwargs) |
| return ret |
| + def _gerrit_tryserver(self, **kwargs): |
| + # Call it through self.tryserver with (gerrit_project='infra/infra'). |
| + project = kwargs.pop('gerrit_project') |
| + gerrit_url = kwargs.pop('gerrit_url', None) |
| + git_url = kwargs.pop('git_url', None) |
| + if not gerrit_url and not git_url: |
| + gerrit_url = 'https://chromium-review.googlesource.com' |
| + git_url = 'https://chromium.googlesource.com/' + project |
| + elif gerrit_url and not git_url: |
| + parsed = list(urlparse.urlparse(gerrit_url)) |
| + m = re.match(r'^((\w+)(-\w+)*)-review.googlesource.com$', parsed[1]) |
| + if not m: # pragma: no cover |
| + raise AssertionError('Can\'t guess git_url from gerrit_url "%s", ' |
| + 'specify it as extra kwarg' % parsed[1]) |
| + parsed[1] = m.group(1) + '.googlesource.com' |
| + parsed[2] = project |
| + git_url = urlparse.urlunparse(parsed) |
| + elif git_url and not gerrit_url: |
| + parsed = list(urlparse.urlparse(git_url)) |
| + m = re.match(r'^((\w+)(-\w+)*).googlesource.com$', parsed[1]) |
| + if not m: # pragma: no cover |
| + raise AssertionError('Can\'t guess gerrit_url from git_url "%s", ' |
| + 'specify it as extra kwarg' % parsed[1]) |
| + parsed[1] = m.group(1) + '-review.googlesource.com' |
| + gerrit_url = urlparse.urlunparse(parsed[:2] + [''] * len(parsed[2:])) |
| + assert project |
| + assert git_url |
| + assert gerrit_url |
| + # Pop old style values from kwargs. |
| + patch_issue = int(kwargs.pop('issue', 456789)) |
| + patch_set = int(kwargs.pop('patchset', 12)) |
| + # Note that new Gerrit patch properties all start with 'patch_' prefix. |
| + ret = self.generic( |
| + patch_storage='gerrit', |
| + patch_gerrit_url=gerrit_url, |
| + patch_project=project, |
| + patch_branch='master', |
| + patch_issue=patch_issue, |
| + patch_set=patch_set, |
| + patch_repository_url=git_url, |
| + patch_ref='refs/changes/%2d/%d/%d' % ( |
| + patch_issue % 100, patch_issue, patch_set) |
| + ) |
| + ret.properties.update(kwargs) |
| + return ret |
| + |
| def tryserver(self, **kwargs): |
| """ |
| Merge kwargs into a typical buildbot properties blob for a job fired off |
| by a rietveld tryjob on the tryserver, and return the blob. |
| + |
| + If gerrit_project is given, generated properties for tryjobs for Gerrit |
| + patches as if they were scheduled by CQ. In this case, gerrit_url and |
| + git_url could be used to customize expectations. |
| """ |
| - ret = self.generic( |
| - branch='', |
| - issue=12853011, |
| - patchset=1, |
| - project='chrome', |
| - repository='', |
| - requester='commit-bot@chromium.org', |
| - revision='HEAD', |
| - rietveld='https://codereview.chromium.org', |
| - patch_project='chromium', |
| - ) |
| + if kwargs.get('gerrit_project') is not None: |
| + return self._gerrit_tryserver(**kwargs) |
| + else: |
|
Paweł Hajdan Jr.
2016/10/25 10:58:54
nit: No need for "else" after return.
tandrii(chromium)
2016/10/25 12:38:31
Done.
|
| + ret = self.generic( |
| + branch='', |
| + issue=12853011, |
| + patchset=1, |
| + project='chrome', |
| + repository='', |
| + requester='commit-bot@chromium.org', |
| + revision='HEAD', |
| + rietveld='https://codereview.chromium.org', |
| + patch_project='chromium', |
| + ) |
| ret.properties.update(kwargs) |
| return ret |
| def tryserver_gerrit(self, full_project_name, gerrit_host=None, **kwargs): |
| """ |
| + DEPRECATED. Use tryserver(gerrit_project='infra/infra') instead. |
| + |
| Merge kwargs into a typical buildbot properties blob for a job fired off |
| by a gerrit tryjob on the tryserver, and return the blob. |
| @@ -83,6 +141,7 @@ class PropertiesTestApi(recipe_test_api.RecipeTestApi): |
| gerrit_host: hostname of the gerrit server. |
| Example: chromium-review.googlesource.com. |
| """ |
| + # TODO(tandrii): remove this method. |
| gerrit_host = gerrit_host or 'chromium-review.googlesource.com' |
| parts = gerrit_host.split('.') |
| assert parts[0].endswith('-review') |