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

Unified Diff: scripts/slave/recipe_modules/raw_io/api.py

Issue 23889036: Refactor the way that TestApi works so that it is actually useful. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: once more... Created 7 years, 3 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
Index: scripts/slave/recipe_modules/raw_io/api.py
diff --git a/scripts/slave/recipe_modules/raw_io/api.py b/scripts/slave/recipe_modules/raw_io/api.py
new file mode 100644
index 0000000000000000000000000000000000000000..3e8553649665b684846bc6b63cc0adfdcc97ee5f
--- /dev/null
+++ b/scripts/slave/recipe_modules/raw_io/api.py
@@ -0,0 +1,33 @@
+from slave import recipe_api
+from slave import recipe_util
+
+import os
+import tempfile
+
+class InputDataPlaceholder(recipe_util.Placeholder):
+ def __init__(self, data, suffix, mod_name):
+ assert isinstance(data, basestring)
+ self.data = data
+ self.suffix = suffix
+ self.input_file = None
+ super(InputDataPlaceholder, self).__init__('input', mod_name)
+
+ def render(self, test):
+ if test.enabled:
+ # cheat and pretend like we're going to pass the data on the
+ # cmdline for test expectation purposes.
+ return [self.data]
+ else: # pragma: no cover
+ input_fd, self.input_file = tempfile.mkstemp(suffix=self.suffix)
+ os.write(input_fd, self.data)
+ os.close(input_fd)
+ return [self.input_file]
+
+ def result(self, presentation, test):
+ if not test.enabled: # pragma: no cover
+ os.unlink(self.input_file)
+
+
+class RawApi(recipe_api.RecipeApi):
agable 2013/09/23 22:57:58 a) This class name should match the file name. b)
iannucci 2013/09/24 02:18:51 a) yes. Done. b) implemented output, made json.out
+ def input(self, data, suffix, mod_name=None):
+ return InputDataPlaceholder(data, suffix, mod_name or self.name)

Powered by Google App Engine
This is Rietveld 408576698