summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLachlan Mackenzie <lachlan.mackenzie@codethink.co.uk>2018-10-05 17:32:40 +0100
committerJonathan Maw <jonathan.maw@codethink.co.uk>2018-10-15 15:54:59 +0000
commit26dfa882a4b9b5106a729c9e0782a4505226b355 (patch)
tree4414c1dd99d69e2d09f02086df268df8f69a249e
parentf4eb685a63239e20b0c2d8fee32d6da54906df86 (diff)
downloadbuildstream-26dfa882a4b9b5106a729c9e0782a4505226b355.tar.gz
yaml.py: Add loader for yaml test files cache option
* Fix to CWD issue provided by Jonathan Maw
-rw-r--r--tests/yaml/yaml.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/yaml/yaml.py b/tests/yaml/yaml.py
index 781763717..70a8310c0 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,21 @@ 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=os.path.join(cache_path.dirname, cache_path.basename), text=True)
+ context = Context()
+
+ with YamlCache.open(context, temppath) as yc:
+ if from_cache == 'raw':
+ return _yaml.load(filename, shortname)
+ elif from_cache == 'cached':
+ _yaml.load(filename, shortname, yaml_cache=yc)
+ 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