1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
from typing import Set, Tuple
import unittest
from unittest.case import expectedFailure
import rdflib
from rdflib.compare import graph_diff
from rdflib.namespace import RDF, FOAF
from rdflib import Graph
from rdflib.term import Node, BNode, Literal
from .testutils import GraphHelper
"""Test for graph_diff - much more extensive testing
would certainly be possible"""
_TripleT = Tuple[Node, Node, Node]
_TripleSetT = Set[_TripleT]
class TestDiff(unittest.TestCase):
"""Unicode literals for graph_diff test
(issue 151)"""
def testA(self):
"""with bnode"""
g = rdflib.Graph()
g.add((rdflib.BNode(), rdflib.URIRef("urn:p"), rdflib.Literal("\xe9")))
diff = graph_diff(g, g)
def testB(self):
"""Curiously, this one passes, even before the fix in issue 151"""
g = rdflib.Graph()
g.add((rdflib.URIRef("urn:a"), rdflib.URIRef("urn:p"), rdflib.Literal("\xe9")))
diff = graph_diff(g, g)
@expectedFailure
def test_subsets(self) -> None:
"""
This test verifies that `graph_diff` returns the correct values
for two graphs, `g0` and `g1` where the triples in `g0` is a
subset of the triples in `g1`.
The expectation is that graph_diff reports that there are no
triples only in `g0`, and that there are triples that occur in both
`g0` and `g1`, and that there are triples only in `g1`.
"""
g0_ts: _TripleSetT = set()
bnode = BNode()
g0_ts.update(
{
(bnode, FOAF.name, Literal("Golan Trevize")),
(bnode, RDF.type, FOAF.Person),
}
)
g0 = Graph()
g0 += g0_ts
g1_ts: _TripleSetT = set()
bnode = BNode()
g1_ts.update(
{
*g0_ts,
(bnode, FOAF.name, Literal("Janov Pelorat")),
(bnode, RDF.type, FOAF.Person),
}
)
g1 = Graph()
g1 += g1_ts
result = graph_diff(g0, g1)
in_both, in_first, in_second = GraphHelper.triple_sets(result)
self.assertFalse(in_first)
self.assertTrue(in_second)
self.assertTrue(in_both)
if __name__ == "__main__":
unittest.main()
|