tests/headertest.py

Thu, 26 Aug 2021 19:37:00 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 26 Aug 2021 19:37:00 +0300
changeset 148
8f621aa4cfd7
parent 127
97de6058109e
permissions
-rw-r--r--

Update license year

105
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 from testsuite import problem_type, report_problem
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 import linetypes
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 @problem_type('bad-header',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 message = lambda reason: str.format('bad header: {}', reason),
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 @problem_type('no-license-set',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 message = 'no license set',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 @problem_type('non-ca-license',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 message = 'no new non-CA-submits are accepted',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 def bad_header(model):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 import header
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 ca_license = 'Redistributable under CCAL version 2.0 : see CAreadme.txt'
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 if isinstance(model.header, header.BadHeader):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 yield report_problem(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 'bad-header',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 bad_object = model.body[model.header.index],
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 reason = model.header.reason,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 elif not model.header.license:
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 yield report_problem(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 'no-license-set',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 bad_object = model.body[0],
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 elif model.header.license != ca_license:
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 yield report_problem(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 'non-ca-license',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 bad_object = model.find_first_header_object('license'),
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 @problem_type('bfc-nocertify',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 message = 'all new parts must be BFC certified',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 def nocertify_test(model):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 import header
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 if model.header.valid and model.header.bfc == 'NOCERTIFY':
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 yield report_problem(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 'bfc-nocertify',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 bad_object = model.find_first_header_object('bfc'),
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 @problem_type('physical-colour-part',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 message = 'no new physical colour parts are accepted',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 def physical_colours_test(model):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 if model.header.valid and 'Physical_Colour' in model.header.qualifiers:
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 yield report_problem(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 'physical-colour-part',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 bad_object = model.find_first_header_object('part type'),
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 @problem_type('unofficial-part',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 message = 'new parts must be unofficial',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 def unofficiality_test(model):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 if model.header.valid and not model.header.filetype.startswith('Unofficial_'):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 yield report_problem(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 'unofficial-part',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 bad_object = model.find_first_header_object('part type')
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69
127
97de6058109e added bfc declaration tests
Teemu Piippo <teemu@hecknology.net>
parents: 105
diff changeset
70 @problem_type('primitive-non-ccw',
105
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 message = 'primitives must have CCW winding',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 @problem_type('no-bfc-line',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 message = 'BFC declaration is missing',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 def header_bfc_test(model):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 if model.header.valid and not model.header.bfc:
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 yield report_problem(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 'no-bfc-line',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 bad_object = model.body[0],
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 elif model.header.valid \
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 and model.header.filetype.endswith('Primitive') \
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86 and model.header.bfc != 'CERTIFY CCW':
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87 yield report_problem(
127
97de6058109e added bfc declaration tests
Teemu Piippo <teemu@hecknology.net>
parents: 105
diff changeset
88 'primitive-non-ccw',
105
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 bad_object = model.find_first_header_object('bfc'),
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92 @problem_type('keywords-for-nonparts',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 severity = 'warning',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94 message = lambda type: str.format(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 'keywords are not allowed for {type} files',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 type = type,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 ),
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
99 def keywords_tests(model):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 if model.header.valid:
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 if model.header.keywords \
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 and model.header.effective_filetype != 'Part':
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 yield report_problem(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 'keywords-for-nonparts',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 bad_object = model.find_first_header_object('keywords'),
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 type = model.header.effective_filetype,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
108
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
109 @problem_type('bad-colour-24-nonline',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
110 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
111 message = 'colour 24 used on non-lines',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
112 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
113 @problem_type('bad-colour-24-line',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
114 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
115 message = 'line with colour other than 24',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
116 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
117 def colour_24_test(model):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
118 for element in model.body:
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
119 if hasattr(element, 'colour'):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
120 is_line = isinstance(element, linetypes.LineSegment)
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
121 if not is_line and element.colour.index == 24:
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
122 yield report_problem('bad-colour-24-nonline', bad_object = element)
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
123 if is_line and element.colour.index != 24:
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
124 yield report_problem('bad-colour-24-line', bad_object = element)
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
125
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
126 @problem_type('moved-to-with-extension',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
127 severity = 'hold',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
128 message = 'moved-to files must not contain the '
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
129 '".dat"-extension in the description',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
131 def moved_to_with_extension_test(model):
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
132 if model.header.valid \
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
133 and model.header.description.startswith('~Moved to') \
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
134 and '.dat' in model.header.description:
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
135 yield report_problem(
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
136 'moved-to-with-extension',
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
137 bad_object = model.body[0],
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
138 )
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
139
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
140 manifest = {
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
141 'tests': [
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
142 bad_header,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
143 nocertify_test,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
144 physical_colours_test,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
145 unofficiality_test,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
146 header_bfc_test,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
147 keywords_tests,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148 colour_24_test,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
149 moved_to_with_extension_test,
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
150 ],
43c367c8895b split header tests into their own file
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
151 }

mercurial