diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-05-12 18:24:11 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-05-12 18:56:16 +0900 |
commit | 496a42db9d3b8ee176718d07e9f1859a54644594 (patch) | |
tree | e7b683eca74fed8453c5a4001ac5e05c5fb747ea | |
parent | f4200ae4e79eaa7d563ad77a4917ee59f0b789ea (diff) | |
download | buildstream-496a42db9d3b8ee176718d07e9f1859a54644594.tar.gz |
tests/plugins/bst2.py: Testing error handling of loading wrong plugin versions.
-rw-r--r-- | setup.cfg | 2 | ||||
-rw-r--r-- | tests/plugins/bst2.py | 60 | ||||
-rw-r--r-- | tests/plugins/bst2/elements/bst2.py | 19 | ||||
-rw-r--r-- | tests/plugins/bst2/elements/malformed.py | 19 | ||||
-rw-r--r-- | tests/plugins/bst2/sources/bst2.py | 32 | ||||
-rw-r--r-- | tests/plugins/bst2/sources/malformed.py | 32 |
6 files changed, 163 insertions, 1 deletions
@@ -12,7 +12,7 @@ test=pytest [tool:pytest] addopts = --verbose --basetemp ./tmp --pep8 --pylint --pylint-rcfile=.pylintrc --durations=20 -norecursedirs = tests/integration/project integration-cache tmp __pycache__ .eggs +norecursedirs = tests/integration/project tests/plugins/bst2 integration-cache tmp __pycache__ .eggs python_files = tests/*/*.py pep8maxlinelength = 119 pep8ignore = diff --git a/tests/plugins/bst2.py b/tests/plugins/bst2.py new file mode 100644 index 000000000..ca7529dfc --- /dev/null +++ b/tests/plugins/bst2.py @@ -0,0 +1,60 @@ +# Pylint doesn't play well with fixtures and dependency injection from pytest +# pylint: disable=redefined-outer-name + +# +# This test case tests the failure modes of loading a plugin +# after it has already been discovered via it's origin. +# + +import os +import pytest + +from buildstream._exceptions import ErrorDomain +from tests.testutils import cli # pylint: disable=unused-import +from buildstream import _yaml + + +DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "bst2") + + +# Sets up the element.bst file so that it requires a source +# or element plugin. +# +def setup_element(project_path, plugin_type, plugin_name): + element_path = os.path.join(project_path, "element.bst") + + if plugin_type == "elements": + element = {"kind": plugin_name} + else: + element = {"kind": "manual", "sources": [{"kind": plugin_name}]} + + _yaml.dump(element, element_path) + + +#################################################### +# Tests # +#################################################### +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("plugin_type", ["elements", "sources"]) +@pytest.mark.parametrize("plugin", ["bst2", "malformed"]) +def test_plugin_bst2(cli, datafiles, plugin_type, plugin): + project = str(datafiles) + project_conf_path = os.path.join(project, "project.conf") + project_conf = { + "name": "test", + "plugins": [ + { + "origin": "local", + "path": plugin_type, + plugin_type: { + plugin: 0 + } + } + ] + } + _yaml.dump(project_conf, project_conf_path) + + setup_element(project, plugin_type, plugin) + + result = cli.run(project=project, args=["show", "element.bst"]) + result.assert_main_error(ErrorDomain.PLUGIN, "plugin-version-mismatch") diff --git a/tests/plugins/bst2/elements/bst2.py b/tests/plugins/bst2/elements/bst2.py new file mode 100644 index 000000000..34a7e4398 --- /dev/null +++ b/tests/plugins/bst2/elements/bst2.py @@ -0,0 +1,19 @@ +from buildstream import Element + + +class Found(Element): + BST_MIN_VERSION = "2.0" + + def configure(self, node): + pass + + def preflight(self): + pass + + def get_unique_key(self): + return {} + + +# Plugin entry point +def setup(): + return Found diff --git a/tests/plugins/bst2/elements/malformed.py b/tests/plugins/bst2/elements/malformed.py new file mode 100644 index 000000000..d3fe97a6a --- /dev/null +++ b/tests/plugins/bst2/elements/malformed.py @@ -0,0 +1,19 @@ +from buildstream import Element + + +class Found(Element): + BST_MIN_VERSION = 5 + + def configure(self, node): + pass + + def preflight(self): + pass + + def get_unique_key(self): + return {} + + +# Plugin entry point +def setup(): + return Found diff --git a/tests/plugins/bst2/sources/bst2.py b/tests/plugins/bst2/sources/bst2.py new file mode 100644 index 000000000..4ab40f005 --- /dev/null +++ b/tests/plugins/bst2/sources/bst2.py @@ -0,0 +1,32 @@ +from buildstream import Source + + +class Found(Source): + BST_MIN_VERSION = "2.0" + + def configure(self, node): + pass + + def preflight(self): + pass + + def get_unique_key(self): + return {} + + def load_ref(self, node): + pass + + def get_ref(self): + return {} + + def set_ref(self, ref, node): + pass + + def is_cached(self): + return False + + +# Plugin entry point +def setup(): + + return Found diff --git a/tests/plugins/bst2/sources/malformed.py b/tests/plugins/bst2/sources/malformed.py new file mode 100644 index 000000000..786e3d619 --- /dev/null +++ b/tests/plugins/bst2/sources/malformed.py @@ -0,0 +1,32 @@ +from buildstream import Source + + +class Found(Source): + BST_MIN_VERSION = "a pony" + + def configure(self, node): + pass + + def preflight(self): + pass + + def get_unique_key(self): + return {} + + def load_ref(self, node): + pass + + def get_ref(self): + return {} + + def set_ref(self, ref, node): + pass + + def is_cached(self): + return False + + +# Plugin entry point +def setup(): + + return Found |