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.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/apps/test_loader.py b/test/apps/test_loader.py
new file mode 100644
index 0000000..4670266
--- /dev/null
+++ b/test/apps/test_loader.py
@@ -0,0 +1,83 @@
+
+# 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()}, {
+ 'https://schema.bsfs.io/core/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 bsn:Entity ;
+ rdfs:range xsd:string ;
+ bsfs:unique "true"^^xsd:boolean .
+ ''',
+ 'tuples': [['https://schema.bsfs.io/ie/Node/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()}, {
+ 'https://schema.bsfs.io/ie/Node/Entity#author',
+ 'https://schema.bsfs.io/core/Predicate',
+ 'https://schema.bsfs.io/ie/Node/Entity#filename',
+ 'https://schema.bsfs.io/ie/Node/Entity#colors_spatial_0658f2234a054e1dd59a14462c89f7733e019160419c796356aa831498bd0a04',
+ 'https://schema.bsfs.io/ie/Node/Entity#preview',
+ 'https://schema.bsfs.io/ie/Node/Preview#width',
+ 'https://schema.bsfs.io/ie/Node/Preview#height',
+ 'https://schema.bsfs.io/ie/Node/Preview#asset',
+ })
+
+ # config file must exist
+ self.assertRaises(OSError, load_pipeline, 'invalid.yaml')
+
+
+## main ##
+
+if __name__ == '__main__':
+ unittest.main()
+
+## EOF ##