Tue, 28 May 2019 19:10:52 +0300
fix LDRAW_ORG parsing
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 | ||
25 | 47 | manifest = { |
48 | 'tests': { | |
49 | 'colour-validity': colours_test, | |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
50 | 'syntax-errors': syntax_errors, |
47
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
51 | 'header-validity': bad_header, |
48 | 52 | 'bfc-nocertify': nocertify_test, |
53 | 'physical-colour': physical_colours_test, | |
54 | 'unofficial-type': unofficiality_test, | |
25 | 55 | }, |
56 | 'messages': { | |
57 | 'bad-colour': lambda colour_index: str.format( | |
58 | 'invalid colour {}', | |
59 | colour_index, | |
60 | ), | |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
61 | 'syntax-error': lambda reason: str.format( |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
62 | 'syntax error: {}', |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
63 | reason, |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
64 | ), |
47
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
65 | 'bad-header': lambda reason: str.format( |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
66 | 'bad header: {}', |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
67 | reason, |
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
68 | ), |
48 | 69 | 'bfc-nocertify': 'all new parts must be BFC certified', |
70 | 'physical-colour': 'no new physical colour parts are accepted', | |
71 | 'unofficial-type': 'new parts must be unofficial', | |
25 | 72 | }, |
73 | } |