1 from testsuite import warning |
1 from testsuite import error, warning |
|
2 import linetypes |
2 |
3 |
3 def colours_test(model): |
4 def colours_test(model): |
4 ''' Checks that all colours used in the part model are valid. ''' |
5 ''' Checks that all colours used in the part model are valid. ''' |
5 yield from ( |
6 yield from ( |
6 warning(element, 'bad-colour', colour_index = element.colour.index) |
7 warning(element, 'bad-colour', colour_index = element.colour.index) |
7 for element in model.body |
8 for element in model.body |
8 if hasattr(element, 'colour') and not element.colour.is_valid |
9 if hasattr(element, 'colour') and not element.colour.is_valid |
9 ) |
10 ) |
10 |
11 |
|
12 def syntax_errors(model): |
|
13 yield from ( |
|
14 error(element, 'syntax-error', reason = element.reason) |
|
15 for element in model.body |
|
16 if isinstance(element, linetypes.Error) |
|
17 ) |
|
18 |
11 manifest = { |
19 manifest = { |
12 'tests': { |
20 'tests': { |
13 'colour-validity': colours_test, |
21 'colour-validity': colours_test, |
|
22 'syntax-errors': syntax_errors, |
14 }, |
23 }, |
15 'messages': { |
24 'messages': { |
16 'bad-colour': lambda colour_index: str.format( |
25 'bad-colour': lambda colour_index: str.format( |
17 'invalid colour {}', |
26 'invalid colour {}', |
18 colour_index, |
27 colour_index, |
19 ), |
28 ), |
|
29 'syntax-error': lambda reason: str.format( |
|
30 'syntax error: {}', |
|
31 reason, |
|
32 ), |
20 }, |
33 }, |
21 } |
34 } |