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

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',
    },
}

mercurial