diff options
-rw-r--r-- | tests/format/project.py | 23 | ||||
-rw-r--r-- | tests/format/project/duplicate-plugins/bar/__init__.py | 0 | ||||
-rw-r--r-- | tests/format/project/duplicate-plugins/bar/foo.py | 9 | ||||
-rw-r--r-- | tests/format/project/duplicate-plugins/bar/frob.py | 9 | ||||
-rw-r--r-- | tests/format/project/duplicate-plugins/baz/__init__.py | 0 | ||||
-rw-r--r-- | tests/format/project/duplicate-plugins/baz/foo.py | 9 | ||||
-rw-r--r-- | tests/format/project/duplicate-plugins/baz/frob.py | 9 | ||||
-rw-r--r-- | tests/format/project/duplicate-plugins/element.bst | 1 | ||||
-rw-r--r-- | tests/format/project/duplicate-plugins/project.conf | 15 | ||||
-rw-r--r-- | tests/plugins/basics.py | 188 | ||||
-rw-r--r-- | tests/plugins/pipeline/badversionelement/project.conf | 13 | ||||
-rw-r--r-- | tests/plugins/pipeline/badversionsource/project.conf | 11 | ||||
-rw-r--r-- | tests/plugins/pipeline/customelement/project.conf | 6 | ||||
-rw-r--r-- | tests/plugins/pipeline/customsource/project.conf | 6 | ||||
-rw-r--r-- | tests/plugins/third_party.py | 18 | ||||
-rw-r--r-- | tests/project/data/plugins/project.conf | 8 | ||||
-rw-r--r-- | tests/project/data/unsupported/project.conf | 3 |
17 files changed, 225 insertions, 103 deletions
diff --git a/tests/format/project.py b/tests/format/project.py new file mode 100644 index 000000000..5b6c474ee --- /dev/null +++ b/tests/format/project.py @@ -0,0 +1,23 @@ +import os +import pytest +from buildstream import _yaml +from buildstream._exceptions import LoadError, LoadErrorReason +from tests.testutils.runcli import cli + + +# Project directory +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "project" +) + + +@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=[ + 'show', 'element.bst']) + assert result.exit_code != 0 + assert result.exception + assert isinstance(result.exception, LoadError) + assert result.exception.reason == LoadErrorReason.INVALID_YAML diff --git a/tests/format/project/duplicate-plugins/bar/__init__.py b/tests/format/project/duplicate-plugins/bar/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/format/project/duplicate-plugins/bar/__init__.py diff --git a/tests/format/project/duplicate-plugins/bar/foo.py b/tests/format/project/duplicate-plugins/bar/foo.py new file mode 100644 index 000000000..260de8b27 --- /dev/null +++ b/tests/format/project/duplicate-plugins/bar/foo.py @@ -0,0 +1,9 @@ +from buildstream import Element + + +class FooElement(Element): + pass + + +def setup(): + return FooElement diff --git a/tests/format/project/duplicate-plugins/bar/frob.py b/tests/format/project/duplicate-plugins/bar/frob.py new file mode 100644 index 000000000..3e2b5ecdd --- /dev/null +++ b/tests/format/project/duplicate-plugins/bar/frob.py @@ -0,0 +1,9 @@ +from buildstream import Element + + +class FrobElement(Element): + pass + + +def setup(): + return FrobElement diff --git a/tests/format/project/duplicate-plugins/baz/__init__.py b/tests/format/project/duplicate-plugins/baz/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/format/project/duplicate-plugins/baz/__init__.py diff --git a/tests/format/project/duplicate-plugins/baz/foo.py b/tests/format/project/duplicate-plugins/baz/foo.py new file mode 100644 index 000000000..260de8b27 --- /dev/null +++ b/tests/format/project/duplicate-plugins/baz/foo.py @@ -0,0 +1,9 @@ +from buildstream import Element + + +class FooElement(Element): + pass + + +def setup(): + return FooElement diff --git a/tests/format/project/duplicate-plugins/baz/frob.py b/tests/format/project/duplicate-plugins/baz/frob.py new file mode 100644 index 000000000..3e2b5ecdd --- /dev/null +++ b/tests/format/project/duplicate-plugins/baz/frob.py @@ -0,0 +1,9 @@ +from buildstream import Element + + +class FrobElement(Element): + pass + + +def setup(): + return FrobElement diff --git a/tests/format/project/duplicate-plugins/element.bst b/tests/format/project/duplicate-plugins/element.bst new file mode 100644 index 000000000..3c29b4ea1 --- /dev/null +++ b/tests/format/project/duplicate-plugins/element.bst @@ -0,0 +1 @@ +kind: autotools diff --git a/tests/format/project/duplicate-plugins/project.conf b/tests/format/project/duplicate-plugins/project.conf new file mode 100644 index 000000000..4b8f5be5f --- /dev/null +++ b/tests/format/project/duplicate-plugins/project.conf @@ -0,0 +1,15 @@ +name: test + +plugins: +- origin: local + path: bar + elements: + foo: 0 + sources: + frob: 0 +- origin: local + path: baz + elements: + foo: 0 + sources: + frob: 0 diff --git a/tests/plugins/basics.py b/tests/plugins/basics.py index 993d87cec..740a20c66 100644 --- a/tests/plugins/basics.py +++ b/tests/plugins/basics.py @@ -43,9 +43,13 @@ def test_element_factory(plugin_fixture): ############################################################## @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)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = SourceFactory(plugin_fixture['base'], plugins) assert(isinstance(factory, SourceFactory)) foo_type, _ = factory.lookup('foo') @@ -54,9 +58,13 @@ def test_custom_source(plugin_fixture, datafiles): @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)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = ElementFactory(plugin_fixture['base'], plugins) assert(isinstance(factory, ElementFactory)) foo_type, _ = factory.lookup('foo') @@ -84,40 +92,16 @@ def test_missing_element(plugin_fixture): 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') - - with pytest.raises(PluginError) as exc: - factory = SourceFactory(plugin_fixture['base'], [plugins1, plugins2]) - - -# 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') - - with pytest.raises(PluginError) as exc: - factory = ElementFactory(plugin_fixture['base'], [plugins1, plugins2]) - - # 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): - factory = SourceFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = SourceFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -125,9 +109,13 @@ def test_source_notatype(plugin_fixture, datafiles): # 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): - factory = ElementFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = ElementFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -136,9 +124,13 @@ def test_element_notatype(plugin_fixture, datafiles): # which is not a Source subclass @pytest.mark.datafiles(os.path.join(DATA_DIR, 'wrongtype')) def test_source_wrongtype(plugin_fixture, datafiles): - factory = SourceFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = SourceFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -147,9 +139,13 @@ def test_source_wrongtype(plugin_fixture, datafiles): # which is not a Element subclass @pytest.mark.datafiles(os.path.join(DATA_DIR, 'wrongtype')) def test_element_wrongtype(plugin_fixture, datafiles): - factory = ElementFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = ElementFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -157,9 +153,13 @@ def test_element_wrongtype(plugin_fixture, datafiles): # 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): - factory = SourceFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = SourceFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -167,9 +167,13 @@ def test_source_missing_setup(plugin_fixture, datafiles): # 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): - factory = ElementFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = ElementFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -178,9 +182,13 @@ def test_element_missing_setup(plugin_fixture, datafiles): # that is not a function @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badsetup')) def test_source_bad_setup(plugin_fixture, datafiles): - factory = SourceFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = SourceFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -189,9 +197,13 @@ def test_source_bad_setup(plugin_fixture, datafiles): # that is not a function @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badsetup')) def test_element_bad_setup(plugin_fixture, datafiles): - factory = ElementFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = ElementFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -200,9 +212,13 @@ def test_element_bad_setup(plugin_fixture, datafiles): # high version of buildstream @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionsource')) def test_source_badversion(plugin_fixture, datafiles): - factory = SourceFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = SourceFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -211,9 +227,13 @@ def test_source_badversion(plugin_fixture, datafiles): # high version of buildstream @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionelement')) def test_element_badversion(plugin_fixture, datafiles): - factory = ElementFactory(plugin_fixture['base'], - [os.path.join(datafiles.dirname, - datafiles.basename)]) + plugins = [{ + 'origin': 'local', + 'path': os.path.join(datafiles.dirname, + datafiles.basename), + 'plugins': {'foo': 0} + }] + factory = ElementFactory(plugin_fixture['base'], plugins) with pytest.raises(PluginError) as exc: foo_type = factory.lookup('foo') @@ -225,12 +245,20 @@ def test_element_badversion(plugin_fixture, datafiles): # Load two factories, both of which define a different 'foo' plugin @pytest.mark.datafiles(DATA_DIR) def test_source_multicontext(plugin_fixture, datafiles): - plugins1 = os.path.join(datafiles.dirname, - datafiles.basename, - 'customsource') - plugins2 = os.path.join(datafiles.dirname, - datafiles.basename, - 'anothersource') + 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'], [plugins1]) factory2 = SourceFactory(plugin_fixture['base'], [plugins2]) @@ -246,12 +274,20 @@ def test_source_multicontext(plugin_fixture, datafiles): # Load two factories, both of which define a different 'foo' plugin @pytest.mark.datafiles(DATA_DIR) def test_element_multicontext(plugin_fixture, datafiles): - plugins1 = os.path.join(datafiles.dirname, - datafiles.basename, - 'customelement') - plugins2 = os.path.join(datafiles.dirname, - datafiles.basename, - 'anotherelement') + 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'], [plugins1]) factory2 = ElementFactory(plugin_fixture['base'], [plugins2]) diff --git a/tests/plugins/pipeline/badversionelement/project.conf b/tests/plugins/pipeline/badversionelement/project.conf index 66d0f5549..4f32752c3 100644 --- a/tests/plugins/pipeline/badversionelement/project.conf +++ b/tests/plugins/pipeline/badversionelement/project.conf @@ -1,12 +1,9 @@ name: pony element-path: elements -required-versions: - - # We provided bar at version 5, should be a conflict. - sources: - foo: 10 - plugins: - sources: - - customelements +- origin: local + path: customelements + elements: + # We provided bar at version 5, should be a conflict. + foo: 10 diff --git a/tests/plugins/pipeline/badversionsource/project.conf b/tests/plugins/pipeline/badversionsource/project.conf index 2925989d1..58cf9c577 100644 --- a/tests/plugins/pipeline/badversionsource/project.conf +++ b/tests/plugins/pipeline/badversionsource/project.conf @@ -1,12 +1,9 @@ name: pony element-path: elements -required-versions: - - # We provided bar at version 5, should be a conflict. +plugins: +- origin: local + path: customsources sources: + # We provided bar at version 5, should be a conflict. foo: 10 - -plugins: - sources: - - customsources diff --git a/tests/plugins/pipeline/customelement/project.conf b/tests/plugins/pipeline/customelement/project.conf index fa80eea01..bdc909985 100644 --- a/tests/plugins/pipeline/customelement/project.conf +++ b/tests/plugins/pipeline/customelement/project.conf @@ -1,5 +1,7 @@ name: pony element-path: elements plugins: - elements: - - pluginelements +- origin: local + path: pluginelements + elements: + foo: 0 diff --git a/tests/plugins/pipeline/customsource/project.conf b/tests/plugins/pipeline/customsource/project.conf index 0be4f201b..8205d185a 100644 --- a/tests/plugins/pipeline/customsource/project.conf +++ b/tests/plugins/pipeline/customsource/project.conf @@ -1,5 +1,7 @@ name: pony element-path: elements plugins: - sources: - - pluginsources +- origin: local + path: pluginsources + sources: + foo: 0 diff --git a/tests/plugins/third_party.py b/tests/plugins/third_party.py index 35705358a..a786fc7c2 100644 --- a/tests/plugins/third_party.py +++ b/tests/plugins/third_party.py @@ -28,22 +28,32 @@ def plugin_fixture(): # Test that external element plugin loading works. @pytest.mark.datafiles(os.path.join(DATA_DIR, 'third_party_element')) def test_custom_pip_element(plugin_fixture, entry_fixture, datafiles): - factory = ElementFactory(plugin_fixture['base'], []) + origin_data = [{ + 'origin': 'local', + 'path': str(datafiles), + 'plugins': {'foop': 0} + }] + factory = ElementFactory(plugin_fixture['base'], origin_data) assert(isinstance(factory, ElementFactory)) entry_fixture(datafiles, 'buildstream.plugins', 'third_party_element:foop') - foo_type, _ = factory.lookup('third_party_element:foop') + foo_type, _ = factory.lookup('foop') assert(foo_type.__name__ == 'FooElement') # Test that external source plugin loading works. @pytest.mark.datafiles(os.path.join(DATA_DIR, 'third_party_source')) def test_custom_pip_source(plugin_fixture, entry_fixture, datafiles): - factory = SourceFactory(plugin_fixture['base'], []) + origin_data = [{ + 'origin': 'local', + 'path': str(datafiles), + 'plugins': {'foop': 0} + }] + factory = SourceFactory(plugin_fixture['base'], origin_data) assert(isinstance(factory, SourceFactory)) entry_fixture(datafiles, 'buildstream.plugins', 'third_party_source:foop') - foo_type, _ = factory.lookup('third_party_source:foop') + foo_type, _ = factory.lookup('foop') assert(foo_type.__name__ == 'FooSource') diff --git a/tests/project/data/plugins/project.conf b/tests/project/data/plugins/project.conf index 119d50424..7d4cbd1ee 100644 --- a/tests/project/data/plugins/project.conf +++ b/tests/project/data/plugins/project.conf @@ -3,7 +3,11 @@ name: pony plugins: +- origin: local + path: elements elements: - - elements + custom: 0 +- origin: local + path: sources sources: - - sources + custom: 0 diff --git a/tests/project/data/unsupported/project.conf b/tests/project/data/unsupported/project.conf index 3241a9193..de94ba3be 100644 --- a/tests/project/data/unsupported/project.conf +++ b/tests/project/data/unsupported/project.conf @@ -1,4 +1,3 @@ # A project which requires a too new version of the format name: foo -required-versions: - project: 5000 +required-project-version: 5000 |