From e13275bdd92aae182d7e93f5b916c4fc4fd280f8 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Wed, 29 Apr 2020 16:22:43 +0900 Subject: tests/plugins/loading.py: Migrate tests for found/not found plugins This new test replaces the test in tests/format/project.py. --- tests/format/project.py | 14 ---------- tests/format/project/plugin-allowed/__init__.py | 0 tests/format/project/plugin-allowed/element.bst | 1 - .../project/plugin-allowed/plugins/__init__.py | 0 tests/format/project/plugin-allowed/plugins/foo.py | 19 ------------- tests/format/project/plugin-allowed/project.conf | 8 ------ tests/format/project/plugin-forbidden/__init__.py | 0 tests/format/project/plugin-forbidden/element.bst | 1 - .../plugin-forbidden/forbidden-plugins/__init__.py | 0 .../forbidden-plugins/forbidden-plugin.py | 19 ------------- tests/format/project/plugin-forbidden/project.conf | 3 -- tests/plugins/loading.py | 30 ++++++++++++++++++++ .../loading/plugins/elements/found/found.py | 19 +++++++++++++ .../plugins/loading/plugins/sources/found/found.py | 32 ++++++++++++++++++++++ 14 files changed, 81 insertions(+), 65 deletions(-) delete mode 100644 tests/format/project/plugin-allowed/__init__.py delete mode 100644 tests/format/project/plugin-allowed/element.bst delete mode 100644 tests/format/project/plugin-allowed/plugins/__init__.py delete mode 100644 tests/format/project/plugin-allowed/plugins/foo.py delete mode 100644 tests/format/project/plugin-allowed/project.conf delete mode 100644 tests/format/project/plugin-forbidden/__init__.py delete mode 100644 tests/format/project/plugin-forbidden/element.bst delete mode 100644 tests/format/project/plugin-forbidden/forbidden-plugins/__init__.py delete mode 100644 tests/format/project/plugin-forbidden/forbidden-plugins/forbidden-plugin.py delete mode 100644 tests/format/project/plugin-forbidden/project.conf create mode 100644 tests/plugins/loading/plugins/elements/found/found.py create mode 100644 tests/plugins/loading/plugins/sources/found/found.py diff --git a/tests/format/project.py b/tests/format/project.py index 32c5d81e5..d3de67222 100644 --- a/tests/format/project.py +++ b/tests/format/project.py @@ -152,20 +152,6 @@ def test_local_plugin_not_directory(cli, datafiles): result.assert_success() -@pytest.mark.datafiles(DATA_DIR) -def test_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"]) - result.assert_success() - - -@pytest.mark.datafiles(DATA_DIR) -def test_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"]) - result.assert_main_error(ErrorDomain.PLUGIN, "plugin-not-found") - - @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("ref_storage", [("inline"), ("project.refs")]) def test_plugin_no_load_ref(cli, datafiles, ref_storage): diff --git a/tests/format/project/plugin-allowed/__init__.py b/tests/format/project/plugin-allowed/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/format/project/plugin-allowed/element.bst b/tests/format/project/plugin-allowed/element.bst deleted file mode 100644 index 675938bec..000000000 --- a/tests/format/project/plugin-allowed/element.bst +++ /dev/null @@ -1 +0,0 @@ -kind: foo diff --git a/tests/format/project/plugin-allowed/plugins/__init__.py b/tests/format/project/plugin-allowed/plugins/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/format/project/plugin-allowed/plugins/foo.py b/tests/format/project/plugin-allowed/plugins/foo.py deleted file mode 100644 index 76d9bfd3c..000000000 --- a/tests/format/project/plugin-allowed/plugins/foo.py +++ /dev/null @@ -1,19 +0,0 @@ -from buildstream import Element - - -class FooElement(Element): - - BST_MIN_VERSION = "2.0" - - 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 deleted file mode 100644 index 97107edf6..000000000 --- a/tests/format/project/plugin-allowed/project.conf +++ /dev/null @@ -1,8 +0,0 @@ -name: test -min-version: 2.0 - -plugins: -- origin: local - path: plugins - elements: - - foo diff --git a/tests/format/project/plugin-forbidden/__init__.py b/tests/format/project/plugin-forbidden/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/format/project/plugin-forbidden/element.bst b/tests/format/project/plugin-forbidden/element.bst deleted file mode 100644 index c8d51318c..000000000 --- a/tests/format/project/plugin-forbidden/element.bst +++ /dev/null @@ -1 +0,0 @@ -kind: bar diff --git a/tests/format/project/plugin-forbidden/forbidden-plugins/__init__.py b/tests/format/project/plugin-forbidden/forbidden-plugins/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/format/project/plugin-forbidden/forbidden-plugins/forbidden-plugin.py b/tests/format/project/plugin-forbidden/forbidden-plugins/forbidden-plugin.py deleted file mode 100644 index 76d9bfd3c..000000000 --- a/tests/format/project/plugin-forbidden/forbidden-plugins/forbidden-plugin.py +++ /dev/null @@ -1,19 +0,0 @@ -from buildstream import Element - - -class FooElement(Element): - - BST_MIN_VERSION = "2.0" - - 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 deleted file mode 100644 index 0211b2061..000000000 --- a/tests/format/project/plugin-forbidden/project.conf +++ /dev/null @@ -1,3 +0,0 @@ -name: test -min-version: 2.0 - diff --git a/tests/plugins/loading.py b/tests/plugins/loading.py index a368e9952..a54df776e 100644 --- a/tests/plugins/loading.py +++ b/tests/plugins/loading.py @@ -200,3 +200,33 @@ def test_incompatible_minor_version(cli, datafiles, plugin_type): result = cli.run(project=project, args=["show", "element.bst"]) result.assert_main_error(ErrorDomain.PLUGIN, "incompatible-minor-version") + + +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("plugin_type", [("elements"), ("sources")]) +def test_plugin_not_found(cli, datafiles, plugin_type): + project = str(datafiles) + + setup_element(project, plugin_type, "notfound") + + result = cli.run(project=project, args=["show", "element.bst"]) + result.assert_main_error(ErrorDomain.PLUGIN, "plugin-not-found") + + +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("plugin_type", [("elements"), ("sources")]) +def test_plugin_found(cli, datafiles, plugin_type): + project = str(datafiles) + + update_project( + project, + { + "plugins": [ + {"origin": "local", "path": os.path.join("plugins", plugin_type, "found"), plugin_type: ["found"],} + ] + }, + ) + setup_element(project, plugin_type, "found") + + result = cli.run(project=project, args=["show", "element.bst"]) + result.assert_success() diff --git a/tests/plugins/loading/plugins/elements/found/found.py b/tests/plugins/loading/plugins/elements/found/found.py new file mode 100644 index 000000000..34a7e4398 --- /dev/null +++ b/tests/plugins/loading/plugins/elements/found/found.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/loading/plugins/sources/found/found.py b/tests/plugins/loading/plugins/sources/found/found.py new file mode 100644 index 000000000..4ab40f005 --- /dev/null +++ b/tests/plugins/loading/plugins/sources/found/found.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 -- cgit v1.2.1