summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-29 18:58:54 +0900
committerTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-29 18:58:54 +0900
commit16d6be452cacac08966a14c304351e4d21d07b22 (patch)
treeefee63dad87e9d9282aed018bd868513ba47bf44
parent5890fb7826f749f76c0d1fffcdd517724997df57 (diff)
downloadbuildstream-16d6be452cacac08966a14c304351e4d21d07b22.tar.gz
tests/context/context.py: Test correct config file is chosen.
-rw-r--r--tests/context/context.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/context/context.py b/tests/context/context.py
index 35428105b..f76a4f07b 100644
--- a/tests/context/context.py
+++ b/tests/context/context.py
@@ -3,6 +3,7 @@ import pytest
from buildstream._context import Context
from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream import _yaml
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
@@ -83,6 +84,33 @@ def test_context_load_user_config(context_fixture, datafiles):
assert(context.logdir == os.path.join(cache_home, 'buildstream', 'logs'))
+@pytest.mark.datafiles(os.path.join(DATA_DIR))
+def test_context_priority(datafiles):
+ confdir = os.path.join(str(datafiles), "config")
+ os.makedirs(confdir)
+
+ # The fallback (usual) config file
+ bst_conf_path = os.path.join(confdir, "buildstream.conf")
+ bst_conf = {"sourcedir": "/sources"}
+ _yaml.dump(bst_conf, bst_conf_path)
+
+ # The version specific config file
+ bst_conf_path = os.path.join(confdir, "buildstream1.conf")
+ bst_conf = {"sourcedir": "/other_sources"}
+ _yaml.dump(bst_conf, bst_conf_path)
+
+ # Load the Context() object and assert that we've chosen
+ # the version specific one.
+ #
+ os.environ["XDG_CONFIG_HOME"] = confdir
+ context = Context()
+ context.load()
+
+ assert context.sourcedir == "/other_sources"
+
+ del os.environ["XDG_CONFIG_HOME"]
+
+
#######################################
# Test failure modes #
#######################################