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

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: License headers 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
« no previous file with comments | « scripts/slave/recipe_modules/raw_io/__init__.py ('k') | scripts/slave/recipe_modules/step/api.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e64be685ab82a3316b1102c19621b8006ae1c717
--- /dev/null
+++ b/scripts/slave/recipe_modules/raw_io/api.py
@@ -0,0 +1,66 @@
+from slave import recipe_api
+from slave import recipe_util
+
+import os
+import tempfile
+
+class InputDataPlaceholder(recipe_util.Placeholder):
+ def __init__(self, data, suffix):
+ assert isinstance(data, basestring)
+ self.data = data
+ self.suffix = suffix
+ self.input_file = None
+ super(InputDataPlaceholder, self).__init__()
+
+ 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 OutputDataPlaceholder(recipe_util.Placeholder):
+ def __init__(self, suffix):
+ self.suffix = suffix
+ self.output_file = None
+ super(OutputDataPlaceholder, self).__init__()
+
+ def render(self, test):
+ if test.enabled:
+ return ['/path/to/tmp/' + self.suffix.lstrip('.')]
+ else: # pragma: no cover
+ output_fd, self.output_file = tempfile.mkstemp(self.suffix)
+ os.close(output_fd)
+ return [self.output_file]
+
+ def result(self, presentation, test):
+ if test.enabled:
+ return test.data
+ else: # pragma: no cover
+ assert self.output_file is not None
+ try:
+ with open(self.output_file.read(), 'rb') as f:
+ return f.read()
+ finally:
+ os.unlink(self.output_file)
+
+
+class RawIOApi(recipe_api.RecipeApi):
+ @recipe_util.returns_placeholder
+ @staticmethod
+ def input(data, suffix):
+ return InputDataPlaceholder(data, suffix)
+
+ @recipe_util.returns_placeholder
+ @staticmethod
+ def output(suffix):
+ return OutputDataPlaceholder(suffix)
« no previous file with comments | « scripts/slave/recipe_modules/raw_io/__init__.py ('k') | scripts/slave/recipe_modules/step/api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698