Skip to content

Commit

Permalink
fix: passing ConjunctiveGraph as namespace_manager (#2073)
Browse files Browse the repository at this point in the history
pass the NamespaceManager of the ConjunctiveGraph as namespace_manager of the Graph created by the get_context() method instead of the ConjunctiveGraph object itself.
  • Loading branch information
mielvds authored Aug 4, 2022
1 parent cfa4180 commit cc80c9c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ CHANGE BARRIER is intended to reduce the potential for merge conflicts
and will be removed for release.
-->

<!-- -->
<!-- -->
<!-- CHANGE BARRIER: START -->
<!-- -->
<!-- -->

- Fixes passing `NamespaceManager` in `ConjunctiveGraph`'s method `get_context()`.
The `get_context()` method will now pass the `NamespaceManager` of `ConjunctiveGraph` to the `namespace_manager` attribute of the newly created context graph, instead of the `ConjunctiveGraph` object itself. This cleans up an old FIXME commment.
[PR #2073](https://github.com/RDFLib/rdflib/pull/2073).

<!-- -->
<!-- -->
<!-- CHANGE BARRIER: END -->
<!-- -->
<!-- -->

<!-- -->
<!-- -->
<!-- CHANGE BARRIER: START -->
Expand Down
3 changes: 1 addition & 2 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1915,9 +1915,8 @@ def get_context(
identifier must be a URIRef or BNode.
"""
# TODO: FIXME - why is ConjunctiveGraph passed as namespace_manager?
return Graph(
store=self.store, identifier=identifier, namespace_manager=self, base=base # type: ignore[arg-type]
store=self.store, identifier=identifier, namespace_manager=self.namespace_manager, base=base # type: ignore[arg-type]
)

def remove_context(self, context):
Expand Down
12 changes: 12 additions & 0 deletions test/test_conjunctivegraph/test_conjunctive_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from rdflib import ConjunctiveGraph, Graph
from rdflib.namespace import NamespaceManager
from rdflib.parser import StringInputSource
from rdflib.term import BNode, Identifier, URIRef

Expand Down Expand Up @@ -47,6 +48,17 @@ def test_quad_contexts():
assert isinstance(q[3], Graph)


def test_context_namespaces():
cg = ConjunctiveGraph()
a = URIRef("urn:a")
ns = URIRef("http://example.org/")
cg.bind("ex", ns)
g = cg.get_context(a)

assert type(g.namespace_manager) is NamespaceManager
assert ("ex", ns) in g.namespace_manager.namespaces()


def get_graph_ids_tests():
def check(kws):
cg = ConjunctiveGraph()
Expand Down

0 comments on commit cc80c9c

Please sign in to comment.