Index: scripts/slave/recipe_modules/json/test_api.py |
diff --git a/scripts/slave/recipe_modules/json/test_api.py b/scripts/slave/recipe_modules/json/test_api.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e8a7f4574d10210e653f2d3739d663a25e6c5b81 |
--- /dev/null |
+++ b/scripts/slave/recipe_modules/json/test_api.py |
@@ -0,0 +1,31 @@ |
+from slave import recipe_test_api |
+ |
+from .util import TestResults |
+ |
+class JsonTestApi(recipe_test_api.RecipeTestApi): |
+ @recipe_test_api.placeholder_step_data |
+ @staticmethod |
+ def output(data, retcode=None): |
+ return data, retcode |
+ |
+ @recipe_test_api.placeholder_step_data |
+ @staticmethod |
+ def test_results(test_results, retcode=None): |
+ return test_results.as_jsonish(), retcode |
+ |
+ def canned_test_output(self, good, passes=9001): |
+ """Produces a 'json test results' compatible object with some canned tests. |
+ Args: |
+ good - Determines if this test result is passing or not. |
+ passes - The number of (theoretically) passing tests. |
+ """ |
+ bad = lambda fail_val: None if good else fail_val |
+ t = TestResults() |
+ t.raw['num_passes'] = passes |
+ t.add_result('good/totally-awesome.html', 'PASS') |
+ t.add_result('flake/totally-flakey.html', 'PASS', bad('TIMEOUT PASS')) |
+ t.add_result('tricky/totally-maybe-not-awesome.html', 'PASS', bad('FAIL')) |
+ t.add_result('bad/totally-bad-probably.html', 'PASS', bad('FAIL')) |
+ ret = self.test_results(t) |
+ ret.retcode = 0 if good else 1 |
+ return ret |