summaryrefslogtreecommitdiff
path: root/tests/plugins
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2016-11-13 20:59:19 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2016-11-13 21:11:28 +0900
commit42855fcdaaaf8b4d031177e12fb6261664979236 (patch)
treea6752214824c3405ecd4e5212c3c7f7129889629 /tests/plugins
parent1561589216f36de18ed3b99464f6a5c7533e65a5 (diff)
downloadbuildstream-42855fcdaaaf8b4d031177e12fb6261664979236.tar.gz
Adding more plugin tests
Diffstat (limited to 'tests/plugins')
-rw-r--r--tests/plugins/basics.py93
-rw-r--r--tests/plugins/basics/anotherelement/__init__.py0
-rw-r--r--tests/plugins/basics/anotherelement/foo.py7
-rw-r--r--tests/plugins/basics/anothersource/__init__.py0
-rw-r--r--tests/plugins/basics/anothersource/foo.py7
-rw-r--r--tests/plugins/basics/customelement/__init__.py0
-rw-r--r--tests/plugins/basics/customelement/foo.py7
-rw-r--r--tests/plugins/basics/customsource/__init__.py0
-rw-r--r--tests/plugins/basics/customsource/foo.py7
9 files changed, 110 insertions, 11 deletions
diff --git a/tests/plugins/basics.py b/tests/plugins/basics.py
index 9e65ba14c..8b96bf0df 100644
--- a/tests/plugins/basics.py
+++ b/tests/plugins/basics.py
@@ -1,21 +1,92 @@
+import os
import pytest
from pluginbase import PluginBase
from buildstream._elementfactory import _ElementFactory
from buildstream._sourcefactory import _SourceFactory
+from buildstream 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_base():
- base = PluginBase(package='buildstream.plugins')
- return base
+def plugin_fixture(datafiles):
+ 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):
+ factory = _SourceFactory(plugin_fixture['base'],
+ [ os.path.join(datafiles.dirname, datafiles.basename) ])
+ 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):
+ factory = _ElementFactory(plugin_fixture['base'],
+ [ os.path.join(datafiles.dirname, datafiles.basename) ])
+ 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 one factory with 2 plugin directories both containing a foo plugin
+@pytest.mark.datafiles(DATA_DIR)
+def test_conflict_source(plugin_fixture, datafiles):
+ plugins1 = os.path.join(datafiles.dirname, datafiles.basename, 'customsource')
+ plugins2 = os.path.join(datafiles.dirname, datafiles.basename, 'anothersource')
-def test_fixture(plugin_base):
- assert(isinstance (plugin_base, PluginBase))
+ with pytest.raises(PluginError) as exc:
+ factory = _SourceFactory(plugin_fixture['base'], [ plugins1, plugins2 ])
-def test_source_factory(plugin_base):
- source_factory = _SourceFactory(plugin_base)
- assert(isinstance (source_factory, _SourceFactory))
+# Load one factory with 2 plugin directories both containing a foo plugin
+@pytest.mark.datafiles(DATA_DIR)
+def test_conflict_element(plugin_fixture, datafiles):
+ plugins1 = os.path.join(datafiles.dirname, datafiles.basename, 'customelement')
+ plugins2 = os.path.join(datafiles.dirname, datafiles.basename, 'anotherelement')
-def test_element_factory(plugin_base):
- element_factory = _ElementFactory(plugin_base)
- assert(isinstance (element_factory, _ElementFactory))
+ with pytest.raises(PluginError) as exc:
+ factory = _ElementFactory(plugin_fixture['base'], [ plugins1, plugins2 ])
diff --git a/tests/plugins/basics/anotherelement/__init__.py b/tests/plugins/basics/anotherelement/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/plugins/basics/anotherelement/__init__.py
diff --git a/tests/plugins/basics/anotherelement/foo.py b/tests/plugins/basics/anotherelement/foo.py
new file mode 100644
index 000000000..b0b65fcbd
--- /dev/null
+++ b/tests/plugins/basics/anotherelement/foo.py
@@ -0,0 +1,7 @@
+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
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/plugins/basics/anothersource/__init__.py
diff --git a/tests/plugins/basics/anothersource/foo.py b/tests/plugins/basics/anothersource/foo.py
new file mode 100644
index 000000000..bf5df372e
--- /dev/null
+++ b/tests/plugins/basics/anothersource/foo.py
@@ -0,0 +1,7 @@
+from buildstream import Source
+
+class AnotherFooSource(Source):
+ pass
+
+def setup():
+ return AnotherFooSource
diff --git a/tests/plugins/basics/customelement/__init__.py b/tests/plugins/basics/customelement/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/plugins/basics/customelement/__init__.py
diff --git a/tests/plugins/basics/customelement/foo.py b/tests/plugins/basics/customelement/foo.py
new file mode 100644
index 000000000..21eb7b42d
--- /dev/null
+++ b/tests/plugins/basics/customelement/foo.py
@@ -0,0 +1,7 @@
+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
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/plugins/basics/customsource/__init__.py
diff --git a/tests/plugins/basics/customsource/foo.py b/tests/plugins/basics/customsource/foo.py
new file mode 100644
index 000000000..aec8ddf60
--- /dev/null
+++ b/tests/plugins/basics/customsource/foo.py
@@ -0,0 +1,7 @@
+from buildstream import Source
+
+class FooSource(Source):
+ pass
+
+def setup():
+ return FooSource