diff --git a/akm_tools/akm_validator.py b/akm_tools/akm_validator.py index 5dac401..65f60ab 100644 --- a/akm_tools/akm_validator.py +++ b/akm_tools/akm_validator.py @@ -22,15 +22,15 @@ def create_and_combine_json_from_a_folder(dir_path): return list_to_return -def parse_and_validate_data(model_folder, schema, extended_schema_dir, overlays): +def parse_and_validate_data(model_folder, schema, extended_schema_dir, extended_data_dir,raise_errors): model_data_list = create_and_combine_json_from_a_folder(model_folder) - overlay_data_list = create_and_combine_json_from_a_folder(overlays) - all_data = model_data_list + overlay_data_list + extended_data_list = create_and_combine_json_from_a_folder(extended_data_dir) + all_data = model_data_list + extended_data_list validator_object = AKMDataValidator(schema=schema) validated_model_data = validator_object.validate_data_instances(all_data, extended_schema_dir=extended_schema_dir) validated_model_data = validator_object.validate_contexts(all_data=validated_model_data) ## passing valid instances - validator_object.log_errors() - + validator_object.log_errors(raise_errors) + return validated_model_data @@ -94,6 +94,14 @@ def main(): choices=export_functions.keys(), help="Specifies the export format", ) + + ## export options + parser.add_argument( + "--silent_mode", + action="store_true", + help="log but dont throw errors", + default=False + ) parser.add_argument("-f", "--export_file_path", type=str, help="Path for export file") args = parser.parse_args() @@ -103,7 +111,11 @@ def main(): with open(args.schema, "r") as f: schema = json.load(f) validated_model_data = parse_and_validate_data( - args.model_data_folder, schema, args.extended_schema_dir, args.extended_data_dir + model_folder=args.model_data_folder, + schema=schema, + extended_schema_dir=args.extended_schema_dir, + extended_data_dir=args.extended_data_dir, + raise_errors=not(args.silent_mode) ) if args.export_format: diff --git a/akm_tools/validation/custom_exceptions.py b/akm_tools/validation/custom_exceptions.py index 22dfb22..9545c66 100644 --- a/akm_tools/validation/custom_exceptions.py +++ b/akm_tools/validation/custom_exceptions.py @@ -11,7 +11,7 @@ def __init__(self, instances: List[Dict]): class BaseInstanceOverwiteException(Exception): def __init__(self, base_instance, extended_instance): err_msg = ( - f"The extended instace :\n{extended_instance}\nis overwriting properties of base instance\n{base_instance}\n" + f"The extended instance :\n{extended_instance}\nis overwriting properties of base instance\n{base_instance}\n" ) super().__init__(err_msg) self.message = err_msg diff --git a/akm_tools/validation/validator.py b/akm_tools/validation/validator.py index e0c1adc..65a00d6 100644 --- a/akm_tools/validation/validator.py +++ b/akm_tools/validation/validator.py @@ -50,9 +50,12 @@ def _configure_data_instance_validators(self): ] return data_instance_validator_objects - def log_errors(self): + def log_errors(self,raise_errors): for error_msg in self.validation_errors: logging.error(error_msg) + if len (self.validation_errors)>0: + if raise_errors: + raise Exception('There were errors during validaton, please check the log file') def validate_contexts(self, all_data: List[Dict]): print("Validating Data Contexts") diff --git a/tests/test_custom_exceptions.py b/tests/test_custom_exceptions.py index 72b9388..81111e0 100644 --- a/tests/test_custom_exceptions.py +++ b/tests/test_custom_exceptions.py @@ -26,7 +26,7 @@ def test_BaseInstanceOverwiteException(): raise BaseInstanceOverwiteException(base_instance, extended_instance) assert ( str(excinfo.value) - == f"The extended instace :\n{extended_instance}\nis overwriting properties of base instance\n{base_instance}\n" + == f"The extended instance :\n{extended_instance}\nis overwriting properties of base instance\n{base_instance}\n" )