| # Copyright 2020 The Chromium 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_api |
| |
| |
| class YamlApi(recipe_api.RecipeApi): |
| """Provides functions to parse YAML files.""" |
| |
| def read_file(self, name, file_path, test_data=None): |
| """Parse a yaml file and return its content as a dictionary. |
| |
| Args: |
| name (str): The step name to assign. |
| file_path (Path): The path to the YAML file. |
| test_data (dict or list): Mock YAML data to return. |
| """ |
| return self.m.step( |
| name, |
| [self.resource("parse_yaml.py"), file_path], |
| stdout=self.m.json.output(), |
| step_test_data=lambda: self.m.json.test_api.output_stream(test_data), |
| ).stdout |