diff options
author | Angelos Evripiotis <jevripiotis@bloomberg.net> | 2019-03-20 14:03:22 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-03-26 18:27:58 +0000 |
commit | 3bb273564e0f0b3666217ba087f319ad5c8d27d7 (patch) | |
tree | 9fbdeb0e5dd07c760dc68fa0612a0796a76284fc /tests/testutils | |
parent | 02578fddc7d2290c2b960c2841e37366bc552c9a (diff) | |
download | buildstream-3bb273564e0f0b3666217ba087f319ad5c8d27d7.tar.gz |
test: Add yaml_file_get_provenance
Add a new helper - testutils.yaml_file_get_provenance, this will let us
make less fragile assertions about the presence of provenance in
BuildStream output.
Diffstat (limited to 'tests/testutils')
-rw-r--r-- | tests/testutils/__init__.py | 1 | ||||
-rw-r--r-- | tests/testutils/yaml.py | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/testutils/__init__.py b/tests/testutils/__init__.py index 173cc7c3e..67378c959 100644 --- a/tests/testutils/__init__.py +++ b/tests/testutils/__init__.py @@ -29,3 +29,4 @@ from .element_generators import create_element_size, update_element_size from .junction import generate_junction from .runner_integration import wait_for_cache_granularity from .python_repo import setup_pypi_repo +from .yaml import yaml_file_get_provenance diff --git a/tests/testutils/yaml.py b/tests/testutils/yaml.py new file mode 100644 index 000000000..4706a27bb --- /dev/null +++ b/tests/testutils/yaml.py @@ -0,0 +1,28 @@ +from buildstream import _yaml + + +# yaml_file_get_provenance() +# +# Load a yaml file and return it's _yaml.Provenance object. +# +# This is useful for checking the provenance in BuildStream output is as +# expected. +# +# Args: +# path (str): The path to the file to be loaded +# shortname (str): How the path should appear in the error +# key (str): Optional key to look up in the loaded file +# indices (list of indexes): Optional index path, in the case of list values +# +# Returns: +# The Provenance of the dict, member or list element +# +def yaml_file_get_provenance(path, shortname, key=None, indices=None): + with open(path) as data: + element_yaml = _yaml.load_data( + data, + _yaml.ProvenanceFile(path, shortname, project=None), + ) + provenance = _yaml.node_get_provenance(element_yaml, key, indices) + assert provenance is not None + return provenance |