Fri, 24 May 2019 17:37:10 +0200
added proper handling of syntax errors
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 | |
25 | 19 | manifest = { |
20 | 'tests': { | |
21 | 'colour-validity': colours_test, | |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
22 | 'syntax-errors': syntax_errors, |
25 | 23 | }, |
24 | 'messages': { | |
25 | 'bad-colour': lambda colour_index: str.format( | |
26 | 'invalid colour {}', | |
27 | colour_index, | |
28 | ), | |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
29 | 'syntax-error': lambda reason: str.format( |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
30 | 'syntax error: {}', |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
31 | reason, |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
32 | ), |
25 | 33 | }, |
34 | } |