235 message = lambda category: str.format( |
235 message = lambda category: str.format( |
236 '"{category}" is not an official category', |
236 '"{category}" is not an official category', |
237 category = category, |
237 category = category, |
238 ) |
238 ) |
239 ) |
239 ) |
|
240 @problem_type('bad-category-in-description', |
|
241 severity = 'hold', |
|
242 message = lambda category: str.format( |
|
243 'the category "{category}" must be set using !CATEGORY ' |
|
244 'and not by description', |
|
245 category = category, |
|
246 ) |
|
247 ) |
240 def category_test(model): |
248 def category_test(model): |
241 if model.header.valid: |
249 if model.header.valid: |
242 categories = library_standards['categories'].keys() |
250 categories = library_standards['categories'] |
243 if model.header.effective_category not in categories: |
251 illegal_categories_in_description = [ |
|
252 category_name.lower() |
|
253 for category_name in categories.keys() |
|
254 if ' ' in category_name |
|
255 ] |
|
256 has_bad_category = False |
|
257 if model.header.effective_category not in categories.keys(): |
244 try: |
258 try: |
245 bad_object = model.find_first_header_object('category') |
259 bad_object = model.find_first_header_object('category') |
246 except KeyError: |
260 except KeyError: |
247 # category was not specified using !CATEGORY, blame |
261 # category was not specified using !CATEGORY, blame |
248 # the description instead |
262 # the description instead |
249 bad_object = model.body[0] |
263 bad_object = model.body[0] |
|
264 has_bad_category = True |
250 yield report_problem( |
265 yield report_problem( |
251 'bad-category', |
266 'bad-category', |
252 bad_object = bad_object, |
267 bad_object = bad_object, |
253 category = model.header.effective_category, |
268 category = model.header.effective_category, |
254 ) |
269 ) |
|
270 # Check if the description sets a multi-word category |
|
271 if not has_bad_category and model.header.category is None: |
|
272 for category_name in illegal_categories_in_description: |
|
273 if model.header.description.lower().startswith(category_name): |
|
274 yield report_problem( |
|
275 'bad-category-in-description', |
|
276 bad_object = model.body[0], |
|
277 category = category_name.title(), |
|
278 ) |
|
279 break |
255 |
280 |
256 manifest = { |
281 manifest = { |
257 'tests': [ |
282 'tests': [ |
258 determinant_test, |
283 determinant_test, |
259 scaling_legality_test, |
284 scaling_legality_test, |