summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-28 16:42:55 +0900
committerbst-marge-bot <marge-bot@buildstream.build>2020-05-29 16:43:52 +0000
commite3de12e7a7c3e85278f484cec009f6d6f1b6e7d5 (patch)
treeed2af8ab1d4f32494e848ff36b38c0cc1b67dc13
parentf5c9a4ed5f9ebc579250c1a35aca77b0afb47e2d (diff)
downloadbuildstream-e3de12e7a7c3e85278f484cec009f6d6f1b6e7d5.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 #
#######################################