forked from RDFLib/rdflib
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: raise an exception when serialization format does not support quads
- fixes <RDFLib#2393>
- Loading branch information
Showing
18 changed files
with
611 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from test.utils.namespace import EGDC, EGSCHEME, EGURN | ||
|
||
from rdflib.graph import ConjunctiveGraph, Graph | ||
from rdflib.namespace import XSD | ||
from rdflib.term import Literal | ||
|
||
|
||
def populate_graph(graph: Graph) -> None: | ||
assert isinstance(graph, ConjunctiveGraph) | ||
|
||
graph.add((EGSCHEME.subject, EGSCHEME.predicate, EGSCHEME.object)) | ||
graph.add((EGDC.subject, EGDC.predicate, Literal("typeless"))) | ||
graph.add((EGURN.subject, EGURN.predicate, EGURN.object)) | ||
|
||
egscheme_graph = graph.get_context(EGSCHEME.graph) | ||
egscheme_graph.add((EGDC.subject, EGDC.predicate, Literal("日本語の表記体系", lang="jpx"))) | ||
egscheme_graph.add((EGURN.subject, EGSCHEME.predicate, EGSCHEME.subject)) | ||
egscheme_graph.add((EGSCHEME.subject, EGSCHEME.predicate, EGSCHEME.object)) | ||
egscheme_graph.add((EGSCHEME.subject, EGSCHEME.predicate, Literal(12))) | ||
|
||
egurn_graph = graph.get_context(EGURN.graph) | ||
egurn_graph.add((EGSCHEME.subject, EGSCHEME.predicate, EGSCHEME.object)) | ||
egurn_graph.add((EGSCHEME.subject, EGDC.predicate, EGDC.object)) | ||
egurn_graph.add( | ||
(EGSCHEME.subject, EGDC.predicate, Literal("XSD string", datatype=XSD.string)) | ||
) | ||
|
||
|
||
__all__ = ["populate_graph"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<http://example.com/subject> <http://example.com/predicate> "日本語の表記体系"@jpx . | ||
<urn:example:subject> <example:predicate> <example:subject> . | ||
<example:object> <http://example.com/predicate> "XSD string" . | ||
<example:subject> <example:predicate> <example:object> . | ||
<example:subject> <example:predicate> "12"^^<http://www.w3.org/2001/XMLSchema#integer> . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from test.utils.namespace import EGDC, EGSCHEME, EGURN | ||
|
||
from rdflib.graph import ConjunctiveGraph, Graph | ||
from rdflib.namespace import XSD | ||
from rdflib.term import Literal | ||
|
||
|
||
def populate_graph(graph: Graph) -> None: | ||
assert isinstance(graph, Graph) | ||
|
||
graph.add((EGDC.subject, EGDC.predicate, Literal("日本語の表記体系", lang="jpx"))) | ||
graph.add((EGURN.subject, EGSCHEME.predicate, EGSCHEME.subject)) | ||
|
||
graph.add((EGSCHEME.object, EGDC.predicate, Literal("XSD string"))) | ||
graph.add((EGSCHEME.subject, EGSCHEME.predicate, EGSCHEME.object)) | ||
graph.add((EGSCHEME.subject, EGSCHEME.predicate, Literal(12))) | ||
|
||
__all__ = ["populate_graph"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@prefix eghttp: <http://example.com/> . | ||
@prefix egurn: <urn:example:> . | ||
@prefix egschema: <example:> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
{ | ||
eghttp:subject eghttp:predicate "日本語の表記体系"@jpx . | ||
|
||
egurn:subject egschema:predicate egschema:subject . | ||
} | ||
|
||
egschema:object eghttp:predicate "XSD string"^^xsd:string . | ||
|
||
egschema:subject egschema:predicate egschema:object, | ||
12 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from test.utils.namespace import EGDO | ||
|
||
from rdflib.graph import ConjunctiveGraph, Graph | ||
|
||
|
||
def populate_graph(graph: Graph) -> None: | ||
assert isinstance(graph, ConjunctiveGraph) | ||
|
||
egdo_graph = graph.get_context(EGDO.graph) | ||
egdo_graph.add((EGDO.subject, EGDO.predicate, EGDO.object)) | ||
|
||
|
||
__all__ = ["populate_graph"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from test.utils.namespace import EGDO | ||
|
||
from rdflib.graph import Graph | ||
|
||
|
||
def populate_graph(graph: Graph) -> None: | ||
graph.add((EGDO.subject, EGDO.predicate, EGDO.object)) | ||
|
||
|
||
__all__ = ["populate_graph"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import itertools | ||
import logging | ||
from test.utils.graph import GRAPH_FORMATS, GraphType | ||
from test.utils.variants import load_pyvariant | ||
from typing import Dict, Iterable, Type | ||
|
||
import pytest | ||
from _pytest.mark.structures import ParameterSet | ||
from _pytest.outcomes import Failed | ||
|
||
from rdflib.graph import ConjunctiveGraph, Dataset, Graph | ||
|
||
|
||
def make_quads_in_triples_cases() -> Iterable[ParameterSet]: | ||
""" | ||
Generate test cases for serializing named graphs (i.e. quads) into a format | ||
that does not support named graphs. | ||
""" | ||
triple_only_formats = [ | ||
graph_format | ||
for graph_format in GRAPH_FORMATS | ||
if graph_format.info.graph_types == {GraphType.TRIPLE} | ||
] | ||
for graph_type, graph_format in itertools.product( | ||
(ConjunctiveGraph, Dataset), triple_only_formats | ||
): | ||
for serializer in graph_format.info.serializers: | ||
yield pytest.param( | ||
graph_type, serializer, marks=pytest.mark.xfail(raises=Failed) | ||
) | ||
|
||
|
||
CONJUNCTIVE_GRAPH_WITH_QUADS = load_pyvariant("diverse_quads", ConjunctiveGraph) | ||
DATASET_WITH_QUADS = load_pyvariant("diverse_quads", Dataset) | ||
|
||
GRAPHS: Dict[Type[Graph], Graph] = { | ||
ConjunctiveGraph: CONJUNCTIVE_GRAPH_WITH_QUADS, | ||
Dataset: DATASET_WITH_QUADS, | ||
} | ||
|
||
|
||
@pytest.mark.parametrize(["graph_type", "serializer"], make_quads_in_triples_cases()) | ||
def test_quads_in_triples(graph_type: Type[ConjunctiveGraph], serializer: str) -> None: | ||
""" | ||
Serializing named graphs (i.e. quads) inside a `ConjunctiveGraph` into a | ||
format that does not support named graphs should result in an exception. | ||
""" | ||
graph = GRAPHS[graph_type] | ||
assert type(graph) is graph_type | ||
with pytest.raises(Exception) as caught: | ||
graph.serialize(format=serializer) | ||
|
||
logging.debug("caught.value = %r", caught.value, exc_info=caught.value) |
Oops, something went wrong.