tests/misc.py

Mon, 24 Jun 2019 11:48:52 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 24 Jun 2019 11:48:52 +0300
changeset 91
c71a7d863c2e
parent 88
6a0b43a5dec0
child 94
109fb7cf658f
permissions
-rw-r--r--

removed the typename methods

62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
1 from testsuite import problem_type, report_problem
38
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
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
4 @problem_type('bad-colour',
64
1c0884f5506e changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
5 severity = 'hold',
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
6 message = lambda colour_index, count: str.format(
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
7 'invalid colour {} used {} time(s)',
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
8 colour_index,
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
9 count,
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
10 ),
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
11 )
25
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
12 def colours_test(model):
26
7c263b864371 Added command line option to list all checks.
Santeri Piippo
parents: 25
diff changeset
13 ''' Checks that all colours used in the part model are valid. '''
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
14 from collections import defaultdict
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
15 bad_colours = defaultdict(lambda: {'count': 0, 'first-occurrence': None})
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
16 for element in model.body:
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
17 if hasattr(element, 'colour') and not element.colour.is_valid:
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
18 bad_colours[element.colour.index]['count'] += 1
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
19 if not bad_colours[element.colour.index]['first-occurrence']:
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
20 bad_colours[element.colour.index]['first-occurrence'] = element
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
21 yield from [
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
22 report_problem(
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
23 'bad-colour',
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
24 bad_object = bad_colour['first-occurrence'],
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
25 colour_index = colour_index,
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
26 count = bad_colour['count'],
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
27 )
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
28 for colour_index, bad_colour in bad_colours.items()
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
29 ]
25
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
30
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
31 @problem_type('syntax-error',
64
1c0884f5506e changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
32 severity = 'hold',
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
33 message = lambda reason: str.format('syntax error: {}', reason),
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
34 )
38
66c9591b733d added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
35 def syntax_errors(model):
66c9591b733d added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
36 yield from (
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
37 report_problem('syntax-error',
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
38 bad_object = element,
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
39 reason = element.reason
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
40 )
38
66c9591b733d added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
41 for element in model.body
66c9591b733d added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
42 if isinstance(element, linetypes.Error)
66c9591b733d added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
43 )
66c9591b733d added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
44
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
45 @problem_type('bad-header',
64
1c0884f5506e changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
46 severity = 'hold',
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
47 message = lambda reason: str.format('bad header: {}', reason),
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
48 )
86
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
49 @problem_type('no-license-set',
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
50 severity = 'hold',
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
51 message = 'no license set',
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
52 )
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
53 @problem_type('non-ca-license',
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
54 severity = 'hold',
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
55 message = 'no new non-CA-submits are accepted',
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
56 )
47
4da025d0b283 added work on header check
Teemu Piippo <teemu@hecknology.net>
parents: 38
diff changeset
57 def bad_header(model):
4da025d0b283 added work on header check
Teemu Piippo <teemu@hecknology.net>
parents: 38
diff changeset
58 import header
86
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
59 ca_license = 'Redistributable under CCAL version 2.0 : see CAreadme.txt'
47
4da025d0b283 added work on header check
Teemu Piippo <teemu@hecknology.net>
parents: 38
diff changeset
60 if isinstance(model.header, header.BadHeader):
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
61 yield report_problem(
47
4da025d0b283 added work on header check
Teemu Piippo <teemu@hecknology.net>
parents: 38
diff changeset
62 'bad-header',
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
63 bad_object = model.body[model.header.index],
47
4da025d0b283 added work on header check
Teemu Piippo <teemu@hecknology.net>
parents: 38
diff changeset
64 reason = model.header.reason,
4da025d0b283 added work on header check
Teemu Piippo <teemu@hecknology.net>
parents: 38
diff changeset
65 )
86
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
66 elif not model.header.license:
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
67 yield report_problem(
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
68 'no-license-set',
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
69 bad_object = model.body[0],
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
70 )
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
71 elif model.header.license != ca_license:
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
72 yield report_problem(
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
73 'non-ca-license',
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
74 bad_object = model.find_first_header_object('license'),
b25fc6f7eb70 added tests for missing license and non-CA
Teemu Piippo <teemu@hecknology.net>
parents: 78
diff changeset
75 )
47
4da025d0b283 added work on header check
Teemu Piippo <teemu@hecknology.net>
parents: 38
diff changeset
76
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
77 @problem_type('bfc-nocertify',
64
1c0884f5506e changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
78 severity = 'hold',
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
79 message = 'all new parts must be BFC certified',
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
80 )
48
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
81 def nocertify_test(model):
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
82 import header
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
83 if model.header.valid and model.header.bfc == 'NOCERTIFY':
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
84 yield report_problem(
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
85 'bfc-nocertify',
69
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
86 bad_object = model.find_first_header_object('bfc'),
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
87 )
48
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
88
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
89 @problem_type('physical-colour-part',
64
1c0884f5506e changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
90 severity = 'hold',
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
91 message = 'no new physical colour parts are accepted',
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
92 )
48
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
93 def physical_colours_test(model):
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
94 if model.header.valid and 'Physical_Colour' in model.header.qualifiers:
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
95 yield report_problem(
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
96 'physical-colour-part',
69
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
97 bad_object = model.find_first_header_object('part type'),
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
98 )
48
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
99
66
e28b249b4422 Fix unofficial part test
Teemu Piippo <teemu@hecknology.net>
parents: 64
diff changeset
100 @problem_type('unofficial-part',
64
1c0884f5506e changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
101 severity = 'hold',
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
102 message = 'new parts must be unofficial',
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
103 )
48
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
104 def unofficiality_test(model):
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
105 if model.header.valid and not model.header.filetype.startswith('Unofficial_'):
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
106 yield report_problem(
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
107 'unofficial-part',
69
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
108 bad_object = model.find_first_header_object('part type')
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
109 )
48
38b0919c1934 added some header tests
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
110
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
111 @problem_type('primitive-ccw',
64
1c0884f5506e changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
112 severity = 'hold',
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
113 message = 'primitives must have CCW winding',
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
114 )
68
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
115 @problem_type('no-bfc-line',
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
116 severity = 'hold',
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
117 message = 'BFC declaration is missing',
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
118 )
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
119 def header_bfc_test(model):
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
120 if model.header.valid and not model.header.bfc:
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
121 yield report_problem(
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
122 'no-bfc-line',
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
123 bad_object = model.body[0],
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
124 )
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
125 elif model.header.valid \
50
0193f8820ba8 added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
126 and model.header.filetype.endswith('Primitive') \
0193f8820ba8 added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
127 and model.header.bfc != 'CERTIFY CCW':
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
128 yield report_problem(
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
129 'primitive-bfc-ccw',
69
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
130 bad_object = model.find_first_header_object('bfc'),
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
131 )
50
0193f8820ba8 added primitive CCW test
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
132
69
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
133 @problem_type('keywords-for-nonparts',
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
134 severity = 'warning',
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
135 message = lambda type: str.format(
71
4e24867a0110 fix capitalization
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
136 'keywords are not allowed for {type} files',
69
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
137 type = type,
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
138 ),
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
139 )
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
140 def keywords_tests(model):
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
141 if model.header.valid:
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
142 if model.header.keywords \
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
143 and model.header.effective_filetype != 'Part':
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
144 yield report_problem(
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
145 'keywords-for-nonparts',
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
146 bad_object = model.find_first_header_object('keywords'),
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
147 type = model.header.effective_filetype,
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
148 )
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
149
70
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
150 @problem_type('bad-colour-24-nonline',
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
151 severity = 'hold',
71
4e24867a0110 fix capitalization
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
152 message = 'colour 24 used on non-lines',
70
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
153 )
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
154 @problem_type('bad-colour-24-line',
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
155 severity = 'hold',
71
4e24867a0110 fix capitalization
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
156 message = 'line with colour other than 24',
70
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
157 )
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
158 def colour_24_test(model):
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
159 for element in model.body:
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
160 if hasattr(element, 'colour'):
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
161 is_line = isinstance(element, linetypes.LineSegment)
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
162 if not is_line and element.colour.index == 24:
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
163 yield report_problem('bad-colour-24-nonline', bad_object = element)
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
164 if is_line and element.colour.index != 24:
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
165 yield report_problem('bad-colour-24-line', bad_object = element)
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
166
74
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
167 @problem_type('moved-to-with-extension',
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
168 severity = 'hold',
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
169 message = 'moved-to files must not contain the '
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
170 '".dat"-extension in the description',
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
171 )
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
172 def moved_to_with_extension_test(model):
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
173 if model.header.valid \
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
174 and model.header.description.startswith('~Moved to') \
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
175 and '.dat' in model.header.description:
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
176 yield report_problem(
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
177 'moved-to-with-extension',
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
178 bad_object = model.body[0],
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
179 )
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
180
75
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
181 @problem_type('bfc-invertnext-not-on-subfile',
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
182 severity = 'hold',
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
183 message = '"BFC INVERTNEXT" not followed by a type-1 line',
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
184 )
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
185 def bfc_invertnext_not_on_subfile_test(model):
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
186 def get_invertnexts(model):
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
187 yield from [
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
188 (index, element)
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
189 for index, element in enumerate(model.body)
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
190 if isinstance(element, linetypes.MetaCommand) \
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
191 and element.text == 'BFC INVERTNEXT'
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
192 ]
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
193 def has_subfile_after_invertnext(index):
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
194 index_subfile = index + 1 # subfile reference should be on the next line
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
195 if index_subfile >= len(model.body):
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
196 return False # past the end...
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
197 else:
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
198 element = model.body[index_subfile]
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
199 return isinstance(element, linetypes.SubfileReference)
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
200 for index, invertnext in get_invertnexts(model):
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
201 if not has_subfile_after_invertnext(index):
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
202 yield report_problem('bfc-invertnext-not-on-subfile',
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
203 bad_object = model.body[index],
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
204 )
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
205
78
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
206 @problem_type('unknown-metacommand',
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
207 severity = 'hold',
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
208 message = lambda command_text: str.format(
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
209 'unknown or deprecated metacommand: {command_text}',
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
210 command_text = command_text,
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
211 )
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
212 )
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
213 def metacommands_test(model):
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
214 allowed_metacommand_patterns = [
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
215 r'^BFC (CLIP|NOCLIP|INVERTNEXT)$',
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
216 r'^\!TEXMAP (START|NEXT) .+',
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
217 r'^\!: .+',
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
218 r'^\!TEXMAP (FALLBACK|END)$',
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
219 ]
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
220 import re
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
221 for element in model.body[model.header_size:]:
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
222 if isinstance(element, linetypes.MetaCommand):
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
223 if element.text and not any(
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
224 re.match(pattern, element.text)
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
225 for pattern in allowed_metacommand_patterns
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
226 ):
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
227 yield report_problem('unknown-metacommand',
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
228 bad_object = element,
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
229 command_text = element.text,
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
230 )
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
231
25
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
232 manifest = {
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
233 'tests': [
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
234 colours_test,
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
235 syntax_errors,
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
236 bad_header,
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
237 nocertify_test,
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
238 physical_colours_test,
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
239 unofficiality_test,
68
c19dd0d3248e complain about missing BFC declarations
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
240 header_bfc_test,
69
a24c4490d9f2 added a check for keywords in non-parts
Teemu Piippo <teemu@hecknology.net>
parents: 68
diff changeset
241 keywords_tests,
70
2453681c6a69 added tests for colour 24 usage
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
242 colour_24_test,
74
831d9f81a48c added a test for ".dat"-extensions in the description
Teemu Piippo <teemu@hecknology.net>
parents: 71
diff changeset
243 moved_to_with_extension_test,
75
3ec747dfbfb9 added a test for BFC INVERTNEXT not followed by a type-1 line
Teemu Piippo <teemu@hecknology.net>
parents: 74
diff changeset
244 bfc_invertnext_not_on_subfile_test,
78
1970afe52da4 added a test for unknown metacommands
Teemu Piippo <teemu@hecknology.net>
parents: 75
diff changeset
245 metacommands_test,
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 50
diff changeset
246 ],
25
8990ac138cc2 added check for invalid colours
Santeri Piippo
parents:
diff changeset
247 }

mercurial