diff options
author | Jim McCusker <mccusker@gmail.com> | 2017-02-16 15:28:32 -0500 |
---|---|---|
committer | Jim McCusker <mccusker@gmail.com> | 2017-02-16 15:28:32 -0500 |
commit | 0d2d0a6c9ab3015b3bad970048bb759b4445b9a2 (patch) | |
tree | 9de7a4d76056f84870c2d087e84c8d222f387549 | |
parent | 74357f4b91fc36504a09e3a37bc6d277dd70f966 (diff) | |
download | rdflib-0d2d0a6c9ab3015b3bad970048bb759b4445b9a2.tar.gz |
Added test for Issue 682 and fixed.
-rw-r--r-- | rdflib/compare.py | 7 | ||||
-rw-r--r-- | test/test_canonicalization.py | 36 |
2 files changed, 40 insertions, 3 deletions
diff --git a/rdflib/compare.py b/rdflib/compare.py index fb9b1902..bf311438 100644 --- a/rdflib/compare.py +++ b/rdflib/compare.py @@ -469,8 +469,11 @@ class _TripleCanonicalizer(object): def to_isomorphic(graph): if isinstance(graph, IsomorphicGraph): return graph - return IsomorphicGraph(store=graph.store) - + result = IsomorphicGraph() + if hasattr(graph, "identifier"): + result = IsomorphicGraph(identifier=graph.identifier) + result += graph + return result def isomorphic(graph1, graph2): """Compare graph for equality. diff --git a/test/test_canonicalization.py b/test/test_canonicalization.py index d1e38d1a..99bdb909 100644 --- a/test/test_canonicalization.py +++ b/test/test_canonicalization.py @@ -1,5 +1,6 @@ -from rdflib import Graph, RDF, BNode, URIRef +from rdflib import Graph, RDF, BNode, URIRef, Namespace, ConjunctiveGraph, Literal from rdflib.compare import to_isomorphic, to_canonical_graph +from rdflib.plugins.memory import IOMemory from six import text_type from io import StringIO @@ -251,3 +252,36 @@ def test_issue494_collapsing_bnodes(): 'canonicalization changed number of statements' assert g_node_degs == cg_node_degs, \ 'canonicalization changed node degrees' + +def test_issue682_signing_named_graphs(): + ns = Namespace("http://love.com#") + + mary = BNode() + john = URIRef("http://love.com/lovers/john#") + + cmary=URIRef("http://love.com/lovers/mary#") + cjohn=URIRef("http://love.com/lovers/john#") + + store = IOMemory() + + g = ConjunctiveGraph(store=store) + g.bind("love",ns) + + gmary = Graph(store=store, identifier=cmary) + + gmary.add((mary, ns['hasName'], Literal("Mary"))) + gmary.add((mary, ns['loves'], john)) + + gjohn = Graph(store=store, identifier=cjohn) + gjohn.add((john, ns['hasName'], Literal("John"))) + + ig = to_isomorphic(g) + igmary = to_isomorphic(gmary) + + print len(igmary), len(mary) + assert len(igmary) == len(gmary) + print len(ig), len(g) + assert len(ig) == len(g) + assert len(igmary) < len(ig) + print ig.graph_digest(), igmary.graph_digest() + assert ig.graph_digest() != igmary.graph_digest() |