added a test for the description setting a multi-word category

Mon, 24 Jun 2019 00:38:18 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 24 Jun 2019 00:38:18 +0300
changeset 82
75b5241a35ec
parent 81
e65d82501a38
child 83
bd840d5dc8d8

added a test for the description setting a multi-word category

tests/library-standards.ini file | annotate | diff | comparison | revisions
tests/subfiles.py file | annotate | diff | comparison | revisions
--- a/tests/library-standards.ini	Mon Jun 24 00:18:19 2019 +0300
+++ b/tests/library-standards.ini	Mon Jun 24 00:38:18 2019 +0300
@@ -63,7 +63,7 @@
 Cockpit =
 Cone =
 Constraction =
-Constraction Accessory = Constraction
+Constraction Accessory =
 Container =
 Conveyor =
 Crane =
@@ -88,11 +88,11 @@
 Lever =
 Magnet =
 Minifig =
-Minifig Accessory = Minifig
-Minifig Footwear = Minifig
-Minifig Headwear = Minifig
-Minifig Hipwear = Minifig
-Minifig Neckwear = Minifig
+Minifig Accessory =
+Minifig Footwear =
+Minifig Headwear =
+Minifig Hipwear =
+Minifig Neckwear =
 Monorail =
 Obsolete =
 Panel =
--- 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': [

mercurial