diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2017-11-30 17:54:43 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-12-13 13:17:28 -0500 |
commit | 3033f55d06aee5634802888aeebd3a7d0bd56e37 (patch) | |
tree | 87e043aa47cf9c36630b8d6ca175aade80278030 /tests/format | |
parent | 1171e1fb871e82292fad22830b62b69ab388ea07 (diff) | |
download | buildstream-3033f55d06aee5634802888aeebd3a7d0bd56e37.tar.gz |
tests: Test whether a plugin is allowed to be loadedfix-132-rebased
Diffstat (limited to 'tests/format')
11 files changed, 62 insertions, 1 deletions
diff --git a/tests/format/project.py b/tests/format/project.py index 5b6c474ee..e06e842e5 100644 --- a/tests/format/project.py +++ b/tests/format/project.py @@ -1,7 +1,7 @@ import os import pytest from buildstream import _yaml -from buildstream._exceptions import LoadError, LoadErrorReason +from buildstream._exceptions import LoadError, LoadErrorReason, PluginError from tests.testutils.runcli import cli @@ -13,6 +13,24 @@ DATA_DIR = os.path.join( @pytest.mark.datafiles(DATA_DIR) +def test_project_plugin_load_allowed(cli, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename, 'plugin-allowed') + result = cli.run(project=project, silent=True, args=[ + 'show', 'element.bst']) + assert result.exit_code == 0 + + +@pytest.mark.datafiles(DATA_DIR) +def test_project_plugin_load_forbidden(cli, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename, 'plugin-forbidden') + result = cli.run(project=project, silent=True, args=[ + 'show', 'element.bst']) + assert result.exit_code != 0 + assert result.exception + assert isinstance(result.exception, PluginError) + + +@pytest.mark.datafiles(DATA_DIR) def test_project_conf_duplicate_plugins(cli, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename, 'duplicate-plugins') result = cli.run(project=project, silent=True, args=[ diff --git a/tests/format/project/plugin-allowed/__init__.py b/tests/format/project/plugin-allowed/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/format/project/plugin-allowed/__init__.py diff --git a/tests/format/project/plugin-allowed/element.bst b/tests/format/project/plugin-allowed/element.bst new file mode 100644 index 000000000..675938bec --- /dev/null +++ b/tests/format/project/plugin-allowed/element.bst @@ -0,0 +1 @@ +kind: foo diff --git a/tests/format/project/plugin-allowed/plugins/__init__.py b/tests/format/project/plugin-allowed/plugins/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/format/project/plugin-allowed/plugins/__init__.py diff --git a/tests/format/project/plugin-allowed/plugins/foo.py b/tests/format/project/plugin-allowed/plugins/foo.py new file mode 100644 index 000000000..bf884233c --- /dev/null +++ b/tests/format/project/plugin-allowed/plugins/foo.py @@ -0,0 +1,16 @@ +from buildstream import Element + + +class FooElement(Element): + def configure(self, config): + pass + + def preflight(self): + pass + + def get_unique_key(self): + return "foo" + + +def setup(): + return FooElement diff --git a/tests/format/project/plugin-allowed/project.conf b/tests/format/project/plugin-allowed/project.conf new file mode 100644 index 000000000..d49e40d48 --- /dev/null +++ b/tests/format/project/plugin-allowed/project.conf @@ -0,0 +1,7 @@ +name: test + +plugins: +- origin: local + path: plugins + elements: + foo: 0 diff --git a/tests/format/project/plugin-forbidden/__init__.py b/tests/format/project/plugin-forbidden/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/format/project/plugin-forbidden/__init__.py diff --git a/tests/format/project/plugin-forbidden/element.bst b/tests/format/project/plugin-forbidden/element.bst new file mode 100644 index 000000000..c8d51318c --- /dev/null +++ b/tests/format/project/plugin-forbidden/element.bst @@ -0,0 +1 @@ +kind: bar diff --git a/tests/format/project/plugin-forbidden/forbidden-plugins/__init__.py b/tests/format/project/plugin-forbidden/forbidden-plugins/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/format/project/plugin-forbidden/forbidden-plugins/__init__.py diff --git a/tests/format/project/plugin-forbidden/forbidden-plugins/forbidden-plugin.py b/tests/format/project/plugin-forbidden/forbidden-plugins/forbidden-plugin.py new file mode 100644 index 000000000..bf884233c --- /dev/null +++ b/tests/format/project/plugin-forbidden/forbidden-plugins/forbidden-plugin.py @@ -0,0 +1,16 @@ +from buildstream import Element + + +class FooElement(Element): + def configure(self, config): + pass + + def preflight(self): + pass + + def get_unique_key(self): + return "foo" + + +def setup(): + return FooElement diff --git a/tests/format/project/plugin-forbidden/project.conf b/tests/format/project/plugin-forbidden/project.conf new file mode 100644 index 000000000..39cc3d65f --- /dev/null +++ b/tests/format/project/plugin-forbidden/project.conf @@ -0,0 +1,2 @@ +name: test + |