aboutsummaryrefslogtreecommitdiffstats
path: root/test/apps/test_loader.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/apps/test_loader.py')
-rw-r--r--test/apps/test_loader.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/test/apps/test_loader.py b/test/apps/test_loader.py
new file mode 100644
index 0000000..09a9162
--- /dev/null
+++ b/test/apps/test_loader.py
@@ -0,0 +1,88 @@
+"""
+
+Part of the bsie test suite.
+A copy of the license is provided with the project.
+Author: Matthias Baumgartner, 2022
+"""
+# standard imports
+import os
+import tempfile
+import unittest
+
+# external imports
+import yaml
+
+# objects to test
+from bsie.apps._loader import load_pipeline
+
+
+## code ##
+
+class TestLoader(unittest.TestCase):
+ def test_load_pipeline(self):
+ # config file can be empty
+ config = {
+ 'ReaderBuilder': {},
+ 'ExtractorBuilder': []
+ }
+ # create config file
+ _, path = tempfile.mkstemp(prefix='bsie-test-', suffix='.yaml')
+ with open(path, 'wt') as cfile:
+ yaml.dump(config, cfile)
+ # pipeline contains only default predicates
+ pipeline = load_pipeline(path)
+ self.assertSetEqual({pred.uri for pred in pipeline.schema.predicates()}, {
+ 'http://bsfs.ai/schema/Predicate',
+ })
+
+ # pipeline is built according to configured extractors
+ config = {
+ 'ReaderBuilder': {},
+ 'ExtractorBuilder': [
+ {'bsie.extractor.preview.Preview': {
+ 'max_sides': [50],
+ }},
+ {'bsie.extractor.generic.path.Path': {}},
+ {'bsie.extractor.generic.constant.Constant': {
+ 'schema': '''
+ bse:author rdfs:subClassOf bsfs:Predicate ;
+ rdfs:domain bsfs:Entity ;
+ rdfs:range xsd:string ;
+ bsfs:unique "true"^^xsd:boolean .
+ ''',
+ 'tuples': [['http://bsfs.ai/schema/Entity#author', 'Me, myself, and I']],
+ }},
+ {'bsie.extractor.image.colors_spatial.ColorsSpatial': {
+ 'width': 2,
+ 'height': 2,
+ 'exp': 2,
+ }},
+ ]
+ }
+ # create config file
+ _, path = tempfile.mkstemp(prefix='bsie-test-', suffix='.yaml')
+ with open(path, 'wt') as cfile:
+ yaml.dump(config, cfile)
+ # pipeline contains all defined predicates
+ pipeline = load_pipeline(path)
+ self.assertSetEqual({pred.uri for pred in pipeline.schema.predicates()}, {
+ 'http://bsfs.ai/schema/Entity#author',
+ 'http://bsfs.ai/schema/Predicate',
+ 'http://bsfs.ai/schema/Entity#filename',
+ 'http://bsfs.ai/schema/Entity/colors_spatial#0658f2234a054e1dd59a14462c89f7733e019160419c796356aa831498bd0a04',
+ 'http://bsfs.ai/schema/Entity#preview',
+ 'http://bsfs.ai/schema/Preview#width',
+ 'http://bsfs.ai/schema/Preview#height',
+ 'http://bsfs.ai/schema/Preview#asset',
+ })
+
+ # config file must exist
+ self.assertRaises(OSError, load_pipeline, 'invalid.yaml')
+
+
+## main ##
+
+if __name__ == '__main__':
+ unittest.main()
+
+## EOF ##