Added command line option to list all checks.

Mon, 22 Jan 2018 21:21:53 +0200

author
Santeri Piippo
date
Mon, 22 Jan 2018 21:21:53 +0200
changeset 26
7c263b864371
parent 25
8990ac138cc2
child 27
3089611c99d1

Added command line option to list all checks.

ldcheck.py file | annotate | diff | comparison | revisions
tests/misc.py file | annotate | diff | comparison | revisions
tests/quadrilaterals.py file | annotate | diff | comparison | revisions
tests/subfiles.py file | annotate | diff | comparison | revisions
--- a/ldcheck.py	Mon Jan 22 21:04:53 2018 +0200
+++ b/ldcheck.py	Mon Jan 22 21:21:53 2018 +0200
@@ -71,15 +71,41 @@
     def quadrilaterals(self):
         yield from self.filter_by_type(linetypes.Quadrilateral)
 
+import argparse
+class ListTestSuiteAction(argparse.Action):
+    def __init__(self, option_strings, dest, nargs = None, **kwargs):
+        super().__init__(option_strings, dest, nargs = 0, **kwargs)
+    def __call__(self, *args, **kwargs):
+        from testsuite import load_tests
+        from sys import exit
+        from re import sub
+        test_suite = load_tests()
+        for test_name in sorted(test_suite['tests'].keys()):
+            test_function = test_suite['tests'][test_name]
+            help = sub(r'\s+', ' ', test_function.__doc__ or '').strip()
+            print(test_name + ': ' + help)
+        exit(0)
+
 if __name__ == '__main__':
     from sys import argv
+    parser = argparse.ArgumentParser()
+    parser.add_argument('filename')
+    parser.add_argument('--list',
+        action = ListTestSuiteAction,
+        help = 'Lists all possible checks and exit',
+    )
+    args = parser.parse_args()
     config = load_config('ldcheck.cfg')
     for ldconfig_ldr_path in find_ldconfig_ldr_paths(config):
         with ldconfig_ldr_path.open() as ldconfig_ldr:
             load_colours(ldconfig_ldr)
-    with open(argv[1], 'r') as file:
+    with open(args.filename) as file:
         from os.path import basename
-        model = read_ldraw(file, name = basename(argv[1]), config = config)
+        model = read_ldraw(
+            file,
+            name = basename(args.filename),
+            config = config,
+        )
         from testsuite import load_tests, check_model, format_report
         test_suite = load_tests()
         report = check_model(model, test_suite)
--- a/tests/misc.py	Mon Jan 22 21:04:53 2018 +0200
+++ b/tests/misc.py	Mon Jan 22 21:21:53 2018 +0200
@@ -1,6 +1,7 @@
 from testsuite import warning
 
 def colours_test(model):
+    ''' Checks that all colours used in the part model are valid. '''
     yield from (
         warning(element, 'bad-colour', colour_index = element.colour.index)
         for element in model.body
--- a/tests/quadrilaterals.py	Mon Jan 22 21:04:53 2018 +0200
+++ b/tests/quadrilaterals.py	Mon Jan 22 21:21:53 2018 +0200
@@ -7,6 +7,7 @@
     return min(container) * max(container) >= 0
 
 def concave_test(model):
+    ''' Checks that all quadrilaterals are convex. '''
     for quadrilateral in model.quadrilaterals:
         geometry = transform_to_xy(quadrilateral.geometry)
         z_scores = [
@@ -17,7 +18,7 @@
             yield error(quadrilateral, 'concave-error')
 
 def skew_test(model):
-    ''' Test for non-coplanar quadrilaterals. '''
+    ''' Checks that all quadrilaterals are coplanar. '''
     for quadrilateral in model.quadrilaterals:
         for triangles in split_quadrilateral(quadrilateral.geometry):
             plane_1 = triangle_plane_normal(triangles[0])
--- a/tests/subfiles.py	Mon Jan 22 21:04:53 2018 +0200
+++ b/tests/subfiles.py	Mon Jan 22 21:21:53 2018 +0200
@@ -10,6 +10,10 @@
     library_standards.read_file(file)
 
 def determinant_test(model):
+    '''
+        Checks all subfile references for matrices with rows or columns all
+        zero.
+    '''
     yield from (
         error(subfile_reference, 'zero-determinant')
         for subfile_reference in model.subfile_references
@@ -46,6 +50,12 @@
 }
 
 def scaling_legality_test(model):
+    '''
+        Checks the part against primitive references with bad scaling. Some
+        primitives (e.g. pegs) are not allowed to be scaled in the
+        X or Z directions. Some (e.g. most studs) are not allowed to be scaled
+        in the Y direction either.
+    '''
     from fnmatch import fnmatch
     scaling_restrictions = library_standards['scaling restrictions']
     for subfile_reference in model.subfile_references:

mercurial