Wed, 29 May 2019 16:36:23 +0300
fixed the formatting of the license
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
1 | from testsuite import error, warning |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
2 | import linetypes |
25 | 3 | |
4 | def colours_test(model): | |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
25
diff
changeset
|
5 | ''' Checks that all colours used in the part model are valid. ''' |
25 | 6 | yield from ( |
7 | warning(element, 'bad-colour', colour_index = element.colour.index) | |
8 | for element in model.body | |
9 | if hasattr(element, 'colour') and not element.colour.is_valid | |
10 | ) | |
11 | ||
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
12 | def syntax_errors(model): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
13 | yield from ( |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
14 | error(element, 'syntax-error', reason = element.reason) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
15 | for element in model.body |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
16 | if isinstance(element, linetypes.Error) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
17 | ) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
18 | |
47
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
19 | def bad_header(model): |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
20 | import header |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
21 | if isinstance(model.header, header.BadHeader): |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
22 | yield error( |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
23 | model.body[model.header.index], |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
24 | 'bad-header', |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
25 | reason = model.header.reason, |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
26 | ) |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
27 | |
48 | 28 | def nocertify_test(model): |
29 | import header | |
30 | if model.header.valid and model.header.bfc == 'NOCERTIFY': | |
31 | yield error( | |
32 | model.body[model.header.first_occurrence['bfc']], | |
33 | 'bfc-nocertify') | |
34 | ||
35 | def physical_colours_test(model): | |
36 | if model.header.valid and 'Physical_Colour' in model.header.qualifiers: | |
37 | yield error( | |
38 | model.body[model.header.first_occurrence['part type']], | |
39 | 'physical-colour') | |
40 | ||
41 | def unofficiality_test(model): | |
42 | if model.header.valid and not model.header.filetype.startswith('Unofficial_'): | |
43 | yield error( | |
44 | model.body[model.header.first_occurrence['part type']], | |
45 | 'unofficial-type') | |
46 | ||
50
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
47 | def primitive_ccw_test(model): |
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
48 | if model.header.valid \ |
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
49 | and model.header.filetype.endswith('Primitive') \ |
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
50 | and model.header.bfc != 'CERTIFY CCW': |
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
51 | yield error( |
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
52 | model.body[model.header.first_occurrence['bfc']], |
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
53 | 'primitive-bfc-ccw') |
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
54 | |
25 | 55 | manifest = { |
56 | 'tests': { | |
57 | 'colour-validity': colours_test, | |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
58 | 'syntax-errors': syntax_errors, |
47
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
59 | 'header-validity': bad_header, |
48 | 60 | 'bfc-nocertify': nocertify_test, |
61 | 'physical-colour': physical_colours_test, | |
62 | 'unofficial-type': unofficiality_test, | |
50
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
63 | 'primitive-ccw': primitive_ccw_test, |
25 | 64 | }, |
65 | 'messages': { | |
66 | 'bad-colour': lambda colour_index: str.format( | |
67 | 'invalid colour {}', | |
68 | colour_index, | |
69 | ), | |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
70 | 'syntax-error': lambda reason: str.format( |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
71 | 'syntax error: {}', |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
72 | reason, |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
73 | ), |
47
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
74 | 'bad-header': lambda reason: str.format( |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
75 | 'bad header: {}', |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
76 | reason, |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
77 | ), |
48 | 78 | 'bfc-nocertify': 'all new parts must be BFC certified', |
79 | 'physical-colour': 'no new physical colour parts are accepted', | |
80 | 'unofficial-type': 'new parts must be unofficial', | |
50
0193f8820ba8
added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
81 | 'primitive-bfc-ccw': 'primitives must have CCW winding', |
25 | 82 | }, |
83 | } |