summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-28 16:42:55 +0900
committerTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-28 17:49:41 +0900
commit1d2dc78a16aaab306598cfdc62ab0f24c3dc704e (patch)
treed673226ba1f718b4b24e7a79c5e7cb06b3e7c691
parent487f66073c61c038e663b1f149a4f9d6e465cb9f (diff)
downloadbuildstream-1d2dc78a16aaab306598cfdc62ab0f24c3dc704e.tar.gz
tests/internals/context.py: Test correct config file is chosen.
-rw-r--r--tests/internals/context.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/internals/context.py b/tests/internals/context.py
index a8b9f6dd3..9d06a68bf 100644
--- a/tests/internals/context.py
+++ b/tests/internals/context.py
@@ -5,6 +5,7 @@ import os
import pytest
from buildstream._context import Context
+from buildstream import _yaml, utils
from buildstream._exceptions import LoadError
from buildstream.exceptions import LoadErrorReason
@@ -80,6 +81,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.roundtrip_dump(bst_conf, bst_conf_path)
+
+ # The version specific config file
+ major_version, _ = utils._get_bst_api_version()
+ bst_conf_path = os.path.join(confdir, "buildstream{}.conf".format(major_version))
+ bst_conf = {"sourcedir": "/other_sources"}
+ _yaml.roundtrip_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
+ with Context() as context:
+ context.load()
+ assert context.sourcedir == "/other_sources"
+
+ del os.environ["XDG_CONFIG_HOME"]
+
+
#######################################
# Test failure modes #
#######################################