aboutsummaryrefslogtreecommitdiffstats
path: root/test/apps
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-03-01 17:07:06 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-03-01 17:07:06 +0100
commit464cc6cb54f55f6255bf0a485533c181d6018303 (patch)
tree0a2447aac75d91230b4fdbaddf129d408e5d5b7e /test/apps
parent02cd75f31120a766a35fc0ae00f8d0711c1c0ae9 (diff)
downloadbsie-464cc6cb54f55f6255bf0a485533c181d6018303.tar.gz
bsie-464cc6cb54f55f6255bf0a485533c181d6018303.tar.bz2
bsie-464cc6cb54f55f6255bf0a485533c181d6018303.zip
load config from file
Diffstat (limited to 'test/apps')
-rw-r--r--test/apps/test_index.py64
-rw-r--r--test/apps/test_info.py44
-rw-r--r--test/apps/test_loader.py88
3 files changed, 166 insertions, 30 deletions
diff --git a/test/apps/test_index.py b/test/apps/test_index.py
index d1e7140..a877684 100644
--- a/test/apps/test_index.py
+++ b/test/apps/test_index.py
@@ -8,10 +8,12 @@ Author: Matthias Baumgartner, 2022
import contextlib
import io
import os
+import tempfile
import unittest
# external imports
import rdflib
+import yaml
# bsie imports
from bsie.utils import ns
@@ -23,17 +25,52 @@ from bsie.apps.index import main
## code ##
class TestIndex(unittest.TestCase):
+ def setUp(self):
+ 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
+ _, self.config_path = tempfile.mkstemp(prefix='bsie-test-', suffix='.yaml')
+ with open(self.config_path, 'wt') as cfile:
+ yaml.dump(config, cfile)
+
+ def tearDown(self):
+ if os.path.exists(self.config_path):
+ os.unlink(self.config_path)
+
def test_disclaimer(self):
print('Please wait, this test will take about 25 seconds')
def test_main_invalid(self):
outbuf = io.StringIO()
with contextlib.redirect_stdout(outbuf):
- bsfs = main([os.path.join(os.path.dirname(__file__), 'inexistent-file.t')])
+ bsfs = main(['--config', self.config_path, os.path.join(os.path.dirname(__file__), 'inexistent-file.t')])
self.assertEqual(outbuf.getvalue().strip(), '')
def test_main(self):
bsfs = main([
+ '--config',
+ self.config_path,
'-r',
'--host', 'http://example.com',
'--user', 'me',
@@ -48,57 +85,44 @@ class TestIndex(unittest.TestCase):
(rdflib.URIRef(pre_file + '2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + '2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + '2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('alpha_second', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + '2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('696', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + '441f3d10c8ff489fe8e33e639606512f6c463151cc429de7e554b9af670c2ece'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + '441f3d10c8ff489fe8e33e639606512f6c463151cc429de7e554b9af670c2ece'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + '441f3d10c8ff489fe8e33e639606512f6c463151cc429de7e554b9af670c2ece'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('omega_second', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + '441f3d10c8ff489fe8e33e639606512f6c463151cc429de7e554b9af670c2ece'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('503', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + '69b98ecf7aff3e95b09688ba93331678eb8397817111f674c9558e6dd8f5e871'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + '69b98ecf7aff3e95b09688ba93331678eb8397817111f674c9558e6dd8f5e871'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + '69b98ecf7aff3e95b09688ba93331678eb8397817111f674c9558e6dd8f5e871'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('td_first', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + '69b98ecf7aff3e95b09688ba93331678eb8397817111f674c9558e6dd8f5e871'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('911', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + '78f7eb7f0d8221cdb2cb26c978fa42a11f75eb87becc768f4474134cb1e06926'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + '78f7eb7f0d8221cdb2cb26c978fa42a11f75eb87becc768f4474134cb1e06926'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + '78f7eb7f0d8221cdb2cb26c978fa42a11f75eb87becc768f4474134cb1e06926'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('testfile', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + '78f7eb7f0d8221cdb2cb26c978fa42a11f75eb87becc768f4474134cb1e06926'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('885', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + '80818b8ec2ee1919116dba9c8a7e0a4608313cf3b463cd88e9ed77a700dd92d3'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + '80818b8ec2ee1919116dba9c8a7e0a4608313cf3b463cd88e9ed77a700dd92d3'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + '80818b8ec2ee1919116dba9c8a7e0a4608313cf3b463cd88e9ed77a700dd92d3'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('bar_first', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + '80818b8ec2ee1919116dba9c8a7e0a4608313cf3b463cd88e9ed77a700dd92d3'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('956', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + '976d2ea0e58488678cc7e435fbfadabfb6eb6cf50ad51862f38f73729ed11795'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + '976d2ea0e58488678cc7e435fbfadabfb6eb6cf50ad51862f38f73729ed11795'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + '976d2ea0e58488678cc7e435fbfadabfb6eb6cf50ad51862f38f73729ed11795'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('omega_first', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + '976d2ea0e58488678cc7e435fbfadabfb6eb6cf50ad51862f38f73729ed11795'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('648', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + '997e2fbb7494a3818ec782d2bc87bf1cffafba6b9c0f658e4a6c18a723e944d3'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + '997e2fbb7494a3818ec782d2bc87bf1cffafba6b9c0f658e4a6c18a723e944d3'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + '997e2fbb7494a3818ec782d2bc87bf1cffafba6b9c0f658e4a6c18a723e944d3'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('alpha_first', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + '997e2fbb7494a3818ec782d2bc87bf1cffafba6b9c0f658e4a6c18a723e944d3'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('754', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + 'a8af899ecdab60dfaea8ec7f934053624c80a1054539e163f2c7eaa986c2777d'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + 'a8af899ecdab60dfaea8ec7f934053624c80a1054539e163f2c7eaa986c2777d'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + 'a8af899ecdab60dfaea8ec7f934053624c80a1054539e163f2c7eaa986c2777d'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('foo_second', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + 'a8af899ecdab60dfaea8ec7f934053624c80a1054539e163f2c7eaa986c2777d'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('585', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + 'b8fd7fba818254166a6043195004138ebda6923e012442f819a2c49671136c70'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + 'b8fd7fba818254166a6043195004138ebda6923e012442f819a2c49671136c70'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + 'b8fd7fba818254166a6043195004138ebda6923e012442f819a2c49671136c70'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('bar_second', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + 'b8fd7fba818254166a6043195004138ebda6923e012442f819a2c49671136c70'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('636', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + 'd43758ace82154a1cc10ca0dfef63cb20dd831f9c87edd6dc06539eefe67371d'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + 'd43758ace82154a1cc10ca0dfef63cb20dd831f9c87edd6dc06539eefe67371d'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + 'd43758ace82154a1cc10ca0dfef63cb20dd831f9c87edd6dc06539eefe67371d'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('foo_first', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + 'd43758ace82154a1cc10ca0dfef63cb20dd831f9c87edd6dc06539eefe67371d'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('546', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + 'd803187cbf3676ae9d38126270a6152c60431589aa3bb3824baf8954e9c097f1'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + 'd803187cbf3676ae9d38126270a6152c60431589aa3bb3824baf8954e9c097f1'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + 'd803187cbf3676ae9d38126270a6152c60431589aa3bb3824baf8954e9c097f1'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('td_second', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + 'd803187cbf3676ae9d38126270a6152c60431589aa3bb3824baf8954e9c097f1'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('703', datatype=rdflib.XSD.integer)),
(rdflib.URIRef(pre_file + 'accb115d266ad60c53cd01a7f7130f245886ce8eaf69bc85319febc11d9fe089'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)),
(rdflib.URIRef(pre_file + 'accb115d266ad60c53cd01a7f7130f245886ce8eaf69bc85319febc11d9fe089'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)),
(rdflib.URIRef(pre_file + 'accb115d266ad60c53cd01a7f7130f245886ce8eaf69bc85319febc11d9fe089'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('testimage.jpg', datatype=rdflib.XSD.string)),
- (rdflib.URIRef(pre_file + 'accb115d266ad60c53cd01a7f7130f245886ce8eaf69bc85319febc11d9fe089'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('349264', datatype=rdflib.XSD.integer)),
# features
(rdflib.URIRef(pre_file + 'accb115d266ad60c53cd01a7f7130f245886ce8eaf69bc85319febc11d9fe089'), rdflib.URIRef('http://bsfs.ai/schema/Entity/colors_spatial#0658f2234a054e1dd59a14462c89f7733e019160419c796356aa831498bd0a04'),
rdflib.Literal(
'(91, 127, 121, 94, 138, 167, 163, 134, 190, 138, 170, 156, 121, 142, 159)',
datatype=rdflib.URIRef('http://ie.bsfs.ai/schema/Feature/ColorsSpatial#0658f2234a054e1dd59a14462c89f7733e019160419c796356aa831498bd0a04'))),
- (rdflib.URIRef(pre_file + 'accb115d266ad60c53cd01a7f7130f245886ce8eaf69bc85319febc11d9fe089'), rdflib.URIRef(ns.bse.filesize), rdflib.Literal('349264', datatype=rdflib.XSD.integer)),
# links to previews
(rdflib.URIRef(pre_file + '2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647'), rdflib.URIRef(ns.bse.preview), rdflib.URIRef(pre_preview + '79cb8a7e6369361a4f4cb7ff729c1ed3fcf87204769623d6fbd6ebfae601e5c7_s50')),
(rdflib.URIRef(pre_file + '441f3d10c8ff489fe8e33e639606512f6c463151cc429de7e554b9af670c2ece'), rdflib.URIRef(ns.bse.preview), rdflib.URIRef(pre_preview + 'a8b3245636074d5370283b690281abda8ffdff12ce8b1af77c8bc0a4c85be860_s50')),
@@ -211,38 +235,26 @@ class TestIndex(unittest.TestCase):
self.assertTrue((set(outbuf.getvalue().split('\n')) - {''}).issuperset({
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647) Predicate({ns.bse.filename}) alpha_second',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647) Predicate({ns.bse.filesize}) 696',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#441f3d10c8ff489fe8e33e639606512f6c463151cc429de7e554b9af670c2ece) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#441f3d10c8ff489fe8e33e639606512f6c463151cc429de7e554b9af670c2ece) Predicate({ns.bse.filename}) omega_second',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#441f3d10c8ff489fe8e33e639606512f6c463151cc429de7e554b9af670c2ece) Predicate({ns.bse.filesize}) 503',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#69b98ecf7aff3e95b09688ba93331678eb8397817111f674c9558e6dd8f5e871) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#69b98ecf7aff3e95b09688ba93331678eb8397817111f674c9558e6dd8f5e871) Predicate({ns.bse.filename}) td_first',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#69b98ecf7aff3e95b09688ba93331678eb8397817111f674c9558e6dd8f5e871) Predicate({ns.bse.filesize}) 911',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#78f7eb7f0d8221cdb2cb26c978fa42a11f75eb87becc768f4474134cb1e06926) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#78f7eb7f0d8221cdb2cb26c978fa42a11f75eb87becc768f4474134cb1e06926) Predicate({ns.bse.filename}) testfile',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#78f7eb7f0d8221cdb2cb26c978fa42a11f75eb87becc768f4474134cb1e06926) Predicate({ns.bse.filesize}) 885',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#80818b8ec2ee1919116dba9c8a7e0a4608313cf3b463cd88e9ed77a700dd92d3) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#80818b8ec2ee1919116dba9c8a7e0a4608313cf3b463cd88e9ed77a700dd92d3) Predicate({ns.bse.filename}) bar_first',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#80818b8ec2ee1919116dba9c8a7e0a4608313cf3b463cd88e9ed77a700dd92d3) Predicate({ns.bse.filesize}) 956',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#976d2ea0e58488678cc7e435fbfadabfb6eb6cf50ad51862f38f73729ed11795) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#976d2ea0e58488678cc7e435fbfadabfb6eb6cf50ad51862f38f73729ed11795) Predicate({ns.bse.filename}) omega_first',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#976d2ea0e58488678cc7e435fbfadabfb6eb6cf50ad51862f38f73729ed11795) Predicate({ns.bse.filesize}) 648',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#997e2fbb7494a3818ec782d2bc87bf1cffafba6b9c0f658e4a6c18a723e944d3) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#997e2fbb7494a3818ec782d2bc87bf1cffafba6b9c0f658e4a6c18a723e944d3) Predicate({ns.bse.filename}) alpha_first',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#997e2fbb7494a3818ec782d2bc87bf1cffafba6b9c0f658e4a6c18a723e944d3) Predicate({ns.bse.filesize}) 754',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#a8af899ecdab60dfaea8ec7f934053624c80a1054539e163f2c7eaa986c2777d) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#a8af899ecdab60dfaea8ec7f934053624c80a1054539e163f2c7eaa986c2777d) Predicate({ns.bse.filename}) foo_second',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#a8af899ecdab60dfaea8ec7f934053624c80a1054539e163f2c7eaa986c2777d) Predicate({ns.bse.filesize}) 585',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#b8fd7fba818254166a6043195004138ebda6923e012442f819a2c49671136c70) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#b8fd7fba818254166a6043195004138ebda6923e012442f819a2c49671136c70) Predicate({ns.bse.filename}) bar_second',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#b8fd7fba818254166a6043195004138ebda6923e012442f819a2c49671136c70) Predicate({ns.bse.filesize}) 636',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#d43758ace82154a1cc10ca0dfef63cb20dd831f9c87edd6dc06539eefe67371d) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#d43758ace82154a1cc10ca0dfef63cb20dd831f9c87edd6dc06539eefe67371d) Predicate({ns.bse.filename}) foo_first',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#d43758ace82154a1cc10ca0dfef63cb20dd831f9c87edd6dc06539eefe67371d) Predicate({ns.bse.filesize}) 546',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#d803187cbf3676ae9d38126270a6152c60431589aa3bb3824baf8954e9c097f1) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#d803187cbf3676ae9d38126270a6152c60431589aa3bb3824baf8954e9c097f1) Predicate({ns.bse.filename}) td_second',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#d803187cbf3676ae9d38126270a6152c60431589aa3bb3824baf8954e9c097f1) Predicate({ns.bse.filesize}) 703',
- f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#accb115d266ad60c53cd01a7f7130f245886ce8eaf69bc85319febc11d9fe089) Predicate({ns.bse.filesize}) 349264',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#accb115d266ad60c53cd01a7f7130f245886ce8eaf69bc85319febc11d9fe089) Predicate({ns.bse.author}) Me, myself, and I',
f'Node(http://bsfs.ai/schema/File, http://example.com/me/file#accb115d266ad60c53cd01a7f7130f245886ce8eaf69bc85319febc11d9fe089) Predicate({ns.bse.filename}) testimage.jpg',
# features
diff --git a/test/apps/test_info.py b/test/apps/test_info.py
index 725fb65..cf8d52f 100644
--- a/test/apps/test_info.py
+++ b/test/apps/test_info.py
@@ -8,8 +8,13 @@ Author: Matthias Baumgartner, 2022
import argparse
import contextlib
import io
+import os
+import tempfile
import unittest
+# external imports
+import yaml
+
# bsie imports
from bsie.utils import bsfs
@@ -20,17 +25,49 @@ from bsie.apps.info import main
## code ##
class TestIndex(unittest.TestCase):
+ def setUp(self):
+ 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
+ _, self.config_path = tempfile.mkstemp(prefix='bsie-test-', suffix='.yaml')
+ with open(self.config_path, 'wt') as cfile:
+ yaml.dump(config, cfile)
+
+ def tearDown(self):
+ if os.path.exists(self.config_path):
+ os.unlink(self.config_path)
+
def test_predicates(self):
outbuf = io.StringIO()
with contextlib.redirect_stdout(outbuf):
# show predicates infos
- main(['predicates'])
+ main(['--config', self.config_path, 'predicates'])
# verify output
self.assertSetEqual({pred for pred in outbuf.getvalue().split('\n') if pred != ''}, {
'http://bsfs.ai/schema/Entity#author',
'http://bsfs.ai/schema/Predicate',
'http://bsfs.ai/schema/Entity#filename',
- 'http://bsfs.ai/schema/Entity#filesize',
'http://bsfs.ai/schema/Entity/colors_spatial#0658f2234a054e1dd59a14462c89f7733e019160419c796356aa831498bd0a04',
'http://bsfs.ai/schema/Entity#preview',
'http://bsfs.ai/schema/Preview#width',
@@ -42,14 +79,13 @@ class TestIndex(unittest.TestCase):
outbuf = io.StringIO()
with contextlib.redirect_stdout(outbuf):
# show schema infos
- main(['schema'])
+ main(['--config', self.config_path, 'schema'])
# verify output
schema = bsfs.schema.from_string(outbuf.getvalue())
self.assertSetEqual({pred.uri for pred in schema.predicates()}, {
'http://bsfs.ai/schema/Entity#author',
'http://bsfs.ai/schema/Predicate',
'http://bsfs.ai/schema/Entity#filename',
- 'http://bsfs.ai/schema/Entity#filesize',
'http://bsfs.ai/schema/Entity/colors_spatial#0658f2234a054e1dd59a14462c89f7733e019160419c796356aa831498bd0a04',
'http://bsfs.ai/schema/Entity#preview',
'http://bsfs.ai/schema/Preview#width',
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 ##