summaryrefslogtreecommitdiff
path: root/tests/plugins/loading.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugins/loading.py')
-rw-r--r--tests/plugins/loading.py110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/plugins/loading.py b/tests/plugins/loading.py
new file mode 100644
index 000000000..1c8a321d5
--- /dev/null
+++ b/tests/plugins/loading.py
@@ -0,0 +1,110 @@
+# 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 buildstream.testing import cli # pylint: disable=unused-import
+from buildstream import _yaml
+
+
+DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "loading")
+
+
+def update_project(project_path, updated_configuration):
+ project_conf_path = os.path.join(project_path, "project.conf")
+ project_conf = _yaml.roundtrip_load(project_conf_path)
+
+ project_conf.update(updated_configuration)
+
+ _yaml.roundtrip_dump(project_conf, project_conf_path)
+
+
+# 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_dir = os.path.join(project_path, "elements")
+ element_path = os.path.join(element_dir, "element.bst")
+ os.makedirs(element_dir, exist_ok=True)
+
+ if plugin_type == "elements":
+ element = {"kind": plugin_name}
+ else:
+ element = {"kind": "manual", "sources": [{"kind": plugin_name}]}
+
+ _yaml.roundtrip_dump(element, element_path)
+
+
+####################################################
+# Tests #
+####################################################
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("plugin_type", [("elements"), ("sources")])
+def test_nosetup(cli, datafiles, plugin_type):
+ project = str(datafiles)
+
+ update_project(project, {"plugins": [{"origin": "local", "path": "plugins/nosetup", plugin_type: ["nosetup"]}]})
+ setup_element(project, plugin_type, "nosetup")
+
+ result = cli.run(project=project, args=["show", "element.bst"])
+ result.assert_main_error(ErrorDomain.PLUGIN, "missing-setup-function")
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("plugin_type", [("elements"), ("sources")])
+def test_setup_not_function(cli, datafiles, plugin_type):
+ project = str(datafiles)
+
+ update_project(
+ project,
+ {"plugins": [{"origin": "local", "path": "plugins/setupnotfunction", plugin_type: ["setupnotfunction"]}]},
+ )
+ setup_element(project, plugin_type, "setupnotfunction")
+
+ result = cli.run(project=project, args=["show", "element.bst"])
+ result.assert_main_error(ErrorDomain.PLUGIN, "setup-is-not-function")
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("plugin_type", [("elements"), ("sources")])
+def test_setup_returns_not_type(cli, datafiles, plugin_type):
+ project = str(datafiles)
+
+ update_project(
+ project,
+ {
+ "plugins": [
+ {"origin": "local", "path": "plugins/setupreturnsnottype", plugin_type: ["setupreturnsnottype"]}
+ ]
+ },
+ )
+ setup_element(project, plugin_type, "setupreturnsnottype")
+
+ result = cli.run(project=project, args=["show", "element.bst"])
+ result.assert_main_error(ErrorDomain.PLUGIN, "setup-returns-not-type")
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("plugin_type", [("elements"), ("sources")])
+def test_setup_returns_bad_type(cli, datafiles, plugin_type):
+ project = str(datafiles)
+
+ update_project(
+ project,
+ {
+ "plugins": [
+ {"origin": "local", "path": "plugins/setupreturnsbadtype", plugin_type: ["setupreturnsbadtype"]}
+ ]
+ },
+ )
+ setup_element(project, plugin_type, "setupreturnsbadtype")
+
+ result = cli.run(project=project, args=["show", "element.bst"])
+ result.assert_main_error(ErrorDomain.PLUGIN, "setup-returns-bad-type")