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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
import os
import pytest
from buildstream import LoadError, LoadErrorReason
from buildstream._loader import Loader
from buildstream._metaelement import MetaElement
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'variants',
)
##############################################################
# Test Basic Failure Modes #
##############################################################
@pytest.mark.datafiles(DATA_DIR)
def test_variant_not_list(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(basedir, 'elements/variants-not-list.bst', None, None)
with pytest.raises(LoadError) as exc:
element = loader.load()
assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
def test_variant_unnamed(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(basedir, 'elements/unnamed-variant.bst', None, None)
with pytest.raises(LoadError) as exc:
element = loader.load()
assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
def test_variant_bad_name(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(basedir, 'elements/variant-bad-name.bst', None, None)
with pytest.raises(LoadError) as exc:
element = loader.load()
assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
def test_variant_only_one(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(basedir, 'elements/only-one-variant.bst', None, None)
with pytest.raises(LoadError) as exc:
element = loader.load()
assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
def test_variant_illegal_composite(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/variant-illegal-composite.bst', None, None)
with pytest.raises(LoadError) as exc:
element = loader.load()
assert (exc.value.reason == LoadErrorReason.ILLEGAL_COMPOSITE)
##############################################################
# Test Simple Variant Compositing #
##############################################################
@pytest.mark.datafiles(DATA_DIR)
def test_variant_simple_composite_default(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/simple-variant-compositing.bst', None, None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
# Without specifying a variant, the default (first) should have been chosen
assert(element.config.get('somedata') == 5)
assert(element.config.get('pony-color') == 'pink')
@pytest.mark.datafiles(DATA_DIR)
def test_variant_simple_composite_pink_pony(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/simple-variant-compositing.bst', 'pink', None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
# We explicitly asked for the pink variation of this pony
assert(element.config.get('somedata') == 5)
assert(element.config.get('pony-color') == 'pink')
@pytest.mark.datafiles(DATA_DIR)
def test_variant_simple_composite_blue_pony(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/simple-variant-compositing.bst', 'blue', None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
# We explicitly asked for the blue variation of this pony,
# which has the side effect of overriding the value of 'somedata'
assert(element.config.get('somedata') == 6)
assert(element.config.get('pony-color') == 'blue')
##############################################################
# Test Variant Dependency Plotting #
##############################################################
#
# Convenience for asserting dependencies
#
def assert_dependency(element, index, name, key, value):
# Test that the dependency we got is the pink color by default
assert(len(element.dependencies) >= index + 1)
dep = element.dependencies[index]
assert(isinstance(dep, MetaElement))
assert(dep.name == name)
assert(isinstance(dep.config, dict))
assert(dep.config.get(key) == value)
return dep
@pytest.mark.datafiles(DATA_DIR)
def test_variant_simple_dependency_default(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/simple-dependency-variants.bst', None, None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
# Test that the default is a pink pony
assert_dependency(element, 0, 'elements-simply-pink', 'color', 'pink')
@pytest.mark.datafiles(DATA_DIR)
def test_variant_simple_dependency_pink_pony(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/simple-dependency-variants.bst', 'pink', None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
# Test that the explicit pink dependency is correct
assert_dependency(element, 0, 'elements-simply-pink', 'color', 'pink')
@pytest.mark.datafiles(DATA_DIR)
def test_variant_simple_dependency_blue_pony(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/simple-dependency-variants.bst', 'blue', None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
# Test that the explicit blue dependency is correct
assert_dependency(element, 0, 'elements-simply-blue', 'color', 'blue')
@pytest.mark.datafiles(DATA_DIR)
def test_variant_indirect_dependency_default(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/indirect-dependency-variants.bst', None, None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
# Test that the default is a blue pony-color by default
simple = assert_dependency(
element, 0, 'elements-simple-dependency-variants', 'pony-color', 'blue')
# Test that the element we depend on now depends on the blue color
assert_dependency(simple, 0, 'elements-simply-blue', 'color', 'blue')
@pytest.mark.datafiles(DATA_DIR)
def test_variant_indirect_dependency_blue_pony(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/indirect-dependency-variants.bst', 'blue', None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
# Test for a blue pony-color
simple = assert_dependency(
element, 0, 'elements-simple-dependency-variants', 'pony-color', 'blue')
# Test that the element we depend on now depends on the blue color
assert_dependency(simple, 0, 'elements-simply-blue', 'color', 'blue')
@pytest.mark.datafiles(DATA_DIR)
def test_variant_indirect_dependency_pink_pony(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(
basedir, 'elements/indirect-dependency-variants.bst', 'pink', None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'pony')
# Test for a blue pony-color
simple = assert_dependency(
element, 0, 'elements-simple-dependency-variants', 'pony-color', 'pink')
# Test that the element we depend on now depends on the blue color
assert_dependency(simple, 0, 'elements-simply-pink', 'color', 'pink')
@pytest.mark.datafiles(DATA_DIR)
def test_engine_resolve_agreement(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(basedir, 'elements/tricky.bst', None, None)
element = loader.load()
assert(isinstance(element, MetaElement))
assert(element.kind == 'tricky')
# Test the first dependency
first = assert_dependency(element, 0, 'elements-tricky-first', 'choice', 'second')
second = assert_dependency(element, 1, 'elements-tricky-second', 'choice', 'second')
@pytest.mark.datafiles(DATA_DIR)
def test_engine_disagreement(datafiles):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
loader = Loader(basedir, 'elements/disagreement.bst', None, None)
with pytest.raises(LoadError) as exc:
element = loader.load()
assert (exc.value.reason == LoadErrorReason.VARIANT_DISAGREEMENT)
|