Unverified Commit ad51dfe5 authored by Maxime Lefrançois's avatar Maxime Lefrançois
Browse files

check: fix crashes and dead checks found by the audit

- clause 10 checkers crashed (`filter_document("ontological_definition")`
  looked for a function parameter); README.md and chowlk.xml were looked
  for in the project root instead of the pattern directory; 10.4 checked
  the ontological definition instead of the SHACL specification
- 9.4.6 passed a document instead of a shapes graph; BaseChecker did not
  set `display_name` when given a logger name
- 9.4.1 used `self.document`, which does not exist on a project checker
- 9.7.1: the term check was dead (`"\b"` was a backspace, `"md"` never
  matched `.md`); terms defined in vocabularies count as defined
- `-c "TS103673 Clause 9.7.1"` now matches clause display names
- 9.4.4.1/9.4.4.2/9.6.3: TS 103 673 "should" requirements are warnings;
  `rdf:langString` wording; no `@en` required on rdfs:comment
- 9.4.3.1/9.4.3.2: check the values of vann:preferredNamespaceUri and
  dcterms:source; 9.6.3 title shape had two severities
- 9.2 logging format errors; 9.4.5 unbound temp_file; SHACL shapes path
- pipeline: missing documents are reported instead of crashing on
  getmtime/fromisoformat; stale cache metadata is removed on reload;
  cached loading errors keep an exception type and are logged;
  undeclared-term fallback no longer types predicates and classes as
  individuals; copy-paste in generate_metadata; always-true `any()`
- project name normalization: `my_repo` is no longer SAREF4REPO, so the
  git remote fallback is reachable; `s4abcd` and `saref4abcd` accepted
- the ETSI work programme fetch failing (offline) is a warning
- `context()` uses the project version when the work item is for
  another version; `__repr__` no longer raises
- git repositories are closed at the end of a run
- PATTERN_SAREF_GRAPHS accepts `patterns/` and digits
parent 30f8d43e
Loading
Loading
Loading
Loading
+4 −0
Changes for src/saref_pypeline/_errors.py: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -35,3 +35,7 @@ class DocumentImportCantFindVersionError(DocumentImportError):
        self.project = project
        self.version = version



class CachedLoadingError(Exception):
    """A loading error restored from the on-disk cache: only its message is known."""
+4 −3
Changes for src/saref_pypeline/check/BaseChecker.py: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -39,17 +39,18 @@ class BaseChecker:
        self.version: SAREFVersionName = project_version.version
        if not isinstance(logger_name, None | str):
            raise ValueError("logger_name shall be None or a string")
        if logger_name == None:
        basename = os.path.basename(caller_file)
        self.ts = basename[: basename.index("_")]
        if "Clause" in basename:
            _, _, *clauses, _ = basename.split("_")
            clause = ".".join(clauses)
            self.display_name = f"{self.ts} Clause {clause}"
                logger_name = f"{project_version.logger_name}.{self.ts}.{clause}"
            default_logger_name = f"{project_version.logger_name}.{self.ts}.{clause}"
        else:
            self.display_name = f"{self.ts}"
                logger_name = f"{project_version.logger_name}.{self.ts}"
            default_logger_name = f"{project_version.logger_name}.{self.ts}"
        if logger_name == None:
            logger_name = default_logger_name
        nb_hash = logger_name.count(".")
        self.logger = logging.getLogger(logger_name)
        if not any(isinstance(h, FirstEventHandler) for h in self.logger.handlers):
+1 −1
Changes for src/saref_pypeline/check/BaseGraphDocumentSHACLChecker.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ class BaseGraphDocumentSHACLChecker(BaseGraphDocumentChecker):
            raise ValueError("shapes_graph shall be a Graph, a string, or None")

        # shapes_graph is a file path string
        if not shapes_file.exists():
        if not os.path.exists(shapes_file):
            raise FileNotFoundError(f"SHACL shapes file not found: {shapes_file}")
        self._shapes_graph = Graph()
        self._shapes_graph.parse(shapes_file, format="turtle")
+6 −1
Changes for src/saref_pypeline/check/TS103673_Clause_10_2_Checker.py: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -22,7 +22,12 @@ class Checker(BasePatternChecker):
    @filter_document("ontological_definition")
    @filter_clause
    def check_clause(self):
        path = os.path.join(self.project_version.project.directory, "README.md")
        path = os.path.join(
            self.project_version.project.directory,
            "patterns",
            self.pattern_name,
            "README.md",
        )
        if not os.path.isfile(path):
            self.logger.warning(
                f"The reference ontology pattern directory for {self.pattern_name} should contain some documentation for the pattern. In particular a `README.md` file and some diagrams referred to in the `README.md` file."
+2 −2
Changes for src/saref_pypeline/check/TS103673_Clause_10_4_Checker.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -21,10 +21,10 @@ class Checker(BasePatternChecker):
    ):
        super().__init__(__file__, pipeline, project_version, pattern_name)

    @filter_document("ontological_definition")
    @filter_document("shacl_specification")
    @filter_clause
    def check_clause(self):
        doc = self.ontological_definition
        doc = self.shacl_specification

        if doc.loading_error:
            e = doc.loading_error
Loading