tests/misc.py

Sat, 08 Jun 2019 01:42:48 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 08 Jun 2019 01:42:48 +0300
changeset 63
8949af6a4279
parent 62
f0a6bf48b05e
child 64
1c0884f5506e
permissions
-rw-r--r--

added the list of issues onto the web frontend

from testsuite import problem_type, report_problem
import linetypes

@problem_type('bad-colour',
    severity = 'error',
    message = lambda colour_index, count: str.format(
        'invalid colour {} used {} time(s)',
        colour_index,
        count,
    ),
)
def colours_test(model):
    ''' Checks that all colours used in the part model are valid. '''
    from collections import defaultdict
    bad_colours = defaultdict(lambda: {'count': 0, 'first-occurrence': None})
    for element in model.body:
        if hasattr(element, 'colour') and not element.colour.is_valid:
            bad_colours[element.colour.index]['count'] += 1
            if not bad_colours[element.colour.index]['first-occurrence']:
                bad_colours[element.colour.index]['first-occurrence'] = element
    yield from [
        report_problem(
            'bad-colour',
            bad_object = bad_colour['first-occurrence'],
            colour_index = colour_index,
            count = bad_colour['count'],
        )
        for colour_index, bad_colour in bad_colours.items()
    ]

@problem_type('syntax-error',
    severity = 'error',
    message = lambda reason: str.format('syntax error: {}', reason),
)
def syntax_errors(model):
    yield from (
        report_problem('syntax-error',
            bad_object = element,
            reason = element.reason
        )
        for element in model.body
        if isinstance(element, linetypes.Error)
    )

@problem_type('bad-header',
    severity = 'error',
    message = lambda reason: str.format('bad header: {}', reason),
)
def bad_header(model):
    import header
    if isinstance(model.header, header.BadHeader):
        yield report_problem(
            'bad-header',
            bad_object = model.body[model.header.index],
            reason = model.header.reason,
        )

@problem_type('bfc-nocertify',
    severity = 'error',
    message = 'all new parts must be BFC certified',
)
def nocertify_test(model):
    import header
    if model.header.valid and model.header.bfc == 'NOCERTIFY':
        yield report_problem(
            'bfc-nocertify',
            bad_object = model.body[model.header.first_occurrence['bfc']],
        )

@problem_type('physical-colour-part',
    severity = 'error',
    message = 'no new physical colour parts are accepted',
)
def physical_colours_test(model):
    if model.header.valid and 'Physical_Colour' in model.header.qualifiers:
        yield report_problem(
            'physical-colour-part',
            bad_object = model.body[model.header.first_occurrence['part type']],
        )

@problem_type('official-part',
    severity = 'error',
    message = 'new parts must be unofficial',
)
def unofficiality_test(model):
    if model.header.valid and not model.header.filetype.startswith('Unofficial_'):
        yield report_problem(
            'unofficial-part',
            bad_object = model.body[model.header.first_occurrence['part type']])

@problem_type('primitive-ccw',
    severity = 'error',
    message = 'primitives must have CCW winding',
)
def primitive_ccw_test(model):
    if model.header.valid \
    and model.header.filetype.endswith('Primitive') \
    and model.header.bfc != 'CERTIFY CCW':
        yield report_problem(
            'primitive-bfc-ccw',
            bad_object = model.body[model.header.first_occurrence['bfc']],
        )

manifest = {
    'tests': [
        colours_test,
        syntax_errors,
        bad_header,
        nocertify_test,
        physical_colours_test,
        unofficiality_test,
        primitive_ccw_test,
    ],
}

mercurial