diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-04-24 18:12:54 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-04-29 16:24:58 +0900 |
commit | d63bd7e9def528d3ed59a2798452ac1da58ebea4 (patch) | |
tree | 05153205e2d5fa8644af7d877319a3cbc0566b68 /tests/internals | |
parent | 82eb1d4271bb634f248bc9e1770119d2815d7cd6 (diff) | |
download | buildstream-d63bd7e9def528d3ed59a2798452ac1da58ebea4.tar.gz |
Plugin loading refactor, removing all versioning
Plugin format versioning was decided to be removed for local
plugins and any plugins for which we do not load an explicitly
provided plugin. For pip, this will be handled with a standard
distutils/setuptools approach, allowing users to specify pip
style version boundaries in the plugin origins.
This patch refactors plugin loading so that all related code
goes into the private _pluginfactory module, a new small
PluginOrigin type was added to better manipulate loaded
origins.
Test cases have been removed and will be readded in a following
commit, adjusted to new expectations.
Diffstat (limited to 'tests/internals')
32 files changed, 2 insertions, 466 deletions
diff --git a/tests/internals/pluginfactory.py b/tests/internals/pluginfactory.py deleted file mode 100644 index 13b9d3aae..000000000 --- a/tests/internals/pluginfactory.py +++ /dev/null @@ -1,287 +0,0 @@ -# Pylint doesn't play well with fixtures and dependency injection from pytest -# pylint: disable=redefined-outer-name - -import os -import pytest - -from pluginbase import PluginBase -from buildstream import Node -from buildstream._elementfactory import ElementFactory -from buildstream._sourcefactory import SourceFactory -from buildstream._exceptions import PluginError - -DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "pluginfactory",) - - -# Simple fixture to create a PluginBase object that -# we use for loading plugins. -@pytest.fixture() -def plugin_fixture(): - return {"base": PluginBase(package="buildstream.plugins")} - - -############################################################## -# Basics: test the fixture, test we can create the factories # -############################################################## -def test_fixture(plugin_fixture): - assert isinstance(plugin_fixture["base"], PluginBase) - - -def test_source_factory(plugin_fixture): - factory = SourceFactory(plugin_fixture["base"]) - assert isinstance(factory, SourceFactory) - - -def test_element_factory(plugin_fixture): - factory = ElementFactory(plugin_fixture["base"]) - assert isinstance(factory, ElementFactory) - - -############################################################## -# Check that we can load custom sources & elements # -############################################################## -@pytest.mark.datafiles(os.path.join(DATA_DIR, "customsource")) -def test_custom_source(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = SourceFactory(plugin_fixture["base"], plugin_origins=plugins) - assert isinstance(factory, SourceFactory) - - foo_type, _ = factory.lookup("foo") - assert foo_type.__name__ == "FooSource" - - -@pytest.mark.datafiles(os.path.join(DATA_DIR, "customelement")) -def test_custom_element(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = ElementFactory(plugin_fixture["base"], plugin_origins=plugins) - assert isinstance(factory, ElementFactory) - - foo_type, _ = factory.lookup("foo") - assert foo_type.__name__ == "FooElement" - - -############################################################## -# Check plugin loading failure modes # -############################################################## -def test_missing_source(plugin_fixture): - factory = SourceFactory(plugin_fixture["base"]) - assert isinstance(factory, SourceFactory) - - # Test fails if PluginError is not raised - with pytest.raises(PluginError): - factory.lookup("foo") - - -def test_missing_element(plugin_fixture): - factory = ElementFactory(plugin_fixture["base"]) - assert isinstance(factory, ElementFactory) - - # Test fails if PluginError is not raised - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin that returns a value instead of Source subclass -@pytest.mark.datafiles(os.path.join(DATA_DIR, "notatype")) -def test_source_notatype(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = SourceFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin that returns a value instead of Element subclass -@pytest.mark.datafiles(os.path.join(DATA_DIR, "notatype")) -def test_element_notatype(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = ElementFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin that returns a type -# which is not a Source subclass -@pytest.mark.datafiles(os.path.join(DATA_DIR, "wrongtype")) -def test_source_wrongtype(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = SourceFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin that returns a type -# which is not a Element subclass -@pytest.mark.datafiles(os.path.join(DATA_DIR, "wrongtype")) -def test_element_wrongtype(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = ElementFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin which fails to provide a setup() function -@pytest.mark.datafiles(os.path.join(DATA_DIR, "nosetup")) -def test_source_missing_setup(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = SourceFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin which fails to provide a setup() function -@pytest.mark.datafiles(os.path.join(DATA_DIR, "nosetup")) -def test_element_missing_setup(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = ElementFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin which provides a setup symbol -# that is not a function -@pytest.mark.datafiles(os.path.join(DATA_DIR, "badsetup")) -def test_source_bad_setup(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = SourceFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin which provides a setup symbol -# that is not a function -@pytest.mark.datafiles(os.path.join(DATA_DIR, "badsetup")) -def test_element_bad_setup(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = ElementFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin which requires an absurdly -# high version of buildstream -@pytest.mark.datafiles(os.path.join(DATA_DIR, "badversionsource")) -def test_source_badversion(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = SourceFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -# Load a factory with a plugin which requires an absurdly -# high version of buildstream -@pytest.mark.datafiles(os.path.join(DATA_DIR, "badversionelement")) -def test_element_badversion(plugin_fixture, datafiles): - plugins = [ - Node.from_dict( - {"origin": "local", "path": os.path.join(datafiles.dirname, datafiles.basename), "plugins": ["foo"]} - ) - ] - factory = ElementFactory(plugin_fixture["base"], plugin_origins=plugins) - with pytest.raises(PluginError): - factory.lookup("foo") - - -############################################################## -# Check we can load different contexts of plugin # -############################################################## - -# Load two factories, both of which define a different 'foo' plugin -@pytest.mark.datafiles(DATA_DIR) -def test_source_multicontext(plugin_fixture, datafiles): - plugins1 = Node.from_dict( - { - "origin": "local", - "path": os.path.join(datafiles.dirname, datafiles.basename, "customsource"), - "plugins": ["foo"], - } - ) - plugins2 = Node.from_dict( - { - "origin": "local", - "path": os.path.join(datafiles.dirname, datafiles.basename, "anothersource"), - "plugins": ["foo"], - } - ) - - factory1 = SourceFactory(plugin_fixture["base"], plugin_origins=[plugins1]) - factory2 = SourceFactory(plugin_fixture["base"], plugin_origins=[plugins2]) - assert isinstance(factory1, SourceFactory) - assert isinstance(factory2, SourceFactory) - - foo_type1, _ = factory1.lookup("foo") - foo_type2, _ = factory2.lookup("foo") - assert foo_type1.__name__ == "FooSource" - assert foo_type2.__name__ == "AnotherFooSource" - - -# Load two factories, both of which define a different 'foo' plugin -@pytest.mark.datafiles(DATA_DIR) -def test_element_multicontext(plugin_fixture, datafiles): - plugins1 = Node.from_dict( - { - "origin": "local", - "path": os.path.join(datafiles.dirname, datafiles.basename, "customelement"), - "plugins": ["foo"], - } - ) - plugins2 = Node.from_dict( - { - "origin": "local", - "path": os.path.join(datafiles.dirname, datafiles.basename, "anotherelement"), - "plugins": ["foo"], - } - ) - - factory1 = ElementFactory(plugin_fixture["base"], plugin_origins=[plugins1]) - factory2 = ElementFactory(plugin_fixture["base"], plugin_origins=[plugins2]) - assert isinstance(factory1, ElementFactory) - assert isinstance(factory2, ElementFactory) - - foo_type1, _ = factory1.lookup("foo") - foo_type2, _ = factory2.lookup("foo") - assert foo_type1.__name__ == "FooElement" - assert foo_type2.__name__ == "AnotherFooElement" diff --git a/tests/internals/pluginfactory/anotherelement/__init__.py b/tests/internals/pluginfactory/anotherelement/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/anotherelement/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/anotherelement/foo.py b/tests/internals/pluginfactory/anotherelement/foo.py deleted file mode 100644 index 2e067a94f..000000000 --- a/tests/internals/pluginfactory/anotherelement/foo.py +++ /dev/null @@ -1,9 +0,0 @@ -from buildstream import Element - - -class AnotherFooElement(Element): - pass - - -def setup(): - return AnotherFooElement diff --git a/tests/internals/pluginfactory/anothersource/__init__.py b/tests/internals/pluginfactory/anothersource/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/anothersource/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/anothersource/foo.py b/tests/internals/pluginfactory/anothersource/foo.py deleted file mode 100644 index 4675b965f..000000000 --- a/tests/internals/pluginfactory/anothersource/foo.py +++ /dev/null @@ -1,9 +0,0 @@ -from buildstream import Source - - -class AnotherFooSource(Source): - pass - - -def setup(): - return AnotherFooSource diff --git a/tests/internals/pluginfactory/badsetup/__init__.py b/tests/internals/pluginfactory/badsetup/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/badsetup/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/badsetup/foo.py b/tests/internals/pluginfactory/badsetup/foo.py deleted file mode 100644 index 145f2577b..000000000 --- a/tests/internals/pluginfactory/badsetup/foo.py +++ /dev/null @@ -1,6 +0,0 @@ -# A plugin is supposed to define a setup function -# which returns the type that the plugin provides -# -# This plugin provides a setup() symbol that is -# not even a function -setup = 5 diff --git a/tests/internals/pluginfactory/badversionelement/__init__.py b/tests/internals/pluginfactory/badversionelement/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/badversionelement/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/badversionelement/foo.py b/tests/internals/pluginfactory/badversionelement/foo.py deleted file mode 100644 index 2a8b12abe..000000000 --- a/tests/internals/pluginfactory/badversionelement/foo.py +++ /dev/null @@ -1,11 +0,0 @@ -from buildstream import Element - - -class FooElement(Element): - - # We have a little while until we have to manually modify this - BST_REQUIRED_VERSION_MAJOR = 5000 - - -def setup(): - return FooElement diff --git a/tests/internals/pluginfactory/badversionsource/__init__.py b/tests/internals/pluginfactory/badversionsource/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/badversionsource/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/badversionsource/foo.py b/tests/internals/pluginfactory/badversionsource/foo.py deleted file mode 100644 index 23333a9d8..000000000 --- a/tests/internals/pluginfactory/badversionsource/foo.py +++ /dev/null @@ -1,11 +0,0 @@ -from buildstream import Source - - -class FooSource(Source): - - # We have a little while until we have to manually modify this - BST_REQUIRED_VERSION_MAJOR = 5000 - - -def setup(): - return FooSource diff --git a/tests/internals/pluginfactory/customelement/__init__.py b/tests/internals/pluginfactory/customelement/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/customelement/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/customelement/foo.py b/tests/internals/pluginfactory/customelement/foo.py deleted file mode 100644 index 260de8b27..000000000 --- a/tests/internals/pluginfactory/customelement/foo.py +++ /dev/null @@ -1,9 +0,0 @@ -from buildstream import Element - - -class FooElement(Element): - pass - - -def setup(): - return FooElement diff --git a/tests/internals/pluginfactory/customsource/__init__.py b/tests/internals/pluginfactory/customsource/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/customsource/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/customsource/foo.py b/tests/internals/pluginfactory/customsource/foo.py deleted file mode 100644 index de78a00ce..000000000 --- a/tests/internals/pluginfactory/customsource/foo.py +++ /dev/null @@ -1,9 +0,0 @@ -from buildstream import Source - - -class FooSource(Source): - pass - - -def setup(): - return FooSource diff --git a/tests/internals/pluginfactory/nosetup/__init__.py b/tests/internals/pluginfactory/nosetup/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/nosetup/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/nosetup/foo.py b/tests/internals/pluginfactory/nosetup/foo.py deleted file mode 100644 index 0b5a4fa7e..000000000 --- a/tests/internals/pluginfactory/nosetup/foo.py +++ /dev/null @@ -1,8 +0,0 @@ -# A plugin is supposed to define a setup function -# which returns the type that the plugin provides -# -# This plugin fails to do so - - -def useless(): - print("Hello World") diff --git a/tests/internals/pluginfactory/notatype/__init__.py b/tests/internals/pluginfactory/notatype/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/notatype/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/notatype/foo.py b/tests/internals/pluginfactory/notatype/foo.py deleted file mode 100644 index 311a4fb32..000000000 --- a/tests/internals/pluginfactory/notatype/foo.py +++ /dev/null @@ -1,6 +0,0 @@ -# Plugins are supposed to return a subclass type -# of Source or Element, depending on plugin type. - - -def setup(): - return 5 diff --git a/tests/internals/pluginfactory/wrongtype/__init__.py b/tests/internals/pluginfactory/wrongtype/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginfactory/wrongtype/__init__.py +++ /dev/null diff --git a/tests/internals/pluginfactory/wrongtype/foo.py b/tests/internals/pluginfactory/wrongtype/foo.py deleted file mode 100644 index 37d9f6bfe..000000000 --- a/tests/internals/pluginfactory/wrongtype/foo.py +++ /dev/null @@ -1,12 +0,0 @@ -# Plugins are supposed to return a subclass type -# of Source or Element, depending on plugin type. -# -# This one fails the requirement - - -class Foo: - pass - - -def setup(): - return Foo diff --git a/tests/internals/pluginloading.py b/tests/internals/pluginloading.py index 0685b09da..1f4446541 100644 --- a/tests/internals/pluginloading.py +++ b/tests/internals/pluginloading.py @@ -3,8 +3,6 @@ import os import pytest from buildstream._project import Project -from buildstream._exceptions import LoadError -from buildstream.exceptions import LoadErrorReason from buildstream._pipeline import Pipeline from tests.testutils import dummy_context @@ -38,23 +36,3 @@ def test_customelement(datafiles, tmpdir): basedir = str(datafiles) with create_pipeline(tmpdir, basedir, "simple.bst") as targets: assert targets[0].get_kind() == "foo" - - -@pytest.mark.datafiles(os.path.join(DATA_DIR, "badversionsource")) -def test_badversionsource(datafiles, tmpdir): - basedir = str(datafiles) - - with pytest.raises(LoadError) as exc, create_pipeline(tmpdir, basedir, "simple.bst"): - pass - - assert exc.value.reason == LoadErrorReason.UNSUPPORTED_PLUGIN - - -@pytest.mark.datafiles(os.path.join(DATA_DIR, "badversionelement")) -def test_badversionelement(datafiles, tmpdir): - basedir = str(datafiles) - - with pytest.raises(LoadError) as exc, create_pipeline(tmpdir, basedir, "simple.bst"): - pass - - assert exc.value.reason == LoadErrorReason.UNSUPPORTED_PLUGIN diff --git a/tests/internals/pluginloading/badversionelement/customelements/__init__.py b/tests/internals/pluginloading/badversionelement/customelements/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginloading/badversionelement/customelements/__init__.py +++ /dev/null diff --git a/tests/internals/pluginloading/badversionelement/customelements/foo.py b/tests/internals/pluginloading/badversionelement/customelements/foo.py deleted file mode 100644 index 75536e87f..000000000 --- a/tests/internals/pluginloading/badversionelement/customelements/foo.py +++ /dev/null @@ -1,19 +0,0 @@ -from buildstream import Element - - -class FooElement(Element): - - BST_FORMAT_VERSION = 5 - - def preflight(self): - pass - - def configure(self, node): - pass - - def get_unique_key(self): - return {} - - -def setup(): - return FooElement diff --git a/tests/internals/pluginloading/badversionelement/elements/simple.bst b/tests/internals/pluginloading/badversionelement/elements/simple.bst deleted file mode 100644 index f949dc5b5..000000000 --- a/tests/internals/pluginloading/badversionelement/elements/simple.bst +++ /dev/null @@ -1,4 +0,0 @@ -kind: foo -description: Custom foo element -config: - some: thing diff --git a/tests/internals/pluginloading/badversionelement/project.conf b/tests/internals/pluginloading/badversionelement/project.conf deleted file mode 100644 index bff73e251..000000000 --- a/tests/internals/pluginloading/badversionelement/project.conf +++ /dev/null @@ -1,10 +0,0 @@ -name: pony -min-version: 2.0 -element-path: elements - -plugins: -- origin: local - path: customelements - elements: - # We provided bar at version 5, should be a conflict. - foo: 10 diff --git a/tests/internals/pluginloading/badversionsource/customsources/__init__.py b/tests/internals/pluginloading/badversionsource/customsources/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/internals/pluginloading/badversionsource/customsources/__init__.py +++ /dev/null diff --git a/tests/internals/pluginloading/badversionsource/customsources/foo.py b/tests/internals/pluginloading/badversionsource/customsources/foo.py deleted file mode 100644 index 628f99b29..000000000 --- a/tests/internals/pluginloading/badversionsource/customsources/foo.py +++ /dev/null @@ -1,16 +0,0 @@ -from buildstream import Source - - -class BarSource(Source): - - BST_FORMAT_VERSION = 5 - - def preflight(self): - pass - - def configure(self, node): - pass - - -def setup(): - return BarSource diff --git a/tests/internals/pluginloading/badversionsource/elements/simple.bst b/tests/internals/pluginloading/badversionsource/elements/simple.bst deleted file mode 100644 index 7e0cc43b7..000000000 --- a/tests/internals/pluginloading/badversionsource/elements/simple.bst +++ /dev/null @@ -1,6 +0,0 @@ -kind: autotools -description: Custom foo source -sources: -- kind: foo - ref: 1.2.3 - uri: http://ponyland.com diff --git a/tests/internals/pluginloading/badversionsource/project.conf b/tests/internals/pluginloading/badversionsource/project.conf deleted file mode 100644 index cd5b2dc82..000000000 --- a/tests/internals/pluginloading/badversionsource/project.conf +++ /dev/null @@ -1,10 +0,0 @@ -name: pony -min-version: 2.0 -element-path: elements - -plugins: -- origin: local - path: customsources - sources: - # We provided bar at version 5, should be a conflict. - foo: 10 diff --git a/tests/internals/pluginloading/customelement/project.conf b/tests/internals/pluginloading/customelement/project.conf index 6a33cc504..2619bdf82 100644 --- a/tests/internals/pluginloading/customelement/project.conf +++ b/tests/internals/pluginloading/customelement/project.conf @@ -5,4 +5,4 @@ plugins: - origin: local path: pluginelements elements: - foo: 0 + - foo diff --git a/tests/internals/pluginloading/customsource/project.conf b/tests/internals/pluginloading/customsource/project.conf index 87d9b5d09..5cb6da537 100644 --- a/tests/internals/pluginloading/customsource/project.conf +++ b/tests/internals/pluginloading/customsource/project.conf @@ -5,4 +5,4 @@ plugins: - origin: local path: pluginsources sources: - foo: 0 + - foo |