tests/bad-whitespace.py

changeset 88
6a0b43a5dec0
equal deleted inserted replaced
87:90105119ff90 88:6a0b43a5dec0
1 from testsuite import problem_type, report_problem
2 import linetypes
3
4 @problem_type('bad-whitespace',
5 severity = 'hold',
6 message = lambda whitespaces: str.format(
7 'non-standard whitespace in description: {whitespaces}',
8 whitespaces = whitespaces,
9 )
10 )
11 def bad_whitespace_test(model):
12 if model.header.valid:
13 import re
14 description = model.header.description
15 # checking against string.whitespace is not adequate enough
16 # because it only contains ASCII characters. So checking using a
17 # regular expression is necessary.
18 bad_whitespaces = set(re.findall('\s', description)) - {' '}
19 if bad_whitespaces:
20 yield report_problem(
21 'bad-whitespace',
22 bad_object = model.body[0],
23 whitespaces = ', '.join(
24 repr(whitespace)
25 for whitespace in sorted(bad_whitespaces)
26 ),
27 )
28
29 manifest = {'tests': [bad_whitespace_test]}

mercurial