diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-01-11 17:27:14 -0500 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-01-16 18:35:21 -0500 |
commit | 99ea157ae4d22220ff3c529e12c19fe47369c4df (patch) | |
tree | 486bb971f3e4d59d9b9848e195c7bc9f10d4532d /tests/plugins | |
parent | 3324490e0669ba15a8b1d54051ff4b387e28b27a (diff) | |
download | buildstream-99ea157ae4d22220ff3c529e12c19fe47369c4df.tar.gz |
tests: Migrate plugin factory test to internals directory
Diffstat (limited to 'tests/plugins')
21 files changed, 0 insertions, 390 deletions
diff --git a/tests/plugins/basics.py b/tests/plugins/basics.py deleted file mode 100644 index 4c9cbafe4..000000000 --- a/tests/plugins/basics.py +++ /dev/null @@ -1,300 +0,0 @@ -import os -import pytest - -from pluginbase import PluginBase -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__)), - 'basics', -) - - -# 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - 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) as exc: - foo_type = 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) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = SourceFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = ElementFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = SourceFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = ElementFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = SourceFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = ElementFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = SourceFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = ElementFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = SourceFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = [{ - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename), - 'plugins': {'foo': 0} - }] - factory = ElementFactory(plugin_fixture['base'], plugin_origins=plugins) - with pytest.raises(PluginError) as exc: - foo_type = 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 = { - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename, - 'customsource'), - 'plugins': {'foo': 0} - } - plugins2 = { - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename, - 'anothersource'), - 'plugins': {'foo': 0} - } - - 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 = { - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename, - 'customelement'), - 'plugins': {'foo': 0} - } - plugins2 = { - 'origin': 'local', - 'path': os.path.join(datafiles.dirname, - datafiles.basename, - 'anotherelement'), - 'plugins': {'foo': 0} - } - - 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/plugins/basics/anotherelement/__init__.py b/tests/plugins/basics/anotherelement/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/anotherelement/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/anotherelement/foo.py b/tests/plugins/basics/anotherelement/foo.py deleted file mode 100644 index 2e067a94f..000000000 --- a/tests/plugins/basics/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/plugins/basics/anothersource/__init__.py b/tests/plugins/basics/anothersource/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/anothersource/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/anothersource/foo.py b/tests/plugins/basics/anothersource/foo.py deleted file mode 100644 index 4675b965f..000000000 --- a/tests/plugins/basics/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/plugins/basics/badsetup/__init__.py b/tests/plugins/basics/badsetup/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/badsetup/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/badsetup/foo.py b/tests/plugins/basics/badsetup/foo.py deleted file mode 100644 index 145f2577b..000000000 --- a/tests/plugins/basics/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/plugins/basics/badversionelement/__init__.py b/tests/plugins/basics/badversionelement/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/badversionelement/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/badversionelement/foo.py b/tests/plugins/basics/badversionelement/foo.py deleted file mode 100644 index 2a8b12abe..000000000 --- a/tests/plugins/basics/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/plugins/basics/badversionsource/__init__.py b/tests/plugins/basics/badversionsource/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/badversionsource/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/badversionsource/foo.py b/tests/plugins/basics/badversionsource/foo.py deleted file mode 100644 index 23333a9d8..000000000 --- a/tests/plugins/basics/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/plugins/basics/customelement/__init__.py b/tests/plugins/basics/customelement/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/customelement/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/customelement/foo.py b/tests/plugins/basics/customelement/foo.py deleted file mode 100644 index 260de8b27..000000000 --- a/tests/plugins/basics/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/plugins/basics/customsource/__init__.py b/tests/plugins/basics/customsource/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/customsource/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/customsource/foo.py b/tests/plugins/basics/customsource/foo.py deleted file mode 100644 index de78a00ce..000000000 --- a/tests/plugins/basics/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/plugins/basics/nosetup/__init__.py b/tests/plugins/basics/nosetup/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/nosetup/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/nosetup/foo.py b/tests/plugins/basics/nosetup/foo.py deleted file mode 100644 index 0b5a4fa7e..000000000 --- a/tests/plugins/basics/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/plugins/basics/notatype/__init__.py b/tests/plugins/basics/notatype/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/notatype/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/notatype/foo.py b/tests/plugins/basics/notatype/foo.py deleted file mode 100644 index 311a4fb32..000000000 --- a/tests/plugins/basics/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/plugins/basics/wrongtype/__init__.py b/tests/plugins/basics/wrongtype/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/plugins/basics/wrongtype/__init__.py +++ /dev/null diff --git a/tests/plugins/basics/wrongtype/foo.py b/tests/plugins/basics/wrongtype/foo.py deleted file mode 100644 index 3fe9a1a62..000000000 --- a/tests/plugins/basics/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 |