tests/misc.py

Fri, 24 May 2019 17:44:04 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 24 May 2019 17:44:04 +0200
changeset 39
abc83875167e
parent 38
66c9591b733d
child 47
4da025d0b283
permissions
-rw-r--r--

fix stylesheet

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
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
3
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
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
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
6 yield from (
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
7 warning(element, 'bad-colour', colour_index = element.colour.index)
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
8 for element in model.body
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
9 if hasattr(element, 'colour') and not element.colour.is_valid
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
10 )
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
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
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
19 manifest = {
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
20 'tests': {
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
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
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
23 },
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
24 'messages': {
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
25 'bad-colour': lambda colour_index: str.format(
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
26 'invalid colour {}',
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
27 colour_index,
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
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
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
33 },
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
34 }

mercurial