tests/bad-whitespace.py

Thu, 26 Aug 2021 19:36:44 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 26 Aug 2021 19:36:44 +0300
changeset 147
bec55b021ae7
parent 88
6a0b43a5dec0
permissions
-rw-r--r--

Merge commit

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

mercurial