blob: ea319346d4f206f0805522ea38668038e5b37682 (
plain) (
blame)
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
|
import pytest
from unit.option import option
def check_prerequisites(prerequisites):
if 'privileged_user' in prerequisites:
if prerequisites['privileged_user'] and not option.is_privileged:
pytest.skip(
'privileged user required',
allow_module_level=True,
)
elif not prerequisites['privileged_user'] and option.is_privileged:
pytest.skip(
'unprivileged user required',
allow_module_level=True,
)
missed = []
# check modules
if 'modules' in prerequisites:
available = option.available['modules']
for module in prerequisites['modules']:
if module in available and available[module]:
continue
missed.append(module)
if missed:
pytest.skip(
f'Unit has no {", ".join(missed)} module(s)',
allow_module_level=True,
)
# check features
if 'features' in prerequisites:
available = option.available['features']
require = prerequisites['features']
for feature in require:
avail_feature = available[feature]
if feature in available and avail_feature:
if isinstance(require[feature], list) and isinstance(
avail_feature, dict
):
avail_keys = avail_feature.keys()
for key in require[feature]:
if key not in avail_keys:
missed.append(f'{feature}/{key}')
continue
missed.append(feature)
if missed:
pytest.skip(
f'{", ".join(missed)} feature(s) not supported',
allow_module_level=True,
)
|