tests/bad-whitespace.py

Thu, 26 Aug 2021 22:04:33 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 26 Aug 2021 22:04:33 +0300
changeset 152
5e347a96869a
parent 88
6a0b43a5dec0
permissions
-rw-r--r--

removed some alias tests that aren't mandated by the official header specification

from testsuite import problem_type, report_problem
import linetypes

@problem_type('bad-whitespace',
    severity = 'hold',
    message = lambda whitespaces: str.format(
        'non-standard whitespace in description: {whitespaces}',
        whitespaces = whitespaces,
    )
)
def bad_whitespace_test(model):
    if model.header.valid:
        import re
        description = model.header.description
        # checking against string.whitespace is not adequate enough
        # because it only contains ASCII characters. So checking using a
        # regular expression is necessary.
        bad_whitespaces = set(re.findall('\s', description)) - {' '}
        if bad_whitespaces:
            yield report_problem(
                'bad-whitespace',
                bad_object = model.body[0],
                whitespaces = ', '.join(
                    repr(whitespace)
                    for whitespace in sorted(bad_whitespaces)
                ),
            )

manifest = {'tests': [bad_whitespace_test]}

mercurial