diff options
author | Lachlan Mackenzie <lachlan.mackenzie@codethink.co.uk> | 2018-10-05 17:32:40 +0100 |
---|---|---|
committer | Lachlan Mackenzie <lachlan.mackenzie@codethink.co.uk> | 2018-10-05 17:39:11 +0100 |
commit | ae5b554b5762cd29e5818da155721f37a869447d (patch) | |
tree | a5637910adee734f67f81d79507def8293229c02 | |
parent | 030935ff42dbc3be1b17b4c65ce343e56b3a88fc (diff) | |
download | buildstream-ae5b554b5762cd29e5818da155721f37a869447d.tar.gz |
Add loader for yaml test files cache option
-rw-r--r-- | tests/yaml/yaml.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/yaml/yaml.py b/tests/yaml/yaml.py index 781763717..7e00f08b4 100644 --- a/tests/yaml/yaml.py +++ b/tests/yaml/yaml.py @@ -1,5 +1,6 @@ import os import pytest +import tempfile from collections import Mapping from buildstream import _yaml @@ -150,6 +151,22 @@ def test_composite_preserve_originals(datafiles): assert(_yaml.node_get(orig_extra, str, 'old') == 'new') +def load_yaml_file(filename, *, cache_path, shortname=None, from_cache='raw'): + + temppath = tempfile.mkstemp(dir=str(cache_path), text=True) + context = Context() + + with YamlCache.open(context, str(temppath)) as yc: + if from_cache == 'raw': + return _yaml.load(filename, shortname) + elif from_cache == 'cached': + _yaml.load(filename, shortname) + + return _yaml.load(filename, shortname, yaml_cache=yc) + else: + assert False + + # Tests for list composition # # Each test composits a filename on top of basics.yaml, and tests |