tests/misc.py

Fri, 24 May 2019 17:44:04 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 24 May 2019 17:44:04 +0200
changeset 39
abc83875167e
parent 38
66c9591b733d
child 47
4da025d0b283
permissions
-rw-r--r--

fix stylesheet

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)
    )

manifest = {
    'tests': {
        'colour-validity': colours_test,
        'syntax-errors': syntax_errors,
    },
    'messages': {
        'bad-colour': lambda colour_index: str.format(
            'invalid colour {}',
            colour_index,
        ),
        'syntax-error': lambda reason: str.format(
            'syntax error: {}',
            reason,
        ),
    },
}

mercurial