| # Copyright 2018 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| from recipe_engine import recipe_test_api |
| |
| from .api import Shard |
| |
| |
| class TestsharderTestApi(recipe_test_api.RecipeTestApi): |
| def shard(self, tests=("hello", "goodbye"), *args, **kwargs): |
| """Creates a Shard object representing a shard.""" |
| # The actual shard test schema has more fields than just "name", but |
| # recipes don't care about any of those fields, so we just use the bare |
| # minimum necessary to be somewhat realistic. |
| kwargs["tests"] = [{"name": test_name} for test_name in tests] |
| return Shard(*args, **kwargs) |
| |
| def execute(self, step_name, shards, stdout=None): |
| """Mocks the result from a call to execute. |
| |
| Args: |
| step_name (str): The name of the step to mock. |
| shards (seq[Shard]): A sequence of Shard objects that will be mocked in |
| as the result for an execute call. |
| stdout (str): The mock stdout of testsharder. |
| """ |
| kwargs = {} |
| if stdout: |
| kwargs["stdout"] = self.m.raw_io.output_text(stdout) |
| return self.step_data( |
| step_name, |
| self.m.json.output([shard.render_to_jsonish() for shard in shards]), |
| **kwargs |
| ) |