tests/misc.py

changeset 105
43c367c8895b
parent 94
109fb7cf658f
child 145
fde18c4d6784
--- a/tests/misc.py	Tue Aug 25 23:15:37 2020 +0300
+++ b/tests/misc.py	Tue Aug 25 23:20:22 2020 +0300
@@ -42,167 +42,6 @@
         if isinstance(element, linetypes.Error)
     )
 
-@problem_type('bad-header',
-    severity = 'hold',
-    message = lambda reason: str.format('bad header: {}', reason),
-)
-@problem_type('no-license-set',
-    severity = 'hold',
-    message = 'no license set',
-)
-@problem_type('non-ca-license',
-    severity = 'hold',
-    message = 'no new non-CA-submits are accepted',
-)
-def bad_header(model):
-    import header
-    ca_license = 'Redistributable under CCAL version 2.0 : see CAreadme.txt'
-    if isinstance(model.header, header.BadHeader):
-        yield report_problem(
-            'bad-header',
-            bad_object = model.body[model.header.index],
-            reason = model.header.reason,
-        )
-    elif not model.header.license:
-        yield report_problem(
-            'no-license-set',
-            bad_object = model.body[0],
-        )
-    elif model.header.license != ca_license:
-        yield report_problem(
-            'non-ca-license',
-            bad_object = model.find_first_header_object('license'),
-        )
-
-@problem_type('bfc-nocertify',
-    severity = 'hold',
-    message = 'all new parts must be BFC certified',
-)
-def nocertify_test(model):
-    import header
-    if model.header.valid and model.header.bfc == 'NOCERTIFY':
-        yield report_problem(
-            'bfc-nocertify',
-            bad_object = model.find_first_header_object('bfc'),
-        )
-
-@problem_type('physical-colour-part',
-    severity = 'hold',
-    message = 'no new physical colour parts are accepted',
-)
-def physical_colours_test(model):
-    if model.header.valid and 'Physical_Colour' in model.header.qualifiers:
-        yield report_problem(
-            'physical-colour-part',
-            bad_object = model.find_first_header_object('part type'),
-        )
-
-@problem_type('unofficial-part',
-    severity = 'hold',
-    message = 'new parts must be unofficial',
-)
-def unofficiality_test(model):
-    if model.header.valid and not model.header.filetype.startswith('Unofficial_'):
-        yield report_problem(
-            'unofficial-part',
-            bad_object = model.find_first_header_object('part type')
-        )
-
-@problem_type('primitive-ccw',
-    severity = 'hold',
-    message = 'primitives must have CCW winding',
-)
-@problem_type('no-bfc-line',
-    severity = 'hold',
-    message = 'BFC declaration is missing',
-)
-def header_bfc_test(model):
-    if model.header.valid and not model.header.bfc:
-        yield report_problem(
-            'no-bfc-line',
-            bad_object = model.body[0],
-        )
-    elif model.header.valid \
-    and model.header.filetype.endswith('Primitive') \
-    and model.header.bfc != 'CERTIFY CCW':
-        yield report_problem(
-            'primitive-bfc-ccw',
-            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,
-            )
-
-@problem_type('bad-colour-24-nonline',
-    severity = 'hold',
-    message = 'colour 24 used on non-lines',
-)
-@problem_type('bad-colour-24-line',
-    severity = 'hold',
-    message = 'line with colour other than 24',
-)
-def colour_24_test(model):
-    for element in model.body:
-        if hasattr(element, 'colour'):
-            is_line = isinstance(element, linetypes.LineSegment)
-            if not is_line and element.colour.index == 24:
-                yield report_problem('bad-colour-24-nonline', bad_object = element)
-            if is_line and element.colour.index != 24:
-                yield report_problem('bad-colour-24-line', bad_object = element)
-
-@problem_type('moved-to-with-extension',
-    severity = 'hold',
-    message = 'moved-to files must not contain the '
-        '".dat"-extension in the description',
-)
-def moved_to_with_extension_test(model):
-    if model.header.valid \
-    and model.header.description.startswith('~Moved to') \
-    and '.dat' in model.header.description:
-        yield report_problem(
-            'moved-to-with-extension',
-            bad_object = model.body[0],
-        )
-
-@problem_type('bfc-invertnext-not-on-subfile',
-    severity = 'hold',
-    message = '"BFC INVERTNEXT" not followed by a type-1 line',
-)
-def bfc_invertnext_not_on_subfile_test(model):
-    def get_invertnexts(model):
-        yield from [
-            (index, element)
-            for index, element in enumerate(model.body)
-            if isinstance(element, linetypes.MetaCommand) \
-                and element.text == 'BFC INVERTNEXT'
-        ]
-    def has_subfile_after_invertnext(index):
-        index_subfile = index + 1 # subfile reference should be on the next line
-        if index_subfile >= len(model.body):
-            return False # past the end...
-        else:
-            element = model.body[index_subfile]
-            return isinstance(element, linetypes.SubfileReference)
-    for index, invertnext in get_invertnexts(model):
-        if not has_subfile_after_invertnext(index):
-            yield report_problem('bfc-invertnext-not-on-subfile',
-                bad_object = model.body[index],
-            )
-
 @problem_type('unknown-metacommand',
     severity = 'hold',
     message = lambda command_text: str.format(
@@ -246,18 +85,35 @@
             count = model.line_ending_errors['count'],
         )
 
+@problem_type('bfc-invertnext-not-on-subfile',
+    severity = 'hold',
+    message = '"BFC INVERTNEXT" not followed by a type-1 line',
+)
+def bfc_invertnext_not_on_subfile_test(model):
+    def get_invertnexts(model):
+        yield from [
+            (index, element)
+            for index, element in enumerate(model.body)
+            if isinstance(element, linetypes.MetaCommand) \
+                and element.text == 'BFC INVERTNEXT'
+        ]
+    def has_subfile_after_invertnext(index):
+        index_subfile = index + 1 # subfile reference should be on the next line
+        if index_subfile >= len(model.body):
+            return False # past the end...
+        else:
+            element = model.body[index_subfile]
+            return isinstance(element, linetypes.SubfileReference)
+    for index, invertnext in get_invertnexts(model):
+        if not has_subfile_after_invertnext(index):
+            yield report_problem('bfc-invertnext-not-on-subfile',
+                bad_object = model.body[index],
+            )
+
 manifest = {
     'tests': [
         colours_test,
         syntax_errors,
-        bad_header,
-        nocertify_test,
-        physical_colours_test,
-        unofficiality_test,
-        header_bfc_test,
-        keywords_tests,
-        colour_24_test,
-        moved_to_with_extension_test,
         bfc_invertnext_not_on_subfile_test,
         metacommands_test,
         line_endings_test,

mercurial