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