diff options
-rw-r--r-- | tests/context/context.py | 28 |
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 # ####################################### |