diff options
Diffstat (limited to 'test/extractor/generic/test_constant.py')
-rw-r--r-- | test/extractor/generic/test_constant.py | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/test/extractor/generic/test_constant.py b/test/extractor/generic/test_constant.py index f3ab0a3..7fdb8ac 100644 --- a/test/extractor/generic/test_constant.py +++ b/test/extractor/generic/test_constant.py @@ -20,39 +20,64 @@ from bsie.extractor.generic.constant import Constant class TestConstant(unittest.TestCase): def test_extract(self): schema = ''' - bse:author a bsfs:Predicate ; + bse:author rdfs:subClassOf bsfs:Predicate ; rdfs:domain bsfs:Entity ; rdfs:range xsd:string ; owl:maxCardinality "1"^^xsd:number . - - bse:comment a bsfs:Predicate ; + bse:comment rdfs:subClassOf bsfs:Predicate ; rdfs:domain bsfs:Entity ; rdfs:range xsd:string ; owl:maxCardinality "INF"^^xsd:number . - ''' tuples = [ (ns.bse.author, 'Me, myself, and I'), (ns.bse.comment, 'the quick brown fox jumps over the lazy dog.'), ] - node = Node(ns.bsfs.Entity, '') # Blank node - predicates = (ns.bse.author, ns.bse.comment) ext = Constant(schema, tuples) + node = Node(ns.bsfs.Entity, '') # Blank node + p_author = ext.schema.predicate(ns.bse.author) + p_comment = ext.schema.predicate(ns.bse.comment) + entity = ext.schema.node(ns.bsfs.Node).get_child(ns.bsfs.Entity) + string = ext.schema.literal(ns.bsfs.Literal).get_child(ns.xsd.string) # baseline - self.assertSetEqual(set(ext.extract(node, None, predicates)), - {(node, pred, value) for pred, value in tuples}) + self.assertSetEqual(set(ext.extract(node, None, (p_author, p_comment))), + {(node, p_author, 'Me, myself, and I'), + (node, p_comment, 'the quick brown fox jumps over the lazy dog.')}) # predicates is respected - self.assertSetEqual(set(ext.extract(node, None, (ns.bse.author, ns.bse.foobar))), - {(node, ns.bse.author, 'Me, myself, and I')}) - self.assertSetEqual(set(ext.extract(node, None, (ns.bse.comment, ns.bse.foobar))), - {(node, ns.bse.comment, 'the quick brown fox jumps over the lazy dog.')}) - self.assertSetEqual(set(ext.extract(node, None, (ns.bse.foobar, ns.bse.barfoo))), set()) - - # FIXME: should change! - # for now: no schema compliance - ext = Constant('', tuples) - self.assertSetEqual(set(ext.extract(node, None, predicates)), - {(node, pred, value) for pred, value in tuples}) + p_foobar = ext.schema.predicate(ns.bsfs.Predicate).get_child(ns.bse.foobar, domain=entity, range=entity) + self.assertSetEqual(set(ext.extract(node, None, (p_author, p_foobar))), + {(node, p_author, 'Me, myself, and I')}) + self.assertSetEqual(set(ext.extract(node, None, (p_comment, p_foobar))), + {(node, p_comment, 'the quick brown fox jumps over the lazy dog.')}) + p_barfoo = ext.schema.predicate(ns.bse.author).get_child(ns.bse.comment, domain=entity, range=string) + self.assertSetEqual(set(ext.extract(node, None, (p_foobar, p_barfoo))), set()) + + def test_construct(self): + # schema compliance + schema = ''' + bse:author rdfs:subClassOf bsfs:Predicate ; + rdfs:domain bsfs:Entity ; + rdfs:range xsd:string ; + owl:maxCardinality "1"^^xsd:number . + bse:comment rdfs:subClassOf bsfs:Predicate ; + rdfs:domain bsfs:Entity ; + rdfs:range xsd:string ; + owl:maxCardinality "INF"^^xsd:number . + ''' + # can create a schema + self.assertIsInstance(Constant(schema, [ + (ns.bse.author, 'Me, myself, and I'), + (ns.bse.comment, 'the quick brown fox jumps over the lazy dog.'), + ]), Constant) + # predicates are validated + self.assertRaises(KeyError, Constant, schema, [ + (ns.bse.author, 'Me, myself, and I'), + (ns.bse.foobar, 'foobar!')]) + # FIXME: values are validated + #class Foo(): pass # not string compatible + #self.assertRaises(ValueError, Constant, schema, [ + # (ns.bse.author, Foo())]) + ## main ## |