added bfc declaration tests

Fri, 18 Sep 2020 20:59:59 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 18 Sep 2020 20:59:59 +0300
changeset 127
97de6058109e
parent 126
16dae12ac0f0
child 128
a24cfbaf885f

added bfc declaration tests

parse.py file | annotate | diff | comparison | revisions
tests/headertest.py file | annotate | diff | comparison | revisions
unittest.py file | annotate | diff | comparison | revisions
unittests/primitive-ccw.test file | annotate | diff | comparison | revisions
unittests/primitive-cw.test file | annotate | diff | comparison | revisions
unittests/primitive-nobfc.test file | annotate | diff | comparison | revisions
unittests/primitive-nocertify.test file | annotate | diff | comparison | revisions
--- a/parse.py	Fri Sep 18 20:46:26 2020 +0300
+++ b/parse.py	Fri Sep 18 20:59:59 2020 +0300
@@ -41,7 +41,13 @@
     def find_first_header_object(self, object_type):
         return self.find_header_object(object_type, 0)
     def find_header_object(self, object_type, n):
-        return self.body[self.header.occurrences[object_type][n]]
+        try:
+            return self.body[self.header.occurrences[object_type][n]]
+        except IndexError:
+            raise KeyError(str.format(
+                '{type} not found in header',
+                type = object_type
+            ))
 
 def model_vertices(
     model,
--- a/tests/headertest.py	Fri Sep 18 20:46:26 2020 +0300
+++ b/tests/headertest.py	Fri Sep 18 20:59:59 2020 +0300
@@ -67,7 +67,7 @@
             bad_object = model.find_first_header_object('part type')
         )
 
-@problem_type('primitive-ccw',
+@problem_type('primitive-non-ccw',
     severity = 'hold',
     message = 'primitives must have CCW winding',
 )
@@ -85,7 +85,7 @@
     and model.header.filetype.endswith('Primitive') \
     and model.header.bfc != 'CERTIFY CCW':
         yield report_problem(
-            'primitive-bfc-ccw',
+            'primitive-non-ccw',
             bad_object = model.find_first_header_object('bfc'),
         )
 
--- a/unittest.py	Fri Sep 18 20:46:26 2020 +0300
+++ b/unittest.py	Fri Sep 18 20:59:59 2020 +0300
@@ -102,6 +102,10 @@
     return problem_tuple[0] + ':' + str(problem_tuple[1])
 
 def run_unit_test_suite():
+    from argparse import ArgumentParser
+    parser = ArgumentParser()
+    parser.add_argument('-d', '--debug', action = 'store_true')
+    args = parser.parse_args()
     config = load_config()
     test_suite = load_tests()
     num_tested = 0
@@ -117,11 +121,14 @@
                 test_suite = test_suite
             )
         except Exception as error:
-            print(str.format(
-                'Error running {test_name}: {error}',
-                test_name = unit_test_path.name,
-                error = str(error),
-            ))
+            if args.debug:
+                raise
+            else:
+                print(str.format(
+                    'Error running {test_name}: {error}',
+                    test_name = unit_test_path.name,
+                    error = str(error),
+                ))
         else:
             print(str.format(
                 '{name}: {verdict}',
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/unittests/primitive-ccw.test	Fri Sep 18 20:59:59 2020 +0300
@@ -0,0 +1,8 @@
+0 Testing: primitive-non-ccw
+0 Expecting: none
+0 Example primitive
+0 Name: example.dat
+0 Author: Me
+0 !LDRAW_ORG Unofficial_Primitive
+0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
+0 BFC CERTIFY CCW
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/unittests/primitive-cw.test	Fri Sep 18 20:59:59 2020 +0300
@@ -0,0 +1,8 @@
+0 Testing: primitive-non-ccw
+0 Expecting: primitive-non-ccw:6
+0 Example primitive
+0 Name: example.dat
+0 Author: Me
+0 !LDRAW_ORG Unofficial_Primitive
+0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
+0 BFC CERTIFY CW
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/unittests/primitive-nobfc.test	Fri Sep 18 20:59:59 2020 +0300
@@ -0,0 +1,7 @@
+0 Testing: no-bfc-line
+0 Expecting: no-bfc-line:1
+0 Example primitive
+0 Name: example.dat
+0 Author: Me
+0 !LDRAW_ORG Unofficial_Primitive
+0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/unittests/primitive-nocertify.test	Fri Sep 18 20:59:59 2020 +0300
@@ -0,0 +1,8 @@
+0 Testing: primitive-non-ccw
+0 Expecting: primitive-non-ccw:6
+0 Example primitive
+0 Name: example.dat
+0 Author: Me
+0 !LDRAW_ORG Unofficial_Primitive
+0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
+0 BFC NOCERTIFY

mercurial