summaryrefslogtreecommitdiff
path: root/tests/internals/pluginloading.py
blob: 2d997077a1ba9cdc9799a9d441fa78f446dfbfae (plain)
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
61
62
63
64
65
import os
import pytest

from buildstream._context import Context
from buildstream._project import Project
from buildstream._exceptions import LoadError, LoadErrorReason
from buildstream._pipeline import Pipeline

DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    'pluginloading',
)


def create_pipeline(tmpdir, basedir, target):
    context = Context()
    context.load(config=os.devnull)
    context.deploydir = os.path.join(str(tmpdir), 'deploy')
    context.casdir = os.path.join(str(tmpdir), 'cas')
    project = Project(basedir, context)

    def dummy_handler(message, context):
        pass

    context.set_message_handler(dummy_handler)

    pipeline = Pipeline(context, project, None)
    targets, = pipeline.load([(target,)])
    return targets


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'customsource'))
def test_customsource(datafiles, tmpdir):

    basedir = str(datafiles)
    targets = create_pipeline(tmpdir, basedir, 'simple.bst')
    assert targets[0].get_kind() == "autotools"


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'customelement'))
def test_customelement(datafiles, tmpdir):

    basedir = str(datafiles)
    targets = create_pipeline(tmpdir, basedir, 'simple.bst')
    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')

    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')

    assert exc.value.reason == LoadErrorReason.UNSUPPORTED_PLUGIN