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..23bfeaa0ea1ec4a3ffaafe8f497302a559275c1f 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 urlparse |
Michael Achenbach
2016/10/24 09:24:34
nit: sort
tandrii(chromium)
2016/10/24 11:23:17
Done.
|
+import re |
+ |
from recipe_engine import recipe_test_api |
class PropertiesTestApi(recipe_test_api.RecipeTestApi): |
@@ -54,27 +57,80 @@ 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('^((\w+)(-\w+)*)-review.googlesource.com$', parsed[1]) |
Michael Achenbach
2016/10/24 09:24:34
Don't you need an r'' ?
Michael Achenbach
2016/10/24 09:24:34
Maybe mark the non-capturing groups as you don't n
tandrii(chromium)
2016/10/24 11:23:17
I don't understand why. I take 1st group, which is
tandrii(chromium)
2016/10/24 11:23:17
I do, and I'd swear it was there. How does it even
Michael Achenbach
2016/10/24 11:51:51
This would be the syntax, e.g. see:
https://docs.p
|
+ assert m, ('Can\'t guess git_url from gerrit_url "%s", ' |
martiniss
2016/10/24 16:48:21
nit: asserts can be disabled in python, turn this
tandrii(chromium)
2016/10/24 18:02:19
I know, but
a) this is a test expectation, so disa
|
+ '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('^((\w+)(-\w+)*).googlesource.com$', parsed[1]) |
+ assert m, ('Can\'t guess gerrit_url from git_url "%s", ' |
+ ', specify it as extra kwarg' % parsed[1]) |
Michael Achenbach
2016/10/24 09:24:34
nit: double comma
|
+ parsed[1] = m.group(1) + '.googlesource.com' |
Michael Achenbach
2016/10/24 09:24:34
Don't you need to add "-review" in this case? Thou
tandrii(chromium)
2016/10/24 11:23:17
Yep, fixed.
|
+ 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, |
Michael Achenbach
2016/10/24 09:24:34
Why not use equal names (e.g. patch_gerrit_url for
tandrii(chromium)
2016/10/24 11:23:17
I was and am undecided on this one. I didn't want
Michael Achenbach
2016/10/24 11:51:51
Ack. Your choice. I don't have a strong opinion he
|
+ 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: |
+ 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 +139,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') |