summaryrefslogtreecommitdiff
path: root/tests/pipeline/load.py
blob: 178e827b01af26b515104a0cfd8818f471530c24 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import os
import pytest
from buildstream._exceptions import ErrorDomain
from buildstream import _yaml
from tests.testutils.runcli import cli
from tests.testutils.site import IS_LINUX, NO_FUSE

pytestmark = pytest.mark.skipif(IS_LINUX and NO_FUSE, reason='FUSE not supported on this system')

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


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'simple'))
def test_load_simple(cli, datafiles):
    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    result = cli.get_element_config(basedir, 'simple.bst')

    assert(result['configure-commands'][0] == 'pony')


###############################################################
#        Testing Element.dependencies() iteration             #
###############################################################
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_all(cli, datafiles):
    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    elements = ['target.bst']

    element_list = cli.get_pipeline(basedir, elements, scope='all')

    assert(len(element_list) == 7)

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


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_run(cli, datafiles):
    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    elements = ['target.bst']

    element_list = cli.get_pipeline(basedir, elements, scope='run')

    assert(len(element_list) == 4)

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


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_build(cli, datafiles):
    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    elements = ['target.bst']

    element_list = cli.get_pipeline(basedir, elements, scope='build')

    assert(len(element_list) == 3)

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


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_build_of_child(cli, datafiles):
    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    elements = ['target.bst']

    element_list = cli.get_pipeline(basedir, elements, scope='build')

    # First pass, lets check dep-two
    element = element_list[2]

    # Pass two, let's look at these
    element_list = cli.get_pipeline(basedir, [element], scope='build')

    assert(len(element_list) == 2)

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


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_no_recurse(cli, datafiles):
    basedir = os.path.join(datafiles.dirname, datafiles.basename)
    elements = ['target.bst']

    # We abuse the 'plan' scope here to ensure that we call
    # element.dependencies() with recurse=False - currently, no `bst
    # show` option does this directly.
    element_list = cli.get_pipeline(basedir, elements, scope='plan')

    assert(len(element_list) == 7)

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


# This test checks various constructions of a pipeline
# with one or more targets and 0 or more exception elements,
# each data set provides the targets, exceptions and expected
# result list.
#
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'exceptions'))
@pytest.mark.parametrize("elements,exceptions,results", [

    # Test without exceptions, lets just see the whole list here
    (['build.bst'], None, [
        'fourth-level-1.bst',
        'third-level-1.bst',
        'fourth-level-2.bst',
        'third-level-2.bst',
        'fourth-level-3.bst',
        'third-level-3.bst',
        'second-level-1.bst',
        'first-level-1.bst',
        'first-level-2.bst',
        'build.bst',
    ]),

    # Test one target and excepting a part of the pipeline, this
    # removes forth-level-1 and third-level-1
    (['build.bst'], ['third-level-1.bst'], [
        'fourth-level-2.bst',
        'third-level-2.bst',
        'fourth-level-3.bst',
        'third-level-3.bst',
        'second-level-1.bst',
        'first-level-1.bst',
        'first-level-2.bst',
        'build.bst',
    ]),

    # Test one target and excepting a part of the pipeline, check that
    # excepted dependencies remain in the pipeline if depended on from
    # outside of the except element
    (['build.bst'], ['second-level-1.bst'], [
        'fourth-level-2.bst',
        'third-level-2.bst',  # first-level-2 depends on this, so not excepted
        'first-level-1.bst',
        'first-level-2.bst',
        'build.bst',
    ]),

    # The same as the above test, but excluding the toplevel build.bst,
    # instead only select the two toplevel dependencies as targets
    (['first-level-1.bst', 'first-level-2.bst'], ['second-level-1.bst'], [
        'fourth-level-2.bst',
        'third-level-2.bst',  # first-level-2 depends on this, so not excepted
        'first-level-1.bst',
        'first-level-2.bst',
    ]),

    # Test one target and excepting an element outisde the pipeline
    (['build.bst'], ['unrelated-1.bst'], [
        'fourth-level-2.bst',
        'third-level-2.bst',  # first-level-2 depends on this, so not excepted
        'first-level-1.bst',
        'first-level-2.bst',
        'build.bst',
    ]),

    # Test one target and excepting two elements
    (['build.bst'], ['unrelated-1.bst', 'unrelated-2.bst'], [
        'first-level-1.bst',
        'build.bst',
    ]),
])
def test_except_elements(cli, datafiles, elements, exceptions, results):
    basedir = os.path.join(datafiles.dirname, datafiles.basename)

    # Except second-level-2 and check that the correct dependencies
    # are removed.
    element_list = cli.get_pipeline(basedir, elements, except_=exceptions, scope='all')
    assert element_list == results


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'noloadref'))
@pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')])
def test_unsupported_load_ref(cli, datafiles, ref_storage):
    basedir = os.path.join(datafiles.dirname, datafiles.basename)

    # Generate project with access to the noloadref plugin and project.refs enabled
    #
    config = {
        'name': 'test',
        'ref-storage': ref_storage,
        'plugins': [
            {
                'origin': 'local',
                'path': 'plugins',
                'sources': {
                    'noloadref': 0
                }
            }
        ]
    }
    _yaml.dump(config, os.path.join(basedir, 'project.conf'))

    result = cli.run(project=basedir, silent=True, args=['show', 'noloadref.bst'])

    # There is no error if project.refs is not in use, otherwise we
    # assert our graceful failure
    if ref_storage == 'inline':
        result.assert_success()
    else:
        result.assert_main_error(ErrorDomain.SOURCE, 'unsupported-load-ref')