# HG changeset patch # User drewp@bigasterisk.com # Date 2013-01-15 21:01:03 # Node ID f7ae0faa0a442d2a71df0a9b1a04b486393531ff # Parent 87150923dcaa15baa337212ccbd76fd360ac0b8b makefile and nosetests path fix. new contextsForStatement Ignore-this: 424b0fa004ff5366b8035af42d9d9d0d diff --git a/light9/rdfdb/rdflibpatch.py b/light9/rdfdb/rdflibpatch.py --- a/light9/rdfdb/rdflibpatch.py +++ b/light9/rdfdb/rdflibpatch.py @@ -1,6 +1,11 @@ """ this is a proposal for a ConjunctiveGraph method in rdflib """ +import sys +if sys.path[0] == '/usr/lib/python2.7/dist-packages': + # nosetests puts this in + sys.path = sys.path[1:] + import unittest from rdflib import ConjunctiveGraph, URIRef as U @@ -73,7 +78,24 @@ def inContext(graph, newContext): are in newContext """ return graphFromQuads([(s,p,o,newContext) for s,p,o in graph]) - + +def contextsForStatement(graph, triple): + return [q[3] for q in graph.quads(triple)] + + +A = U("http://a"); B = U("http://b") +class TestContextsForStatement(unittest.TestCase): + def testNotFound(self): + g = graphFromQuads([(A,A,A,A)]) + self.assertEqual(contextsForStatement(g, (B,B,B)), []) + def testOneContext(self): + g = graphFromQuads([(A,A,A,A), (A,A,B,B)]) + self.assertEqual(contextsForStatement(g, (A,A,A)), [A]) + def testTwoContexts(self): + g = graphFromQuads([(A,A,A,A), (A,A,A,B)]) + self.assertEqual(sorted(contextsForStatement(g, (A,A,A))), sorted([A,B])) + + class TestGraphFromQuads(unittest.TestCase): nqOut = ' .\n' diff --git a/makefile b/makefile new file mode 100644 --- /dev/null +++ b/makefile @@ -0,0 +1,2 @@ +tests: + bin/python `which nosetests` --no-path-adjustment light9.rdfdb.rdflibpatch