summaryrefslogtreecommitdiff
path: root/tests/pipeline/load.py
blob: 33d49bb31d8f5f7ccaaea1899eb93b01237fed5d (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import os
import pytest

from buildstream import Context, Project, Scope
from buildstream._pipeline import Pipeline
from buildstream._platform import Platform

from tests.testutils.site import HAVE_ROOT

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


def create_pipeline(tmpdir, basedir, target):
    context = Context([], 'x86_64')
    project = Project(basedir, context)

    context.deploydir = os.path.join(str(tmpdir), 'deploy')
    context.artifactdir = os.path.join(str(tmpdir), 'artifact')
    context._platform = Platform.get_platform()

    return Pipeline(context, project, target)


@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'simple'))
def test_load_simple(datafiles, tmpdir):

    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    pipeline = create_pipeline(tmpdir, basedir, 'simple.bst')

    assert(pipeline.target.get_kind() == "autotools")

    assert(isinstance(pipeline.target.commands['configure-commands'], list))
    command_list = pipeline.target.commands['configure-commands']
    assert(len(command_list) == 1)
    assert(command_list[0] == 'pony')


###############################################################
#        Testing Element.dependencies() iteration             #
###############################################################
@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_all(datafiles, tmpdir):

    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    pipeline = create_pipeline(tmpdir, basedir, 'target.bst')

    assert(pipeline.target.get_kind() == "autotools")

    assert(isinstance(pipeline.target.commands['configure-commands'], list))
    command_list = pipeline.target.commands['configure-commands']
    assert(len(command_list) == 1)
    assert(command_list[0] == 'pony')

    element_list = pipeline.target.dependencies(Scope.ALL)
    element_list = list(element_list)
    assert(len(element_list) == 7)

    assert(element_list[0].name == "build-build.bst")
    assert(element_list[1].name == "run-build.bst")
    assert(element_list[2].name == "build.bst")
    assert(element_list[3].name == "dep-one.bst")
    assert(element_list[4].name == "run.bst")
    assert(element_list[5].name == "dep-two.bst")
    assert(element_list[6].name == "target.bst")


@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_run(datafiles, tmpdir):

    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    pipeline = create_pipeline(tmpdir, basedir, 'target.bst')

    assert(pipeline.target.get_kind() == "autotools")

    assert(isinstance(pipeline.target.commands['configure-commands'], list))
    command_list = pipeline.target.commands['configure-commands']
    assert(len(command_list) == 1)
    assert(command_list[0] == 'pony')

    element_list = pipeline.target.dependencies(Scope.RUN)
    element_list = list(element_list)
    assert(len(element_list) == 4)

    assert(element_list[0].name == "dep-one.bst")
    assert(element_list[1].name == "run.bst")
    assert(element_list[2].name == "dep-two.bst")
    assert(element_list[3].name == "target.bst")


@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_build(datafiles, tmpdir):

    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    pipeline = create_pipeline(tmpdir, basedir, 'target.bst')

    assert(pipeline.target.get_kind() == "autotools")

    assert(isinstance(pipeline.target.commands['configure-commands'], list))
    command_list = pipeline.target.commands['configure-commands']
    assert(len(command_list) == 1)
    assert(command_list[0] == 'pony')

    element_list = pipeline.target.dependencies(Scope.BUILD)
    element_list = list(element_list)

    assert(len(element_list) == 3)

    assert(element_list[0].name == "dep-one.bst")
    assert(element_list[1].name == "run.bst")
    assert(element_list[2].name == "dep-two.bst")


@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_build_of_child(datafiles, tmpdir):

    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    pipeline = create_pipeline(tmpdir, basedir, 'target.bst')

    assert(pipeline.target.get_kind() == "autotools")

    assert(isinstance(pipeline.target.commands['configure-commands'], list))
    command_list = pipeline.target.commands['configure-commands']
    assert(len(command_list) == 1)
    assert(command_list[0] == 'pony')

    # First pass, lets check dep-two
    element_list = pipeline.target.dependencies(Scope.BUILD)
    element_list = list(element_list)
    element = element_list[2]

    # Pass two, let's look at these
    element_list = element.dependencies(Scope.BUILD)
    element_list = list(element_list)

    assert(len(element_list) == 2)

    assert(element_list[0].name == "run-build.bst")
    assert(element_list[1].name == "build.bst")


###############################################################
#                   Testing element removal                   #
###############################################################
@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'remove'))
def test_remove_elements(datafiles, tmpdir):

    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    pipeline = create_pipeline(tmpdir, basedir, 'build.bst')

    # Remove second-level-2 and check that the correct dependencies
    # are removed.
    element_list = pipeline.target.dependencies(Scope.ALL)
    element_list = pipeline.remove_elements(element_list, ['second-level-1.bst'])

    assert(set(e.name for e in element_list) ==
           set(['build.bst', 'third-level-2.bst', 'fourth-level-2.bst',
                'first-level-1.bst', 'first-level-2.bst']))