33
44from jinja2 import Environment , PackageLoader
55
6- from ted_sws .core .model .manifestation import RDFManifestation
6+ from ted_sws .core .model .manifestation import RDFManifestation , SHACLTestSuiteValidationReport , \
7+ QueriedSHACLShapeValidationResult
78from ted_sws .core .model .notice import Notice
89from ted_sws .core .model .transform import MappingSuite , SHACLTestSuite
910from ted_sws .data_manager .adapters .repository_abc import NoticeRepositoryABC , MappingSuiteRepositoryABC
1011from ted_sws .notice_validator .adapters .shacl_runner import SHACLRunner
11- from ted_sws .notice_validator .model .shacl_test_suite import QueriedSHACLShapeValidationResult , \
12- SHACLSuiteValidationReport
1312from ted_sws .resources import SHACL_RESULT_QUERY_PATH
1413
1514TEMPLATES = Environment (loader = PackageLoader ("ted_sws.notice_validator.resources" , "templates" ))
@@ -28,7 +27,7 @@ def __init__(self, rdf_manifestation: RDFManifestation, shacl_test_suite: SHACLT
2827 self .shacl_test_suite = shacl_test_suite
2928 self .mapping_suite = mapping_suite
3029
31- def execute_test_suite (self ) -> SHACLSuiteValidationReport :
30+ def execute_test_suite (self ) -> SHACLTestSuiteValidationReport :
3231 """
3332 Executing SHACL shape validation from a SHACL test suite and return execution details
3433 :return:
@@ -46,25 +45,22 @@ def execute_test_suite(self) -> SHACLSuiteValidationReport:
4645 except Exception as e :
4746 shacl_shape_validation_result .error = str (e )
4847
49- return SHACLSuiteValidationReport (mapping_suite_identifier = self .mapping_suite .identifier ,
50- shacl_test_suite_identifier = self .shacl_test_suite .identifier ,
51- validation_result = shacl_shape_validation_result ,
52- object_data = "SHACLTestSuiteExecution" )
48+ return SHACLTestSuiteValidationReport (mapping_suite_identifier = self .mapping_suite .identifier ,
49+ test_suite_identifier = self .shacl_test_suite .identifier ,
50+ validation_results = shacl_shape_validation_result ,
51+ object_data = "SHACLTestSuiteExecution" )
5352
5453
55- class SHACLReportBuilder :
54+ def generate_shacl_report ( shacl_test_suite_execution : SHACLTestSuiteValidationReport ) -> SHACLTestSuiteValidationReport :
5655 """
57- Given a QueriedSHACLShapeValidationResult, generates JSON and HTML reports.
56+ This function generate html report after SHACL test execution.
57+ :param shacl_test_suite_execution:
58+ :return:
5859 """
59-
60- def __init__ (self , shacl_test_suite_execution : SHACLSuiteValidationReport ):
61- self .shacl_test_suite_execution = shacl_test_suite_execution
62-
63- def generate_report (self ) -> SHACLSuiteValidationReport :
64- html_report = TEMPLATES .get_template (SHACL_TEST_SUITE_EXECUTION_HTML_REPORT_TEMPLATE ).render (
65- self .shacl_test_suite_execution .dict ())
66- self .shacl_test_suite_execution .object_data = html_report
67- return self .shacl_test_suite_execution
60+ html_report = TEMPLATES .get_template (SHACL_TEST_SUITE_EXECUTION_HTML_REPORT_TEMPLATE ).render (
61+ shacl_test_suite_execution .dict ())
62+ shacl_test_suite_execution .object_data = html_report
63+ return shacl_test_suite_execution
6864
6965
7066def validate_notice_with_shacl_suite (notice : Notice , mapping_suite_package : MappingSuite ):
@@ -75,15 +71,14 @@ def validate_notice_with_shacl_suite(notice: Notice, mapping_suite_package: Mapp
7571 :return:
7672 """
7773
78- def shacl_validation (rdf_manifestation : RDFManifestation ) -> List [SHACLSuiteValidationReport ]:
74+ def shacl_validation (rdf_manifestation : RDFManifestation ) -> List [SHACLTestSuiteValidationReport ]:
7975 reports = []
8076 shacl_test_suites = mapping_suite_package .shacl_test_suites
8177 for shacl_test_suite in shacl_test_suites :
8278 test_suite_execution = SHACLTestSuiteRunner (rdf_manifestation = rdf_manifestation ,
8379 shacl_test_suite = shacl_test_suite ,
8480 mapping_suite = mapping_suite_package ).execute_test_suite ()
85- report_builder = SHACLReportBuilder (shacl_test_suite_execution = test_suite_execution )
86- reports .append (report_builder .generate_report ())
81+ reports .append (generate_shacl_report (shacl_test_suite_execution = test_suite_execution ))
8782
8883 return reports
8984
0 commit comments