Sat, 22 Jun 2019 23:38:51 +0300
complain about missing BFC declarations
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
1 | from testsuite import problem_type, report_problem |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
2 | import linetypes |
25 | 3 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
4 | @problem_type('bad-colour', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
5 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
6 | message = lambda colour_index, count: str.format( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
7 | 'invalid colour {} used {} time(s)', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
8 | colour_index, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
9 | count, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
10 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
11 | ) |
25 | 12 | def colours_test(model): |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
25
diff
changeset
|
13 | ''' Checks that all colours used in the part model are valid. ''' |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
14 | from collections import defaultdict |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
15 | bad_colours = defaultdict(lambda: {'count': 0, 'first-occurrence': None}) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
16 | for element in model.body: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
17 | if hasattr(element, 'colour') and not element.colour.is_valid: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
18 | bad_colours[element.colour.index]['count'] += 1 |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
19 | if not bad_colours[element.colour.index]['first-occurrence']: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
20 | bad_colours[element.colour.index]['first-occurrence'] = element |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
21 | yield from [ |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
22 | report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
23 | 'bad-colour', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
24 | bad_object = bad_colour['first-occurrence'], |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
25 | colour_index = colour_index, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
26 | count = bad_colour['count'], |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
27 | ) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
28 | for colour_index, bad_colour in bad_colours.items() |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
29 | ] |
25 | 30 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
31 | @problem_type('syntax-error', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
32 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
33 | message = lambda reason: str.format('syntax error: {}', reason), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
34 | ) |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
35 | def syntax_errors(model): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
36 | yield from ( |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
37 | report_problem('syntax-error', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
38 | bad_object = element, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
39 | reason = element.reason |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
40 | ) |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
41 | for element in model.body |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
42 | if isinstance(element, linetypes.Error) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
43 | ) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
44 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
45 | @problem_type('bad-header', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
46 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
47 | message = lambda reason: str.format('bad header: {}', reason), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
48 | ) |
47
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
49 | def bad_header(model): |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
50 | import header |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
51 | if isinstance(model.header, header.BadHeader): |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
52 | yield report_problem( |
47
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
53 | 'bad-header', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
54 | bad_object = model.body[model.header.index], |
47
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
55 | reason = model.header.reason, |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
56 | ) |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
57 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
58 | @problem_type('bfc-nocertify', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
59 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
60 | message = 'all new parts must be BFC certified', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
61 | ) |
48 | 62 | def nocertify_test(model): |
63 | import header | |
64 | if model.header.valid and model.header.bfc == 'NOCERTIFY': | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
65 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
66 | 'bfc-nocertify', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
67 | bad_object = model.body[model.header.first_occurrence['bfc']], |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
68 | ) |
48 | 69 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
70 | @problem_type('physical-colour-part', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
71 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
72 | message = 'no new physical colour parts are accepted', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
73 | ) |
48 | 74 | def physical_colours_test(model): |
75 | if model.header.valid and 'Physical_Colour' in model.header.qualifiers: | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
76 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
77 | 'physical-colour-part', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
78 | bad_object = model.body[model.header.first_occurrence['part type']], |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
79 | ) |
48 | 80 | |
66
e28b249b4422
Fix unofficial part test
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
81 | @problem_type('unofficial-part', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
82 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
83 | message = 'new parts must be unofficial', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
84 | ) |
48 | 85 | def unofficiality_test(model): |
86 | if model.header.valid and not model.header.filetype.startswith('Unofficial_'): | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
87 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
88 | 'unofficial-part', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
89 | bad_object = model.body[model.header.first_occurrence['part type']]) |
48 | 90 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
91 | @problem_type('primitive-ccw', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
92 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
93 | message = 'primitives must have CCW winding', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
94 | ) |
68
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
95 | @problem_type('no-bfc-line', |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
96 | severity = 'hold', |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
97 | message = 'BFC declaration is missing', |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
98 | ) |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
99 | def header_bfc_test(model): |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
100 | def find_the_bfc_object(model): |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
101 | return model.body[model.header.first_occurrence['bfc']], |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
102 | if model.header.valid and not model.header.bfc: |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
103 | yield report_problem( |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
104 | 'no-bfc-line', |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
105 | bad_object = model.body[0], |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
106 | ) |
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
107 | elif model.header.valid \ |
50
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
108 | and model.header.filetype.endswith('Primitive') \ |
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
109 | and model.header.bfc != 'CERTIFY CCW': |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
110 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
111 | 'primitive-bfc-ccw', |
68
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
112 | bad_object = find_the_bfc_object(model), |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
113 | ) |
50
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
114 | |
25 | 115 | manifest = { |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
116 | 'tests': [ |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
117 | colours_test, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
118 | syntax_errors, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
119 | bad_header, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
120 | nocertify_test, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
121 | physical_colours_test, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
122 | unofficiality_test, |
68
c19dd0d3248e
complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents:
66
diff
changeset
|
123 | header_bfc_test, |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
50
diff
changeset
|
124 | ], |
25 | 125 | } |