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