aboutsummaryrefslogtreecommitdiffstats
path: root/test/graph/test_walk.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/graph/test_walk.py')
-rw-r--r--test/graph/test_walk.py57
1 files changed, 27 insertions, 30 deletions
diff --git a/test/graph/test_walk.py b/test/graph/test_walk.py
index f9dbc7a..4b844da 100644
--- a/test/graph/test_walk.py
+++ b/test/graph/test_walk.py
@@ -1,15 +1,11 @@
-"""
-Part of the bsfs test suite.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# imports
import unittest
# bsfs imports
from bsfs import schema as bsc
from bsfs.graph import Graph
+from bsfs.graph.ac import NullAC
from bsfs.namespace import Namespace, ns
from bsfs.triple_store.sparql import SparqlStore
from bsfs.utils import URI
@@ -19,8 +15,8 @@ from bsfs.graph.walk import Walk
## code ##
-bse = ns.bse
-bst = Namespace('http://bsfs.ai/schema/Tag')
+ns.bse = ns.bsfs.Entity()
+ns.bst = ns.bsfs.Tag()
class TestWalk(unittest.TestCase):
def setUp(self):
@@ -28,9 +24,9 @@ class TestWalk(unittest.TestCase):
self.schema = bsc.from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
- prefix bsfs: <http://bsfs.ai/schema/>
- prefix bse: <http://bsfs.ai/schema/Entity#>
- prefix bst: <http://bsfs.ai/schema/Tag#>
+ prefix bsfs: <https://schema.bsfs.io/core/>
+ prefix bse: <https://schema.bsfs.io/core/Entity#>
+ prefix bst: <https://schema.bsfs.io/core/Tag#>
bsfs:Entity rdfs:subClassOf bsfs:Node .
bsfs:Tag rdfs:subClassOf bsfs:Node .
@@ -65,7 +61,8 @@ class TestWalk(unittest.TestCase):
''')
self.backend = SparqlStore.Open()
self.user = URI('http://example.com/me')
- self.graph = Graph(self.backend, self.user)
+ self.ac = NullAC(self.backend, self.user)
+ self.graph = Graph(self.backend, self.ac)
self.graph.migrate(self.schema)
# nodes setup
@@ -76,14 +73,14 @@ class TestWalk(unittest.TestCase):
URI('http://example.com/me/tag#1234'),
URI('http://example.com/me/tag#4321')})
# add some instances
- self.ents.set(bse.tag, self.tags)
- self.graph.node(ns.bsfs.Tag, URI('http://example.com/me/tag#1234')).set(bst.label, 'hello')
- self.graph.node(ns.bsfs.Tag, URI('http://example.com/me/tag#4321')).set(bst.label, 'world')
+ self.ents.set(ns.bse.tag, self.tags)
+ self.graph.node(ns.bsfs.Tag, URI('http://example.com/me/tag#1234')).set(ns.bst.label, 'hello')
+ self.graph.node(ns.bsfs.Tag, URI('http://example.com/me/tag#4321')).set(ns.bst.label, 'world')
def test_essentials(self): # __eq__, __hash__, __str__, __repr__
- p_author = self.schema.predicate(bse.author)
- p_tag = self.schema.predicate(bse.tag)
- p_main = self.schema.predicate(bst.main)
+ p_author = self.schema.predicate(ns.bse.author)
+ p_tag = self.schema.predicate(ns.bse.tag)
+ p_main = self.schema.predicate(ns.bst.main)
# comparison
self.assertEqual(Walk(self.ents, [p_tag]), Walk(self.ents, [p_tag]))
self.assertEqual(hash(Walk(self.ents, [p_tag])), hash(Walk(self.ents, [p_tag])))
@@ -99,18 +96,18 @@ class TestWalk(unittest.TestCase):
self.assertNotEqual(hash(Walk(self.tags, [p_author])), hash(Walk(self.tags, [p_main])))
# string conversion
self.assertEqual(str(Walk(self.ents, [p_tag, p_main])),
- 'Walk(@http://bsfs.ai/schema/Entity: http://bsfs.ai/schema/Entity#tag, http://bsfs.ai/schema/Tag#main)')
+ 'Walk(@https://schema.bsfs.io/core/Entity: https://schema.bsfs.io/core/Entity#tag, https://schema.bsfs.io/core/Tag#main)')
self.assertEqual(repr(Walk(self.ents, [p_tag, p_main])),
- 'Walk(http://bsfs.ai/schema/Entity, (http://bsfs.ai/schema/Entity#tag, http://bsfs.ai/schema/Tag#main))')
+ 'Walk(https://schema.bsfs.io/core/Entity, (https://schema.bsfs.io/core/Entity#tag, https://schema.bsfs.io/core/Tag#main))')
def test_tail(self):
self.assertEqual(Walk(self.ents, (
- self.schema.predicate(bse.tag),
+ self.schema.predicate(ns.bse.tag),
)).tail,
self.schema.node(ns.bsfs.Tag))
self.assertEqual(Walk(self.ents, (
- self.schema.predicate(bse.tag),
- self.schema.predicate(bst.main),
+ self.schema.predicate(ns.bse.tag),
+ self.schema.predicate(ns.bst.main),
)).tail,
self.schema.node(ns.bsfs.Entity))
@@ -118,24 +115,24 @@ class TestWalk(unittest.TestCase):
tag_type = self.schema.node(ns.bsfs.Tag)
# step returns a predicate
self.assertEqual(Walk.step(self.schema, tag_type, 'subTagOf'),
- (self.schema.predicate(bst.subTagOf), ))
+ (self.schema.predicate(ns.bst.subTagOf), ))
# invalid step raises an error
self.assertRaises(ValueError, Walk.step, self.schema, tag_type, 'foobar')
# ambiguous step raises an error
self.assertRaises(ValueError, Walk.step, self.schema, tag_type, 'author')
def test_getattr(self): # __getattr__
- walk = Walk(self.ents, (self.schema.predicate(bse.tag), ))
+ walk = Walk(self.ents, (self.schema.predicate(ns.bse.tag), ))
# first step
self.assertEqual(walk.subTagOf, Walk(self.ents, (
- self.schema.predicate(bse.tag),
- self.schema.predicate(bst.subTagOf),
+ self.schema.predicate(ns.bse.tag),
+ self.schema.predicate(ns.bst.subTagOf),
)))
# second step
self.assertEqual(walk.subTagOf.main, Walk(self.ents, (
- self.schema.predicate(bse.tag),
- self.schema.predicate(bst.subTagOf),
- self.schema.predicate(bst.main),
+ self.schema.predicate(ns.bse.tag),
+ self.schema.predicate(ns.bst.subTagOf),
+ self.schema.predicate(ns.bst.main),
)))
# invalid step raises an error
self.assertRaises(ValueError, getattr, walk, 'foobar')
@@ -143,7 +140,7 @@ class TestWalk(unittest.TestCase):
self.assertRaises(ValueError, getattr, walk, 'author')
def test_get(self): # get, __call__
- walk = Walk(self.ents, (self.schema.predicate(bse.tag), ))
+ walk = Walk(self.ents, (self.schema.predicate(ns.bse.tag), ))
tags = {
self.graph.node(ns.bsfs.Tag, URI('http://example.com/me/tag#1234')),
self.graph.node(ns.bsfs.Tag, URI('http://example.com/me/tag#4321'))}