diff -r e65d82501a38 -r 75b5241a35ec tests/subfiles.py --- a/tests/subfiles.py Mon Jun 24 00:18:19 2019 +0300 +++ b/tests/subfiles.py Mon Jun 24 00:38:18 2019 +0300 @@ -237,21 +237,46 @@ category = category, ) ) +@problem_type('bad-category-in-description', + severity = 'hold', + message = lambda category: str.format( + 'the category "{category}" must be set using !CATEGORY ' + 'and not by description', + category = category, + ) +) def category_test(model): if model.header.valid: - categories = library_standards['categories'].keys() - if model.header.effective_category not in categories: + categories = library_standards['categories'] + illegal_categories_in_description = [ + category_name.lower() + for category_name in categories.keys() + if ' ' in category_name + ] + has_bad_category = False + if model.header.effective_category not in categories.keys(): try: bad_object = model.find_first_header_object('category') except KeyError: # category was not specified using !CATEGORY, blame # the description instead bad_object = model.body[0] + has_bad_category = True yield report_problem( 'bad-category', bad_object = bad_object, category = model.header.effective_category, ) + # Check if the description sets a multi-word category + if not has_bad_category and model.header.category is None: + for category_name in illegal_categories_in_description: + if model.header.description.lower().startswith(category_name): + yield report_problem( + 'bad-category-in-description', + bad_object = model.body[0], + category = category_name.title(), + ) + break manifest = { 'tests': [