Thu, 26 Aug 2021 19:37:00 +0300
Update license year
from testsuite import problem_type, report_problem import linetypes from librarystandards import library_standards @problem_type('bad-category', severity = 'hold', message = lambda category: str.format( '"{category}" is not an official category', 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): # Only test the category if the description does not start with a '~' if model.header.valid and not model.header.description.startswith('~'): 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': [category_test]}