| # Copyright 2019 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 google.protobuf import text_format as textpb |
| from recipe_engine import recipe_test_api |
| |
| |
| class TextProtoTestApi(recipe_test_api.RecipeTestApi): |
| def spec_not_found(self, step_name="read spec"): |
| """Returns mock step data that simulates a missing spec file.""" |
| return self.step_data(step_name, self.m.file.read_raw(errno_name="EEXIST")) |
| |
| def spec_parse_error(self, step_name="read spec"): |
| """Returns mock step data that simulates a spec file that fails to parse.""" |
| return self.step_data( |
| step_name, |
| self.m.file.read_raw(content="not a proto message"), |
| ) |
| |
| def spec_loaded_ok(self, message, step_name="read spec"): |
| """Returns mock step data that simulates successfully fetching a spec file. |
| |
| Args: |
| message: The spec as a protobuf Message. |
| """ |
| return self.step_data( |
| step_name, |
| self.m.file.read_raw(content=textpb.MessageToString(message)), |
| ) |