aboutsummaryrefslogtreecommitdiffstats
path: root/test/triple_store/sparql/test_utils.py
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-03-05 19:25:17 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-03-05 19:25:17 +0100
commite4845c627e97a6d125bf33d9e7a4a8d373d7fc4a (patch)
tree634198c34aae3c0306ce30ac7452abd7b53a14e8 /test/triple_store/sparql/test_utils.py
parent9b490d19dcebc0fc24cb2ab89a783f1f7d6147f7 (diff)
parent3ae93a405724ca6b5ddeb0b458fcc95685f83f09 (diff)
downloadbsfs-e4845c627e97a6d125bf33d9e7a4a8d373d7fc4a.tar.gz
bsfs-e4845c627e97a6d125bf33d9e7a4a8d373d7fc4a.tar.bz2
bsfs-e4845c627e97a6d125bf33d9e7a4a8d373d7fc4a.zip
Merge branch 'mb/diogenes' into develop
Diffstat (limited to 'test/triple_store/sparql/test_utils.py')
-rw-r--r--test/triple_store/sparql/test_utils.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/test/triple_store/sparql/test_utils.py b/test/triple_store/sparql/test_utils.py
index 073b8f8..44a1299 100644
--- a/test/triple_store/sparql/test_utils.py
+++ b/test/triple_store/sparql/test_utils.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsfs test suite.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
import operator
import re
@@ -21,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
@@ -45,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'
@@ -61,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)))
@@ -74,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)
@@ -82,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')
@@ -118,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 ?root (?head as ?name) where {{ ?root <{ns.rdf.type}>/<{ns.rdfs.subClassOf}>* <http://bsfs.ai/schema/Entity> . ?root <{ns.bse.tag}> ?head }}'))
+ 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 ?root where {{ ?root <{ns.rdf.type}>/<{ns.rdfs.subClassOf}>* <http://bsfs.ai/schema/Entity> . }}'))
+ 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 ?root (?head as ?name) where {{ ?root <{ns.rdf.type}>/<{ns.rdfs.subClassOf}>* <http://bsfs.ai/schema/Entity> . }}'))
+ 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)))