tests/misc.py

Sat, 01 Jun 2019 10:47:58 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 01 Jun 2019 10:47:58 +0300
changeset 56
ed6d39c59e56
parent 50
0193f8820ba8
child 62
f0a6bf48b05e
permissions
-rw-r--r--

fixed BFC INVERTNEXT being interpreted as a header command

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
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
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
28 def nocertify_test(model):
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
29 import header
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
30 if model.header.valid and model.header.bfc == 'NOCERTIFY':
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
31 yield error(
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
32 model.body[model.header.first_occurrence['bfc']],
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
33 'bfc-nocertify')
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
34
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
35 def physical_colours_test(model):
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
36 if model.header.valid and 'Physical_Colour' in model.header.qualifiers:
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
37 yield error(
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
38 model.body[model.header.first_occurrence['part type']],
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
39 'physical-colour')
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
40
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
41 def unofficiality_test(model):
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
42 if model.header.valid and not model.header.filetype.startswith('Unofficial_'):
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
43 yield error(
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
44 model.body[model.header.first_occurrence['part type']],
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
45 'unofficial-type')
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
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
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
55 manifest = {
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
56 'tests': {
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
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
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
60 'bfc-nocertify': nocertify_test,
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
61 'physical-colour': physical_colours_test,
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
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
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
64 },
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
65 'messages': {
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
66 'bad-colour': lambda colour_index: str.format(
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
67 'invalid colour {}',
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
68 colour_index,
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
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
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
78 'bfc-nocertify': 'all new parts must be BFC certified',
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
79 'physical-colour': 'no new physical colour parts are accepted',
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
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
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
82 },
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
83 }

mercurial