Przeglądaj źródła

Corrections diverses

omassot 7 lat temu
rodzic
commit
f6d17ea284
4 zmienionych plików z 39 dodań i 7 usunięć
  1. 2 2
      core/cerberus_.py
  2. 9 4
      core/checker.py
  3. 28 0
      core/mncheck.py
  4. 0 1
      core/model.py

+ 2 - 2
core/cerberus_.py

@@ -49,10 +49,10 @@ def is_float(field, value, error):
 
 # Ref: http://docs.python-cerberus.org/en/stable/api.html#error-codes
 
-class ExtendedValidator(cerberus.validator.Validator):
+class CerberusValidator(cerberus.validator.Validator):
 
     def __init__(self, *args, **kwargs):
-        super(ExtendedValidator, self).__init__(*args, **kwargs)
+        super().__init__(*args, **kwargs)
         
         # Rends tous les champs requis par défaut, à moins que 'required' ait été défini dans le schéma
         for field in self.schema:

+ 9 - 4
core/checker.py

@@ -1,5 +1,7 @@
 '''
 
+    A simplified version of the unittest module, adapted to run unit tests on data sets instead of code.
+
 @author: olivier.massot, 2018
 '''
 import inspect
@@ -71,14 +73,14 @@ class BaseChecker():
     
     def __init__(self):
         self._test_running = None
-    
+        
     def setUp(self):
         pass
     
     def tearDown(self):
         pass
     
-    def log_error(self, message, info):
+    def log_error(self, message, **info):
         self._test_running.log_error(message, info)
     
     def run(self):
@@ -100,9 +102,12 @@ class BaseChecker():
                     r.handle_exception()
                 
                 self.tearDown()
-                
+
                 tests_results.append(r)
-                
+        
+                if any(err.critical for err in r.errors):
+                    break
+        
         return tests_results
     
 

+ 28 - 0
core/mncheck.py

@@ -0,0 +1,28 @@
+'''
+
+@author: olivier.massot, 2018
+'''
+import importlib
+import logging
+import pkgutil
+
+logger = logging.getLogger("mncheck")
+
+
+def list_schemas():
+    import schemas
+    return [name for _, name, ispkg in pkgutil.iter_modules(schemas.__path__) if not (ispkg or name[0] == '_')]
+
+def get_schema(schema_name):
+    return importlib.import_module("schemas." + schema_name)
+
+def validate(schema_name):
+    try:
+        schema = get_schema(schema_name)
+    except ModuleNotFoundError:
+        logger.critical(f"Le schéma {schema_name} n'existe pas")
+        return
+    
+    results = schema.checker.run()
+    
+    return results

+ 0 - 1
core/model.py

@@ -25,7 +25,6 @@ class QgsModel():
                   4: "MULTI-POINT", 5:"MULTI-LIGNE", 6:"MULTI-POLYGONE"}
     
     layername = ""
-    pk = ""
     geom_type = 0
     bounding_box = (0,0,1,1)
     schema = {}