diff options
Diffstat (limited to 'test/triple_store/sparql/test_utils.py')
-rw-r--r-- | test/triple_store/sparql/test_utils.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/test/triple_store/sparql/test_utils.py b/test/triple_store/sparql/test_utils.py index 8f894bb..44a1299 100644 --- a/test/triple_store/sparql/test_utils.py +++ b/test/triple_store/sparql/test_utils.py @@ -16,6 +16,8 @@ from bsfs.triple_store.sparql.utils import GenHopName, Query ## code ## +ns.bse = ns.bsfs.Entity() + class TestGenHopName(unittest.TestCase): def test_next(self): # baseline @@ -40,7 +42,7 @@ class TestGenHopName(unittest.TestCase): class TestQuery(unittest.TestCase): def setUp(self): - self.root_type = 'http://bsfs.ai/schema/Entity' + self.root_type = 'https://schema.bsfs.io/core/Entity' self.root_head = '?root' self.select = (('?head', 'name'), ) self.where = f'?root <{ns.bse.tag}> ?head' @@ -56,8 +58,8 @@ class TestQuery(unittest.TestCase): self.assertEqual(q, Query(self.root_type, self.root_head, self.select, self.where)) self.assertEqual(hash(q), hash(Query(self.root_type, self.root_head, self.select, self.where))) # comparison respects root_type - self.assertNotEqual(q, Query('http://bsfs.ai/schema/Tag', self.root_head, self.select, self.where)) - self.assertNotEqual(hash(q), hash(Query('http://bsfs.ai/schema/Tag', self.root_head, self.select, self.where))) + self.assertNotEqual(q, Query('https://schema.bsfs.io/core/Tag', self.root_head, self.select, self.where)) + self.assertNotEqual(hash(q), hash(Query('https://schema.bsfs.io/core/Tag', self.root_head, self.select, self.where))) # comparison respects root_head self.assertNotEqual(q, Query(self.root_type, '?foo', self.select, self.where)) self.assertNotEqual(hash(q), hash(Query(self.root_type, '?foo', self.select, self.where))) @@ -69,7 +71,7 @@ class TestQuery(unittest.TestCase): self.assertNotEqual(hash(q), hash(Query(self.root_type, self.root_head, self.select, '?root bse:filename ?head'))) # string conversion self.assertEqual(str(q), q.query) - self.assertEqual(repr(q), "Query(http://bsfs.ai/schema/Entity, ?root, (('?head', 'name'),), ?root <http://bsfs.ai/schema/Entity#tag> ?head)") + self.assertEqual(repr(q), "Query(https://schema.bsfs.io/core/Entity, ?root, (('?head', 'name'),), ?root <https://schema.bsfs.io/core/Entity#tag> ?head)") def test_add(self): q = Query(self.root_type, self.root_head, self.select, self.where) @@ -77,7 +79,7 @@ class TestQuery(unittest.TestCase): self.assertRaises(TypeError, operator.add, q, 1234) self.assertRaises(TypeError, operator.add, q, 'foobar') # root type and head must match - self.assertRaises(ValueError, operator.add, q, Query('http://bsfs.ai/schema/Tag', self.root_head)) + self.assertRaises(ValueError, operator.add, q, Query('https://schema.bsfs.io/core/Node/Tag', self.root_head)) self.assertRaises(ValueError, operator.add, q, Query(self.root_type, '?foobar')) # select and were are combined combo = q + Query(self.root_type, self.root_head, (('?foo', 'bar'), ), f'?root <{ns.bse.filename}> ?foo') @@ -113,23 +115,23 @@ class TestQuery(unittest.TestCase): return value # query composes a valid query q = Query(self.root_type, self.root_head, self.select, self.where) - self.assertEqual(normalize(q.query), normalize(f'select distinct ?root (?head as ?name) where {{ ?root <{ns.rdf.type}>/<{ns.rdfs.subClassOf}>* <http://bsfs.ai/schema/Entity> . ?root <{ns.bse.tag}> ?head }} order by str(?root)')) + self.assertEqual(normalize(q.query), normalize(f'select distinct ?root (?head as ?name) where {{ ?root <{ns.rdf.type}>/<{ns.rdfs.subClassOf}>* <https://schema.bsfs.io/core/Entity> . ?root <{ns.bse.tag}> ?head }} order by str(?root)')) # select and where are optional q = Query(self.root_type, self.root_head) - self.assertEqual(normalize(q.query), normalize(f'select distinct ?root where {{ ?root <{ns.rdf.type}>/<{ns.rdfs.subClassOf}>* <http://bsfs.ai/schema/Entity> . }} order by str(?root)')) + self.assertEqual(normalize(q.query), normalize(f'select distinct ?root where {{ ?root <{ns.rdf.type}>/<{ns.rdfs.subClassOf}>* <https://schema.bsfs.io/core/Entity> . }} order by str(?root)')) # select and where need not to correspond q = Query(self.root_type, self.root_head, (('?head', 'name'), )) - self.assertEqual(normalize(q.query), normalize(f'select distinct ?root (?head as ?name) where {{ ?root <{ns.rdf.type}>/<{ns.rdfs.subClassOf}>* <http://bsfs.ai/schema/Entity> . }} order by str(?root)')) + self.assertEqual(normalize(q.query), normalize(f'select distinct ?root (?head as ?name) where {{ ?root <{ns.rdf.type}>/<{ns.rdfs.subClassOf}>* <https://schema.bsfs.io/core/Entity> . }} order by str(?root)')) # query is used for string representation self.assertEqual(str(q), q.query) def test_call(self): graph = rdflib.Graph() # schema - graph.add((rdflib.URIRef('http://bsfs.ai/schema/Document'), rdflib.URIRef(ns.rdfs.subClassOf), rdflib.URIRef('http://bsfs.ai/schema/Entity'))) + graph.add((rdflib.URIRef('https://schema.bsfs.io/core/Document'), rdflib.URIRef(ns.rdfs.subClassOf), rdflib.URIRef('https://schema.bsfs.io/core/Entity'))) # nodes - graph.add((rdflib.URIRef('http://example.com/entity#1234'), rdflib.URIRef(ns.rdf.type), rdflib.URIRef('http://bsfs.ai/schema/Entity'))) - graph.add((rdflib.URIRef('http://example.com/doc#1234'), rdflib.URIRef(ns.rdf.type), rdflib.URIRef('http://bsfs.ai/schema/Document'))) + graph.add((rdflib.URIRef('http://example.com/entity#1234'), rdflib.URIRef(ns.rdf.type), rdflib.URIRef('https://schema.bsfs.io/core/Entity'))) + graph.add((rdflib.URIRef('http://example.com/doc#1234'), rdflib.URIRef(ns.rdf.type), rdflib.URIRef('https://schema.bsfs.io/core/Document'))) # links graph.add((rdflib.URIRef('http://example.com/entity#1234'), rdflib.URIRef(ns.bse.tag), rdflib.Literal('tag#1234', datatype=rdflib.XSD.string))) graph.add((rdflib.URIRef('http://example.com/doc#1234'), rdflib.URIRef(ns.bse.tag), rdflib.Literal('tag#1234', datatype=rdflib.XSD.string))) |