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

Unified Diff: recipe_modules/gclient/test_api.py

Issue 1651033004: depot_tools: import bot_update gclient git rietveld tryserver recipe modules (reland #1) (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: 80cols Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « recipe_modules/gclient/example.expected/tryserver.json ('k') | recipe_modules/git/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_modules/gclient/test_api.py
diff --git a/recipe_modules/gclient/test_api.py b/recipe_modules/gclient/test_api.py
new file mode 100644
index 0000000000000000000000000000000000000000..be9338de86642ef8adae94a477f7d2254f7ed9bf
--- /dev/null
+++ b/recipe_modules/gclient/test_api.py
@@ -0,0 +1,37 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import hashlib
+
+from recipe_engine import recipe_test_api
+
+class GclientTestApi(recipe_test_api.RecipeTestApi):
+ def output_json(self, projects, git_mode=False):
+ """Deterministically synthesize json.output test data for gclient's
+ --output-json option.
+
+ Args:
+ projects - a list of project paths (e.g. ['src', 'src/dependency'])
+ git_mode - Return git hashes instead of svn revs.
+ """
+ # TODO(iannucci): Account for parent_got_revision_mapping. Right now the
+ # synthesized json output from this method will always use
+ # gen_revision(project), but if parent_got_revision and its ilk are
+ # specified, we should use those values instead.
+ return self.m.json.output({
+ 'solutions': dict(
+ (p+'/', {'revision': self.gen_revision(p, git_mode)})
+ for p in projects
+ )
+ })
+
+ @staticmethod
+ def gen_revision(project, GIT_MODE):
+ """Hash project to bogus deterministic revision values."""
+ h = hashlib.sha1(project)
+ if GIT_MODE:
+ return h.hexdigest()
+ else:
+ import struct
+ return struct.unpack('!I', h.digest()[:4])[0] % 300000
« no previous file with comments | « recipe_modules/gclient/example.expected/tryserver.json ('k') | recipe_modules/git/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698