1 from testsuite import problem_type, report_problem |
1 from testsuite import problem_type, report_problem |
2 import linetypes |
2 import linetypes |
3 |
3 |
4 @problem_type('bad-colour', |
4 @problem_type('bad-colour', |
5 severity = 'error', |
5 severity = 'hold', |
6 message = lambda colour_index, count: str.format( |
6 message = lambda colour_index, count: str.format( |
7 'invalid colour {} used {} time(s)', |
7 'invalid colour {} used {} time(s)', |
8 colour_index, |
8 colour_index, |
9 count, |
9 count, |
10 ), |
10 ), |
27 ) |
27 ) |
28 for colour_index, bad_colour in bad_colours.items() |
28 for colour_index, bad_colour in bad_colours.items() |
29 ] |
29 ] |
30 |
30 |
31 @problem_type('syntax-error', |
31 @problem_type('syntax-error', |
32 severity = 'error', |
32 severity = 'hold', |
33 message = lambda reason: str.format('syntax error: {}', reason), |
33 message = lambda reason: str.format('syntax error: {}', reason), |
34 ) |
34 ) |
35 def syntax_errors(model): |
35 def syntax_errors(model): |
36 yield from ( |
36 yield from ( |
37 report_problem('syntax-error', |
37 report_problem('syntax-error', |
41 for element in model.body |
41 for element in model.body |
42 if isinstance(element, linetypes.Error) |
42 if isinstance(element, linetypes.Error) |
43 ) |
43 ) |
44 |
44 |
45 @problem_type('bad-header', |
45 @problem_type('bad-header', |
46 severity = 'error', |
46 severity = 'hold', |
47 message = lambda reason: str.format('bad header: {}', reason), |
47 message = lambda reason: str.format('bad header: {}', reason), |
48 ) |
48 ) |
49 def bad_header(model): |
49 def bad_header(model): |
50 import header |
50 import header |
51 if isinstance(model.header, header.BadHeader): |
51 if isinstance(model.header, header.BadHeader): |
54 bad_object = model.body[model.header.index], |
54 bad_object = model.body[model.header.index], |
55 reason = model.header.reason, |
55 reason = model.header.reason, |
56 ) |
56 ) |
57 |
57 |
58 @problem_type('bfc-nocertify', |
58 @problem_type('bfc-nocertify', |
59 severity = 'error', |
59 severity = 'hold', |
60 message = 'all new parts must be BFC certified', |
60 message = 'all new parts must be BFC certified', |
61 ) |
61 ) |
62 def nocertify_test(model): |
62 def nocertify_test(model): |
63 import header |
63 import header |
64 if model.header.valid and model.header.bfc == 'NOCERTIFY': |
64 if model.header.valid and model.header.bfc == 'NOCERTIFY': |
66 'bfc-nocertify', |
66 'bfc-nocertify', |
67 bad_object = model.body[model.header.first_occurrence['bfc']], |
67 bad_object = model.body[model.header.first_occurrence['bfc']], |
68 ) |
68 ) |
69 |
69 |
70 @problem_type('physical-colour-part', |
70 @problem_type('physical-colour-part', |
71 severity = 'error', |
71 severity = 'hold', |
72 message = 'no new physical colour parts are accepted', |
72 message = 'no new physical colour parts are accepted', |
73 ) |
73 ) |
74 def physical_colours_test(model): |
74 def physical_colours_test(model): |
75 if model.header.valid and 'Physical_Colour' in model.header.qualifiers: |
75 if model.header.valid and 'Physical_Colour' in model.header.qualifiers: |
76 yield report_problem( |
76 yield report_problem( |
77 'physical-colour-part', |
77 'physical-colour-part', |
78 bad_object = model.body[model.header.first_occurrence['part type']], |
78 bad_object = model.body[model.header.first_occurrence['part type']], |
79 ) |
79 ) |
80 |
80 |
81 @problem_type('official-part', |
81 @problem_type('official-part', |
82 severity = 'error', |
82 severity = 'hold', |
83 message = 'new parts must be unofficial', |
83 message = 'new parts must be unofficial', |
84 ) |
84 ) |
85 def unofficiality_test(model): |
85 def unofficiality_test(model): |
86 if model.header.valid and not model.header.filetype.startswith('Unofficial_'): |
86 if model.header.valid and not model.header.filetype.startswith('Unofficial_'): |
87 yield report_problem( |
87 yield report_problem( |
88 'unofficial-part', |
88 'unofficial-part', |
89 bad_object = model.body[model.header.first_occurrence['part type']]) |
89 bad_object = model.body[model.header.first_occurrence['part type']]) |
90 |
90 |
91 @problem_type('primitive-ccw', |
91 @problem_type('primitive-ccw', |
92 severity = 'error', |
92 severity = 'hold', |
93 message = 'primitives must have CCW winding', |
93 message = 'primitives must have CCW winding', |
94 ) |
94 ) |
95 def primitive_ccw_test(model): |
95 def primitive_ccw_test(model): |
96 if model.header.valid \ |
96 if model.header.valid \ |
97 and model.header.filetype.endswith('Primitive') \ |
97 and model.header.filetype.endswith('Primitive') \ |