tests/misc.py

changeset 69
a24c4490d9f2
parent 68
c19dd0d3248e
child 70
2453681c6a69
equal deleted inserted replaced
68:c19dd0d3248e 69:a24c4490d9f2
62 def nocertify_test(model): 62 def nocertify_test(model):
63 import header 63 import header
64 if model.header.valid and model.header.bfc == 'NOCERTIFY': 64 if model.header.valid and model.header.bfc == 'NOCERTIFY':
65 yield report_problem( 65 yield report_problem(
66 'bfc-nocertify', 66 'bfc-nocertify',
67 bad_object = model.body[model.header.first_occurrence['bfc']], 67 bad_object = model.find_first_header_object('bfc'),
68 ) 68 )
69 69
70 @problem_type('physical-colour-part', 70 @problem_type('physical-colour-part',
71 severity = 'hold', 71 severity = 'hold',
72 message = 'no new physical colour parts are accepted', 72 message = 'no new physical colour parts are accepted',
73 ) 73 )
74 def physical_colours_test(model): 74 def physical_colours_test(model):
75 if model.header.valid and 'Physical_Colour' in model.header.qualifiers: 75 if model.header.valid and 'Physical_Colour' in model.header.qualifiers:
76 yield report_problem( 76 yield report_problem(
77 'physical-colour-part', 77 'physical-colour-part',
78 bad_object = model.body[model.header.first_occurrence['part type']], 78 bad_object = model.find_first_header_object('part type'),
79 ) 79 )
80 80
81 @problem_type('unofficial-part', 81 @problem_type('unofficial-part',
82 severity = 'hold', 82 severity = 'hold',
83 message = 'new parts must be unofficial', 83 message = 'new parts must be unofficial',
84 ) 84 )
85 def unofficiality_test(model): 85 def unofficiality_test(model):
86 if model.header.valid and not model.header.filetype.startswith('Unofficial_'): 86 if model.header.valid and not model.header.filetype.startswith('Unofficial_'):
87 yield report_problem( 87 yield report_problem(
88 'unofficial-part', 88 'unofficial-part',
89 bad_object = model.body[model.header.first_occurrence['part type']]) 89 bad_object = model.find_first_header_object('part type')
90 )
90 91
91 @problem_type('primitive-ccw', 92 @problem_type('primitive-ccw',
92 severity = 'hold', 93 severity = 'hold',
93 message = 'primitives must have CCW winding', 94 message = 'primitives must have CCW winding',
94 ) 95 )
95 @problem_type('no-bfc-line', 96 @problem_type('no-bfc-line',
96 severity = 'hold', 97 severity = 'hold',
97 message = 'BFC declaration is missing', 98 message = 'BFC declaration is missing',
98 ) 99 )
99 def header_bfc_test(model): 100 def header_bfc_test(model):
100 def find_the_bfc_object(model):
101 return model.body[model.header.first_occurrence['bfc']],
102 if model.header.valid and not model.header.bfc: 101 if model.header.valid and not model.header.bfc:
103 yield report_problem( 102 yield report_problem(
104 'no-bfc-line', 103 'no-bfc-line',
105 bad_object = model.body[0], 104 bad_object = model.body[0],
106 ) 105 )
107 elif model.header.valid \ 106 elif model.header.valid \
108 and model.header.filetype.endswith('Primitive') \ 107 and model.header.filetype.endswith('Primitive') \
109 and model.header.bfc != 'CERTIFY CCW': 108 and model.header.bfc != 'CERTIFY CCW':
110 yield report_problem( 109 yield report_problem(
111 'primitive-bfc-ccw', 110 'primitive-bfc-ccw',
112 bad_object = find_the_bfc_object(model), 111 bad_object = model.find_first_header_object('bfc'),
113 ) 112 )
113
114 @problem_type('keywords-for-nonparts',
115 severity = 'warning',
116 message = lambda type: str.format(
117 'Keywords are not allowed for {type} files',
118 type = type,
119 ),
120 )
121 def keywords_tests(model):
122 if model.header.valid:
123 if model.header.keywords \
124 and model.header.effective_filetype != 'Part':
125 yield report_problem(
126 'keywords-for-nonparts',
127 bad_object = model.find_first_header_object('keywords'),
128 type = model.header.effective_filetype,
129 )
114 130
115 manifest = { 131 manifest = {
116 'tests': [ 132 'tests': [
117 colours_test, 133 colours_test,
118 syntax_errors, 134 syntax_errors,
119 bad_header, 135 bad_header,
120 nocertify_test, 136 nocertify_test,
121 physical_colours_test, 137 physical_colours_test,
122 unofficiality_test, 138 unofficiality_test,
123 header_bfc_test, 139 header_bfc_test,
140 keywords_tests,
124 ], 141 ],
125 } 142 }

mercurial