diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/context/__init__.py | 0 | ||||
-rw-r--r-- | tests/context/context.py | 23 | ||||
-rw-r--r-- | tests/context/data/invalidtype.yaml | 3 |
3 files changed, 25 insertions, 1 deletions
diff --git a/tests/context/__init__.py b/tests/context/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/context/__init__.py diff --git a/tests/context/context.py b/tests/context/context.py index a785b6628..ae4effad1 100644 --- a/tests/context/context.py +++ b/tests/context/context.py @@ -2,7 +2,7 @@ import os import pytest from buildstream import Context -from buildstream import LoadError +from buildstream import LoadError, LoadErrorReason DATA_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), @@ -73,6 +73,8 @@ def test_context_load_missing_config(context_fixture, datafiles): with pytest.raises(LoadError) as exc: context.load(conf_file) + assert (exc.value.reason == LoadErrorReason.MISSING_FILE) + @pytest.mark.datafiles(os.path.join(DATA_DIR)) def test_context_load_malformed_config(context_fixture, datafiles): context = context_fixture['context'] @@ -85,6 +87,8 @@ def test_context_load_malformed_config(context_fixture, datafiles): with pytest.raises(LoadError) as exc: context.load(conf_file) + assert (exc.value.reason == LoadErrorReason.INVALID_YAML) + @pytest.mark.datafiles(os.path.join(DATA_DIR)) def test_context_load_notdict_config(context_fixture, datafiles): context = context_fixture['context'] @@ -96,3 +100,20 @@ def test_context_load_notdict_config(context_fixture, datafiles): with pytest.raises(LoadError) as exc: context.load(conf_file) + + # XXX Should this be a different LoadErrorReason ? + assert (exc.value.reason == LoadErrorReason.INVALID_YAML) + +@pytest.mark.datafiles(os.path.join(DATA_DIR)) +def test_context_load_invalid_type(context_fixture, datafiles): + context = context_fixture['context'] + assert(isinstance(context, Context)) + + conf_file = os.path.join(datafiles.dirname, + datafiles.basename, + 'invalidtype.yaml') + + with pytest.raises(LoadError) as exc: + context.load(conf_file) + + assert (exc.value.reason == LoadErrorReason.ILLEGAL_COMPOSITE) diff --git a/tests/context/data/invalidtype.yaml b/tests/context/data/invalidtype.yaml new file mode 100644 index 000000000..3eb3200a8 --- /dev/null +++ b/tests/context/data/invalidtype.yaml @@ -0,0 +1,3 @@ +# Specify wrong value type for something + +sourcedir: 5 |