tests/category.py

Mon, 24 Jun 2019 11:48:52 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 24 Jun 2019 11:48:52 +0300
changeset 91
c71a7d863c2e
parent 89
d2b277cb948e
child 93
ffe05d369412
permissions
-rw-r--r--

removed the typename methods

89
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 from testsuite import problem_type, report_problem
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 import linetypes
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 from librarystandards import library_standards
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 @problem_type('bad-category',
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 severity = 'hold',
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 message = lambda category: str.format(
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 '"{category}" is not an official category',
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 category = category,
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 )
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 )
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 @problem_type('bad-category-in-description',
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 severity = 'hold',
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 message = lambda category: str.format(
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 'the category "{category}" must be set using !CATEGORY '
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 'and not by description',
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 category = category,
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 )
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 )
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 def category_test(model):
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 if model.header.valid:
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 categories = library_standards['categories']
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 illegal_categories_in_description = [
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 category_name.lower()
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 for category_name in categories.keys()
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 if ' ' in category_name
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 ]
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 has_bad_category = False
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 if model.header.effective_category not in categories.keys():
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 try:
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 bad_object = model.find_first_header_object('category')
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 except KeyError:
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 # category was not specified using !CATEGORY, blame
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 # the description instead
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 bad_object = model.body[0]
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 has_bad_category = True
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 yield report_problem(
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 'bad-category',
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 bad_object = bad_object,
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 category = model.header.effective_category,
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 )
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 # Check if the description sets a multi-word category
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 if not has_bad_category and model.header.category is None:
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 for category_name in illegal_categories_in_description:
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 if model.header.description.lower().startswith(category_name):
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 yield report_problem(
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 'bad-category-in-description',
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 bad_object = model.body[0],
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 category = category_name.title(),
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 )
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 break
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52
d2b277cb948e split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 manifest = {'tests': [category_test]}

mercurial