4
4
import sys
5
5
from functools import partial
6
6
from pathlib import Path
7
+ from typing import TYPE_CHECKING
7
8
from typing import Callable
8
9
9
10
import pytest
33
34
from variantlib .pyproject_toml import VariantPyProjectToml
34
35
from variantlib .variants_json import VariantsJson
35
36
37
+ if TYPE_CHECKING :
38
+ from variantlib .protocols import VariantPropertyType
39
+
36
40
if sys .version_info >= (3 , 11 ):
37
41
import tomllib
38
42
else :
44
48
45
49
class ClashingPlugin (PluginType ):
46
50
namespace = "test_namespace"
51
+ dynamic = False
47
52
48
- def get_all_configs (self ) -> list [VariantFeatureConfigType ]:
53
+ def get_all_configs (
54
+ self , known_properties : frozenset [VariantPropertyType ] | None
55
+ ) -> list [VariantFeatureConfigType ]:
49
56
return [
50
57
VariantFeatureConfig ("name1" , ["val1a" , "val1b" , "val1c" , "val1d" ]),
51
58
]
52
59
53
- def get_supported_configs (self ) -> list [VariantFeatureConfigType ]:
60
+ def get_supported_configs (
61
+ self , known_properties : frozenset [VariantPropertyType ] | None
62
+ ) -> list [VariantFeatureConfigType ]:
54
63
return []
55
64
56
65
57
66
class ExceptionPluginBase (PluginType ):
58
67
namespace = "exception_test"
68
+ dynamic = False
59
69
60
70
returned_value : list [VariantFeatureConfigType ]
61
71
62
- def get_all_configs (self ) -> list [VariantFeatureConfigType ]:
72
+ def get_all_configs (
73
+ self , known_properties : frozenset [VariantPropertyType ] | None
74
+ ) -> list [VariantFeatureConfigType ]:
63
75
return self .returned_value
64
76
65
- def get_supported_configs (self ) -> list [VariantFeatureConfigType ]:
77
+ def get_supported_configs (
78
+ self , known_properties : frozenset [VariantPropertyType ] | None
79
+ ) -> list [VariantFeatureConfigType ]:
66
80
return self .returned_value
67
81
68
82
@@ -115,6 +129,65 @@ def test_get_supported_configs(
115
129
}
116
130
117
131
132
+ def test_get_all_configs_dynamic (
133
+ mocked_plugin_loader : BasePluginLoader ,
134
+ ) -> None :
135
+ assert mocked_plugin_loader .get_all_configs (
136
+ [
137
+ VariantProperty ("test_namespace" , "name1" , "val1z" ),
138
+ VariantProperty ("second_namespace" , "name3" , "val3bcde" ),
139
+ ]
140
+ ) == {
141
+ "incompatible_namespace" : ProviderConfig (
142
+ namespace = "incompatible_namespace" ,
143
+ configs = [
144
+ VariantFeatureConfig ("flag1" , ["on" ]),
145
+ VariantFeatureConfig ("flag2" , ["on" ]),
146
+ VariantFeatureConfig ("flag3" , ["on" ]),
147
+ VariantFeatureConfig ("flag4" , ["on" ]),
148
+ ],
149
+ ),
150
+ "second_namespace" : ProviderConfig (
151
+ namespace = "second_namespace" ,
152
+ configs = [
153
+ VariantFeatureConfig ("name3" , ["val3a" , "val3b" , "val3c" , "val3bcde" ]),
154
+ ],
155
+ ),
156
+ "test_namespace" : ProviderConfig (
157
+ namespace = "test_namespace" ,
158
+ configs = [
159
+ VariantFeatureConfig ("name1" , ["val1a" , "val1b" , "val1c" , "val1d" ]),
160
+ VariantFeatureConfig ("name2" , ["val2a" , "val2b" , "val2c" ]),
161
+ ],
162
+ ),
163
+ }
164
+
165
+
166
+ def test_get_supported_configs_dynamic (
167
+ mocked_plugin_loader : BasePluginLoader ,
168
+ ) -> None :
169
+ assert mocked_plugin_loader .get_supported_configs (
170
+ [
171
+ VariantProperty ("test_namespace" , "name1" , "val1z" ),
172
+ VariantProperty ("second_namespace" , "name3" , "val3abcd" ),
173
+ ]
174
+ ) == {
175
+ "second_namespace" : ProviderConfig (
176
+ namespace = "second_namespace" ,
177
+ configs = [
178
+ VariantFeatureConfig ("name3" , ["val3a" , "val3abcd" ]),
179
+ ],
180
+ ),
181
+ "test_namespace" : ProviderConfig (
182
+ namespace = "test_namespace" ,
183
+ configs = [
184
+ VariantFeatureConfig ("name1" , ["val1a" , "val1b" ]),
185
+ VariantFeatureConfig ("name2" , ["val2a" , "val2b" , "val2c" ]),
186
+ ],
187
+ ),
188
+ }
189
+
190
+
118
191
def test_namespace_clash () -> None :
119
192
with (
120
193
pytest .raises (
@@ -227,8 +300,11 @@ def test_namespace_incorrect_name() -> None:
227
300
228
301
class IncompletePlugin :
229
302
namespace = "incomplete_plugin"
303
+ dynamic = False
230
304
231
- def get_supported_configs (self ) -> list [VariantFeatureConfigType ]:
305
+ def get_supported_configs (
306
+ self , known_properties : frozenset [VariantPropertyType ] | None
307
+ ) -> list [VariantFeatureConfigType ]:
232
308
return []
233
309
234
310
@@ -237,8 +313,8 @@ def test_namespace_incorrect_type() -> None:
237
313
pytest .raises (
238
314
PluginError ,
239
315
match = r"'tests.plugins.test_loader:RANDOM_STUFF' does not meet "
240
- r"the PluginType prototype: 123 \(missing attributes: get_all_configs , "
241
- r"get_supported_configs, namespace\)" ,
316
+ r"the PluginType prototype: 123 \(missing attributes: dynamic , "
317
+ r"get_all_configs, get_supported_configs, namespace\)" ,
242
318
),
243
319
ListPluginLoader (["tests.plugins.test_loader:RANDOM_STUFF" ]),
244
320
):
@@ -251,10 +327,14 @@ class RaisingInstantiationPlugin:
251
327
def __init__ (self ) -> None :
252
328
raise RuntimeError ("I failed to initialize" )
253
329
254
- def get_all_configs (self ) -> list [VariantFeatureConfigType ]:
330
+ def get_all_configs (
331
+ self , known_properties : frozenset [VariantPropertyType ]
332
+ ) -> list [VariantFeatureConfigType ]:
255
333
return []
256
334
257
- def get_supported_configs (self ) -> list [VariantFeatureConfigType ]:
335
+ def get_supported_configs (
336
+ self , known_properties : frozenset [VariantPropertyType ]
337
+ ) -> list [VariantFeatureConfigType ]:
258
338
return []
259
339
260
340
@@ -273,14 +353,19 @@ def test_namespace_instantiation_raises() -> None:
273
353
274
354
class CrossTypeInstantiationPlugin :
275
355
namespace = "cross_plugin"
356
+ dynamic = False
276
357
277
358
def __new__ (cls ) -> IncompletePlugin : # type: ignore[misc]
278
359
return IncompletePlugin ()
279
360
280
- def get_all_configs (self ) -> list [VariantFeatureConfigType ]:
361
+ def get_all_configs (
362
+ self , known_properties : frozenset [VariantPropertyType ] | None
363
+ ) -> list [VariantFeatureConfigType ]:
281
364
return []
282
365
283
- def get_supported_configs (self ) -> list [VariantFeatureConfigType ]:
366
+ def get_supported_configs (
367
+ self , known_properties : frozenset [VariantPropertyType ] | None
368
+ ) -> list [VariantFeatureConfigType ]:
284
369
return []
285
370
286
371
@@ -314,9 +399,13 @@ def test_get_build_setup(
314
399
]
315
400
)
316
401
317
- assert mocked_plugin_loader .get_build_setup (variant_desc ) == {
318
- "cflags" : ["-mflag1" , "-mflag4" , "-march=val1b" ],
319
- "cxxflags" : ["-mflag1" , "-mflag4" , "-march=val1b" ],
402
+ # flag order may depend on (random) property ordering
403
+ assert {
404
+ k : sorted (v )
405
+ for k , v in mocked_plugin_loader .get_build_setup (variant_desc ).items ()
406
+ } == {
407
+ "cflags" : ["-march=val1b" , "-mflag1" , "-mflag4" ],
408
+ "cxxflags" : ["-march=val1b" , "-mflag1" , "-mflag4" ],
320
409
"ldflags" : ["-Wl,--test-flag" ],
321
410
}
322
411
0 commit comments