Newer
Older
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
#!/usr/bin/env python3
#
# This module defines the test case format and implement a
# parser for such a format.
#
import sys
import yaml
test_case_format = {
'metadata' : (True, {
'name' : (True, ""),
'format' : (False, ""),
'image-type' : (True, [ 'target', 'minimal', 'ostree',
'development', 'SDK', 'any' ]),
'image-arch' : (True, ['amd64', 'arm64', 'armhf', 'any']),
'type' : (True, ['functional', 'sanity', 'system']),
'exec-type' : (True, ['manual' , 'automated']),
'priority' : (True, ['low', 'medium', 'high', 'critical']),
'maintainer' : (False, ""),
'description' : (True, ""),
'resources' : (False, []),
'pre-conditions' : (False, []),
'expected' : (True, []),
'notes' : (False, []),
'post-conditions' : (False, [])
}),
'install' : (False, {
'deps' : (True, [])
}),
'run' : (True, {
'steps' : (True, [])
}),
'parse' : (False, {})
}
def parse_format(test_case, test_case_format):
for tagf, valuestr in test_case_format.items():
mandatory, valuef = valuestr
value = test_case.get(tagf)
if not value:
if mandatory:
sys.stderr.write("Error: mandatory field missing: '{}'\n"
.format(tagf))
sys.exit(1)
# Test case doesn't have this non-mandatory tag, so just continue.
continue
if type(value) == str and type(valuef) == list:
if tagf in ['image-type' , 'image-arch', 'type',
'exec-type', 'priority']:
try:
valuef.index(value)
except ValueError:
sys.stderr.write("Warning: value '{}' not found in '{}' for "\
"field '{}'\n".format(value, valuef, tagf))
continue
if type(value) != type(valuef):
sys.stderr.write("Error: incorrect type for field: '{}'\n"
.format(tagf))
sys.exit(1)
if type(value) == dict:
parse_format(value, valuef)
return True
if '__main__' == __name__:
testcase = sys.argv[1]
with open(testcase) as test_case:
test_case_data = yaml.safe_load(test_case)
parse_format(test_case_data, test_case_format)