tests/misc.py

changeset 69
a24c4490d9f2
parent 68
c19dd0d3248e
child 70
2453681c6a69
--- a/tests/misc.py	Sat Jun 22 23:38:51 2019 +0300
+++ b/tests/misc.py	Sat Jun 22 23:52:08 2019 +0300
@@ -64,7 +64,7 @@
     if model.header.valid and model.header.bfc == 'NOCERTIFY':
         yield report_problem(
             'bfc-nocertify',
-            bad_object = model.body[model.header.first_occurrence['bfc']],
+            bad_object = model.find_first_header_object('bfc'),
         )
 
 @problem_type('physical-colour-part',
@@ -75,7 +75,7 @@
     if model.header.valid and 'Physical_Colour' in model.header.qualifiers:
         yield report_problem(
             'physical-colour-part',
-            bad_object = model.body[model.header.first_occurrence['part type']],
+            bad_object = model.find_first_header_object('part type'),
         )
 
 @problem_type('unofficial-part',
@@ -86,7 +86,8 @@
     if model.header.valid and not model.header.filetype.startswith('Unofficial_'):
         yield report_problem(
             'unofficial-part',
-            bad_object = model.body[model.header.first_occurrence['part type']])
+            bad_object = model.find_first_header_object('part type')
+        )
 
 @problem_type('primitive-ccw',
     severity = 'hold',
@@ -97,8 +98,6 @@
     message = 'BFC declaration is missing',
 )
 def header_bfc_test(model):
-    def find_the_bfc_object(model):
-        return model.body[model.header.first_occurrence['bfc']],
     if model.header.valid and not model.header.bfc:
         yield report_problem(
             'no-bfc-line',
@@ -109,9 +108,26 @@
     and model.header.bfc != 'CERTIFY CCW':
         yield report_problem(
             'primitive-bfc-ccw',
-            bad_object = find_the_bfc_object(model),
+            bad_object = model.find_first_header_object('bfc'),
         )
 
+@problem_type('keywords-for-nonparts',
+    severity = 'warning',
+    message = lambda type: str.format(
+        'Keywords are not allowed for {type} files',
+        type = type,
+    ),
+)
+def keywords_tests(model):
+    if model.header.valid:
+        if model.header.keywords \
+        and model.header.effective_filetype != 'Part':
+            yield report_problem(
+                'keywords-for-nonparts',
+                bad_object = model.find_first_header_object('keywords'),
+                type = model.header.effective_filetype,
+            )
+
 manifest = {
     'tests': [
         colours_test,
@@ -121,5 +137,6 @@
         physical_colours_test,
         unofficiality_test,
         header_bfc_test,
+        keywords_tests,
     ],
 }

mercurial