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: SPARQL
LOAD ... INTO GRAPH
handling
`LOAD ... INTO GRAPH` stopped working correctly after the change to handling of the `publicID` `Graph.parse` parameter in RDFLib 7.0.0 (<RDFLib#2406>). This is because `LOAD` evaluation relied on `publicID` to select the graph name. So after <RDFLib#2406> data would be loaded into the default graph even if a named graph is specified. This change adds tests for `LOAD ... INTO GRAPH` and fixes the load evaluation. A consequence of this change is also that relative IRI lookup for graphs loaded with `LOAD ... INTO GRAPH` is now relative to the source document URI instead of the base URI of the graph being loaded into, which is more correct.
- Loading branch information
Showing
4 changed files
with
118 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import logging | ||
from test.data import TEST_DATA_DIR | ||
from test.utils import GraphHelper | ||
from test.utils.graph import load_sources | ||
from test.utils.namespace import EGDO | ||
from typing import Callable | ||
|
||
import pytest | ||
|
||
from rdflib.graph import ConjunctiveGraph, Dataset, Graph | ||
|
||
|
||
@pytest.mark.parametrize("graph_factory", [Graph, ConjunctiveGraph, Dataset]) | ||
def test_load_into_default(graph_factory: Callable[[], Graph]) -> None: | ||
""" | ||
Evaluation of ``LOAD <source>`` into default graph works correctly. | ||
""" | ||
source_path = TEST_DATA_DIR / "variants" / "simple_triple.ttl" | ||
|
||
expected_graph = graph_factory() | ||
load_sources(source_path, graph=expected_graph) | ||
|
||
actual_graph = graph_factory() | ||
actual_graph.update(f"LOAD <{source_path.as_uri()}>") | ||
|
||
if logging.getLogger().isEnabledFor(logging.DEBUG): | ||
debug_format = ( | ||
"trig" if isinstance(expected_graph, ConjunctiveGraph) else "turtle" | ||
) | ||
logging.debug( | ||
"expected_graph = \n%s", expected_graph.serialize(format=debug_format) | ||
) | ||
logging.debug( | ||
"actual_graph = \n%s", actual_graph.serialize(format=debug_format) | ||
) | ||
|
||
if isinstance(expected_graph, ConjunctiveGraph): | ||
assert isinstance(actual_graph, ConjunctiveGraph) | ||
GraphHelper.assert_collection_graphs_equal(expected_graph, actual_graph) | ||
else: | ||
GraphHelper.assert_triple_sets_equals(expected_graph, actual_graph) | ||
|
||
|
||
@pytest.mark.parametrize("graph_factory", [ConjunctiveGraph, Dataset]) | ||
def test_load_into_named(graph_factory: Callable[[], ConjunctiveGraph]) -> None: | ||
""" | ||
Evaluation of ``LOAD <source> INTO GRAPH <name>`` works correctly. | ||
""" | ||
source_path = TEST_DATA_DIR / "variants" / "simple_triple.ttl" | ||
|
||
expected_graph = graph_factory() | ||
load_sources(source_path, graph=expected_graph.get_context(EGDO.graph)) | ||
|
||
actual_graph = graph_factory() | ||
|
||
actual_graph.update(f"LOAD <{source_path.as_uri()}> INTO GRAPH <{EGDO.graph}>") | ||
|
||
if logging.getLogger().isEnabledFor(logging.DEBUG): | ||
debug_format = "trig" | ||
logging.debug( | ||
"expected_graph = \n%s", expected_graph.serialize(format=debug_format) | ||
) | ||
logging.debug( | ||
"actual_graph = \n%s", actual_graph.serialize(format=debug_format) | ||
) | ||
|
||
GraphHelper.assert_collection_graphs_equal(expected_graph, actual_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