def testDiff(self): graph0 = comp_graph.ComparableGraph() graph1 = comp_graph.ComparableGraph() graph0.parse(source="./examples/example1.ttl", format="n3") graph1.parse(source="./examples/example2.ttl", format="n3") diffTupel = graph0.diff(graph1) # tst short for tests tst = [ r"^http:\/\/example\.org\/subjectT\shttp:\/\/example\.org\/predicate\s[a-zA-Z0-9]+$", r"^[a-zA-Z0-9]+\shttp:\/\/example\.org\/predicate\s[a-zA-Z0-9]+$", r"^[a-zA-Z0-9]+\shttp:\/\/example\.org\/predicate\s[a-zA-Z0-9]+$" ] for aGraph in diffTupel[0]: for subj, pred, obje in aGraph: done = None for te in tst: if (re.match(te, "{} {} {}".format(subj, pred, obje))): done = te self.assertNotEqual(done, None) tst.remove(done) assert (tst.__len__() == 0) tst = [ r"^http:\/\/example\.org\/subject\shttp:\/\/example\.org\/predicate\s[a-zA-Z0-9]+$", r"^[a-zA-Z0-9]+\shttp:\/\/example\.org\/predicate\s[a-zA-Z0-9]+$", r"^[a-zA-Z0-9]+\shttp:\/\/example\.org\/predicate\s[a-zA-Z0-9]+$" ] for aGraph in diffTupel[1]: for subj, pred, obje in aGraph: done = None for te in tst: if (re.match(te, "{} {} {}".format(subj, pred, obje))): done = te self.assertNotEqual(done, None) tst.remove(done) assert (tst.__len__() == 0)
def testNotEqualGraphs(self): graphA = comp_graph.ComparableGraph() graphB = comp_graph.ComparableGraph() graphA.parse('examples/example1.ttl', format='turtle') graphB.parse('examples/example2.ttl', format='n3') self.assertFalse(graphA == graphB) self.assertNotEqual(graphA, graphB)
def testEqualGraphs(self): graphA = comp_graph.ComparableGraph() graphB = comp_graph.ComparableGraph() graphA.parse('examples/isoSimpleGraph1.ttl', format='n3') graphB.parse('examples/isoSimpleGraph1.ttl', format='n3') self.assertTrue(graphA == graphB) self.assertEqual(graphA, graphB)
def testSet(self): graphA = comp_graph.ComparableGraph() graphA.parse('examples/example1.ttl', format='turtle') sub = rdflib.URIRef("http://test.com/subject") pre = rdflib.URIRef("http://test.com/predicate") obj = rdflib.URIRef("http://test.com/object") graphA.set((sub, pre, obj)) assert((sub, pre, obj) in graphA)
def testAddN(self): graphA = comp_graph.ComparableGraph() graphA.parse('examples/example1.ttl', format='turtle') sub = rdflib.URIRef("http://test.com/subject") pre = rdflib.URIRef("http://test.com/predicate") obj = rdflib.URIRef("http://test.com/object") con = rdflib.URIRef("http://test.com/context") graphA.addN([(sub, pre, obj, con)])
def testUpdate(self): graphA = comp_graph.ComparableGraph() graphA.parse('examples/example1.ttl', format='turtle') sub = rdflib.URIRef("http://test.com/subject") pre = rdflib.URIRef("http://test.com/predicate") obj = rdflib.URIRef("http://test.com/object") graphA.add((sub, pre, obj)) graphA.update(''' INSERT { ?s <https://test.com/predicate#x> <https://test.com/object#x> . } WHERE { ?s <http://test.com/predicate> <http://test.com/object> . } ''') # if I bring rdflib.URIRef("https://test.com/object#x") into the next line # and then back, the test suddenly passes exactly one time # the test seems to randomly fail assert((sub, rdflib.URIRef("https://test.com/predicate#x"), rdflib.URIRef("https://test.com/object#x")) in graphA)
from atomicgraphs import comp_graph graph0 = comp_graph.ComparableGraph() graph1 = comp_graph.ComparableGraph() graph0.parse(source="./examples/example1.ttl", format="n3") graph1.parse(source="./examples/example2.ttl", format="n3") diffTupel = graph0.diff(graph1) print("{} {}".format(len(diffTupel[0]), len(diffTupel[1]))) print("--------------------------------------------------") for aGraph in diffTupel[0]: print("-") print(aGraph.__repr__()) for subj, pred, obj in aGraph: print("{} {} {}".format(subj, pred, obj)) print("==================================================") for aGraph in diffTupel[1]: print("+") print(aGraph.__repr__()) for subj, pred, obj in aGraph: print("{} {} {}".format(subj, pred, obj)) print(graph0 == graph1)