blob: 33b97c422d006ca2f2e0bdc7ce9109974f7687e4 [file] [log] [blame]
# 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, Test
class TestsharderTestApi(recipe_test_api.RecipeTestApi):
def shard(self, *args, **kwargs):
"""Creates a Shard object representing a shard."""
return Shard(*args, **kwargs)
def test(self, name, os="fuchsia", **original_kwargs):
"""Creates a Test object representing a test."""
kwargs = {
"name": name,
"os": os,
"label": "//path/to/%s:%s(//toolchain)" % (name, name),
}
if os == "fuchsia":
package_url = "fuchsia-pkg://fuchsia.com/%s" % name
kwargs["package_url"] = package_url
kwargs["command"] = ["run", package_url]
kwargs["path"] = "/pkgfs/packages/path/to/%s" % name
else:
kwargs["path"] = "host_x64/path/to/%s" % name
kwargs.update(original_kwargs)
return Test(**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
)