Skip to content

fix validation issues #161

fix validation issues

fix validation issues #161

GitHub Actions / JUnit Test Report failed Aug 12, 2024 in 0s

3 tests run, 2 passed, 0 skipped, 1 failed.

Annotations

Check failure on line 83 in .mypy_cache/3.11/tests/test_reason.data.json

See this annotation in the file changed.

@github-actions github-actions / JUnit Test Report

test_reason.tests

FileNotFoundError: [Errno 2] No such file or directory: 'temp/elk.ttl'
Raw output
_setup = None

    @needs_cmem
    def tests(_setup: None) -> None:  # noqa: C901
        """Tests for reason plugin"""
    
        def get_remote_graph(iri: str) -> Graph:
            graph = Graph().parse(
                data=get(iri, owl_imports_resolution=False).text,
                format="turtle",
            )
            graph.remove((URIRef(iri), DCTERMS.created, None))
            graph.remove((URIRef(iri), RDFS.label, None))
            graph.remove((None, RDF.type, OWL.AnnotationProperty))
            return graph
    
        def test_reasoner(reasoner: str, err_list: list) -> list:
            ReasonPlugin(
                data_graph_iri=REASON_DATA_GRAPH_IRI,
                ontology_graph_iri=REASON_ONTOLOGY_GRAPH_IRI,
                output_graph_iri=REASON_RESULT_GRAPH_IRI,
                reasoner=reasoner,
                sub_class=False,
                class_assertion=True,
                property_assertion=True,
                validate_profile=True,
            ).execute(None, context=TestExecutionContext())
    
            result = get_remote_graph(REASON_RESULT_GRAPH_IRI)
            result.serialize(f"temp/{reasoner}.ttl", format="turtle")
            test = Graph().parse(Path(__path__[0]) / f"test_{reasoner}.ttl", format="turtle")
            if to_isomorphic(result) != to_isomorphic(test):
                err_list.append(reasoner)
            return err_list
    
        def test_validate(errors: str) -> str:
            result = ValidatePlugin(
                ontology_graph_iri=VALIDATE_ONTOLOGY_GRAPH_IRI,
                output_graph_iri=OUTPUT_GRAPH_IRI,
                validate_profile=True,
                md_filename=MD_FILENAME,
            ).execute(None, context=TestExecutionContext(PROJECT_ID))
    
            val_errors = ""
            md_test = (Path(__path__[0]) / "test_validate.md").read_text()
    
            if next(iter(result.entities)).values[0][0] != md_test:  # type: ignore[union-attr]
                val_errors += 'EntityPath "markdown" output error. '
    
            if next(iter(result.entities)).values[2][0] != "Full,DL,EL,QL,RL":  # type: ignore[union-attr]
                val_errors += 'EntityPath "valid_profile" output error. '
    
            if md_test != get_resource(PROJECT_ID, MD_FILENAME).decode():
                val_errors += "Markdown file error. "
    
            output_graph = get_remote_graph(OUTPUT_GRAPH_IRI)
            test = Graph().parse(Path(__path__[0]) / "test_validate_output.ttl", format="turtle")
            if to_isomorphic(output_graph) != to_isomorphic(test):
                val_errors += "Output graph error. "
    
            if val_errors:
                errors += "Validate: " + val_errors
            return errors
    
        errors_list: list[str] = []
        reasoners = ["elk", "emr", "hermit", "jfact", "structural", "whelk"]
        for reasoner in reasoners:
>           errors_list = test_reasoner(reasoner, errors_list)

tests/test_reason.py:121: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_reason.py:83: in test_reasoner
    result.serialize(f"temp/{reasoner}.ttl", format="turtle")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Graph identifier=Na9dd0461e7ab40cc9a8ba8289c093794 (<class 'rdflib.graph.Graph'>)>
destination = 'temp/elk.ttl', format = 'turtle', base = None, encoding = None
args = {}
serializer = <rdflib.plugins.serializers.turtle.TurtleSerializer object at 0x7fe116da3a50>
os_path = 'temp/elk.ttl', location = 'temp/elk.ttl', scheme = '', netloc = ''
path = 'temp/elk.ttl'

    def serialize(
        self: _GraphT,
        destination: Optional[Union[str, pathlib.PurePath, IO[bytes]]] = None,
        format: str = "turtle",
        base: Optional[str] = None,
        encoding: Optional[str] = None,
        **args: Any,
    ) -> Union[bytes, str, _GraphT]:
        """
        Serialize the graph.
    
        :param destination:
           The destination to serialize the graph to. This can be a path as a
           :class:`str` or :class:`~pathlib.PurePath` object, or it can be a
           :class:`~typing.IO[bytes]` like object. If this parameter is not
           supplied the serialized graph will be returned.
        :param format:
           The format that the output should be written in. This value
           references a :class:`~rdflib.serializer.Serializer` plugin. Format
           support can be extended with plugins, but ``"xml"``, ``"n3"``,
           ``"turtle"``, ``"nt"``, ``"pretty-xml"``, ``"trix"``, ``"trig"``,
           ``"nquads"``, ``"json-ld"`` and ``"hext"`` are built in. Defaults to
           ``"turtle"``.
        :param base:
           The base IRI for formats that support it. For the turtle format this
           will be used as the ``@base`` directive.
        :param encoding: Encoding of output.
        :param args:
           Additional arguments to pass to the
           :class:`~rdflib.serializer.Serializer` that will be used.
        :return: The serialized graph if ``destination`` is `None`. The
            serialized graph is returned as `str` if no encoding is specified,
            and as `bytes` if an encoding is specified.
        :rtype: :class:`bytes` if ``destination`` is `None` and ``encoding`` is not `None`.
        :rtype: :class:`str` if ``destination`` is `None` and ``encoding`` is `None`.
        :return: ``self`` (i.e. the :class:`~rdflib.graph.Graph` instance) if
            ``destination`` is not `None`.
        :rtype: :class:`~rdflib.graph.Graph` if ``destination`` is not `None`.
        """
    
        # if base is not given as attribute use the base set for the graph
        if base is None:
            base = self.base
    
        serializer = plugin.get(format, Serializer)(self)
        stream: IO[bytes]
        if destination is None:
            stream = BytesIO()
            if encoding is None:
                serializer.serialize(stream, base=base, encoding="utf-8", **args)
                return stream.getvalue().decode("utf-8")
            else:
                serializer.serialize(stream, base=base, encoding=encoding, **args)
                return stream.getvalue()
        if hasattr(destination, "write"):
            stream = cast(IO[bytes], destination)
            serializer.serialize(stream, base=base, encoding=encoding, **args)
        else:
            if isinstance(destination, pathlib.PurePath):
                os_path = str(destination)
            else:
                location = cast(str, destination)
                scheme, netloc, path, params, _query, fragment = urlparse(location)
                if scheme == "file":
                    if netloc != "":
                        raise ValueError(
                            f"the file URI {location!r} has an authority component which is not supported"
                        )
                    os_path = url2pathname(path)
                else:
                    os_path = location
>           with open(os_path, "wb") as stream:
E           FileNotFoundError: [Errno 2] No such file or directory: 'temp/elk.ttl'

.venv/lib/python3.11/site-packages/rdflib/graph.py:1359: FileNotFoundError