diff options
Diffstat (limited to 'test/extractor/generic/test_constant.py')
-rw-r--r-- | test/extractor/generic/test_constant.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/extractor/generic/test_constant.py b/test/extractor/generic/test_constant.py new file mode 100644 index 0000000..f3ab0a3 --- /dev/null +++ b/test/extractor/generic/test_constant.py @@ -0,0 +1,63 @@ +""" + +Part of the bsie test suite. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# imports +import unittest + +# bsie imports +from bsie.utils import ns +from bsie.utils.node import Node + +# objects to test +from bsie.extractor.generic.constant import Constant + + +## code ## + +class TestConstant(unittest.TestCase): + def test_extract(self): + schema = ''' + bse:author a bsfs:Predicate ; + rdfs:domain bsfs:Entity ; + rdfs:range xsd:string ; + owl:maxCardinality "1"^^xsd:number . + + bse:comment a 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) + # baseline + self.assertSetEqual(set(ext.extract(node, None, predicates)), + {(node, pred, value) for pred, value in tuples}) + # 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}) + + +## main ## + +if __name__ == '__main__': + unittest.main() + +## EOF ## |