summaryrefslogtreecommitdiff
path: root/tests/internals/pluginloading.py
blob: 83944bbd925c99ad3f151276ad10cef2f416c967 (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
from contextlib import contextmanager
import os
import pytest

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

from tests.testutils import dummy_context

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


@contextmanager
def create_pipeline(tmpdir, basedir, target):
    with dummy_context() as context:
        context.deploydir = os.path.join(str(tmpdir), "deploy")
        context.casdir = os.path.join(str(tmpdir), "cas")
        project = Project(basedir, context)

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


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

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


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

    basedir = str(datafiles)
    with create_pipeline(tmpdir, basedir, "simple.bst") as targets:
        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"):
        pass

    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"):
        pass

    assert exc.value.reason == LoadErrorReason.UNSUPPORTED_PLUGIN