1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# Pylint doesn't play well with fixtures and dependency injection from pytest
# pylint: disable=redefined-outer-name
#
# This test case tests the failure modes of loading a plugin
# after it has already been discovered via it's origin.
#
import os
import pytest
from buildstream._exceptions import ErrorDomain
from tests.testutils import cli # pylint: disable=unused-import
from buildstream import _yaml
DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "bst2")
# Sets up the element.bst file so that it requires a source
# or element plugin.
#
def setup_element(project_path, plugin_type, plugin_name):
element_path = os.path.join(project_path, "element.bst")
if plugin_type == "elements":
element = {"kind": plugin_name}
else:
element = {"kind": "manual", "sources": [{"kind": plugin_name}]}
_yaml.dump(element, element_path)
####################################################
# Tests #
####################################################
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("plugin_type", ["elements", "sources"])
@pytest.mark.parametrize("plugin", ["bst2", "malformed"])
def test_plugin_bst2(cli, datafiles, plugin_type, plugin):
project = str(datafiles)
project_conf_path = os.path.join(project, "project.conf")
project_conf = {
"name": "test",
"plugins": [
{
"origin": "local",
"path": plugin_type,
plugin_type: {
plugin: 0
}
}
]
}
_yaml.dump(project_conf, project_conf_path)
setup_element(project, plugin_type, plugin)
result = cli.run(project=project, args=["show", "element.bst"])
result.assert_main_error(ErrorDomain.PLUGIN, "plugin-version-mismatch")
|