Wed, 05 Jun 2019 00:33:50 +0300
show the filename of the processed file in the report
from testsuite import error, warning import linetypes def colours_test(model): ''' Checks that all colours used in the part model are valid. ''' yield from ( warning(element, 'bad-colour', colour_index = element.colour.index) for element in model.body if hasattr(element, 'colour') and not element.colour.is_valid ) def syntax_errors(model): yield from ( error(element, 'syntax-error', reason = element.reason) for element in model.body if isinstance(element, linetypes.Error) ) def bad_header(model): import header if isinstance(model.header, header.BadHeader): yield error( model.body[model.header.index], 'bad-header', reason = model.header.reason, ) def nocertify_test(model): import header if model.header.valid and model.header.bfc == 'NOCERTIFY': yield error( model.body[model.header.first_occurrence['bfc']], 'bfc-nocertify') def physical_colours_test(model): if model.header.valid and 'Physical_Colour' in model.header.qualifiers: yield error( model.body[model.header.first_occurrence['part type']], 'physical-colour') def unofficiality_test(model): if model.header.valid and not model.header.filetype.startswith('Unofficial_'): yield error( model.body[model.header.first_occurrence['part type']], 'unofficial-type') def primitive_ccw_test(model): if model.header.valid \ and model.header.filetype.endswith('Primitive') \ and model.header.bfc != 'CERTIFY CCW': yield error( model.body[model.header.first_occurrence['bfc']], 'primitive-bfc-ccw') manifest = { 'tests': { 'colour-validity': colours_test, 'syntax-errors': syntax_errors, 'header-validity': bad_header, 'bfc-nocertify': nocertify_test, 'physical-colour': physical_colours_test, 'unofficial-type': unofficiality_test, 'primitive-ccw': primitive_ccw_test, }, 'messages': { 'bad-colour': lambda colour_index: str.format( 'invalid colour {}', colour_index, ), 'syntax-error': lambda reason: str.format( 'syntax error: {}', reason, ), 'bad-header': lambda reason: str.format( 'bad header: {}', reason, ), 'bfc-nocertify': 'all new parts must be BFC certified', 'physical-colour': 'no new physical colour parts are accepted', 'unofficial-type': 'new parts must be unofficial', 'primitive-bfc-ccw': 'primitives must have CCW winding', }, }