aboutsummaryrefslogtreecommitdiffstats
path: root/test/front
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2022-12-18 14:21:11 +0100
committerMatthias Baumgartner <dev@igsor.net>2022-12-18 14:21:11 +0100
commit91437ba89d35bf482f3d9671bb99ef2fc69f5985 (patch)
treee9bfe27e5a641c040cfa8fe747a7cbb28091079c /test/front
parent87e4cd5a4581094f490f79d4f1cf91f51897660f (diff)
parente94368c75468e3e94382b12705e55d396249eaca (diff)
downloadbsfs-91437ba89d35bf482f3d9671bb99ef2fc69f5985.tar.gz
bsfs-91437ba89d35bf482f3d9671bb99ef2fc69f5985.tar.bz2
bsfs-91437ba89d35bf482f3d9671bb99ef2fc69f5985.zip
Merge branch 'develop' into main
Diffstat (limited to 'test/front')
-rw-r--r--test/front/__init__.py0
-rw-r--r--test/front/test_bsfs.py38
-rw-r--r--test/front/test_builder.py64
3 files changed, 102 insertions, 0 deletions
diff --git a/test/front/__init__.py b/test/front/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/front/__init__.py
diff --git a/test/front/test_bsfs.py b/test/front/test_bsfs.py
new file mode 100644
index 0000000..0d7f383
--- /dev/null
+++ b/test/front/test_bsfs.py
@@ -0,0 +1,38 @@
+"""
+
+Part of the bsfs test suite.
+A copy of the license is provided with the project.
+Author: Matthias Baumgartner, 2022
+"""
+# imports
+import unittest
+
+# bsie imports
+from bsfs.graph import Graph
+from bsfs.triple_store import SparqlStore
+from bsfs.utils import errors, URI
+
+# objects to test
+from bsfs.front.bsfs import Open
+
+
+## code ##
+
+class TestBSFS(unittest.TestCase):
+ def test_open(self):
+ # valid config produces a valid graph
+ config = {'Graph': {'backend': {'SparqlStore': {}}, 'user': 'http://example.com/me'}}
+ graph = Open(config)
+ self.assertIsInstance(graph, Graph)
+ self.assertIsInstance(graph._backend, SparqlStore)
+ self.assertEqual(graph._user, URI('http://example.com/me'))
+ # invalid config raises an error
+ self.assertRaises(errors.ConfigError, Open, {})
+
+
+## main ##
+
+if __name__ == '__main__':
+ unittest.main()
+
+## EOF ##
diff --git a/test/front/test_builder.py b/test/front/test_builder.py
new file mode 100644
index 0000000..08f2027
--- /dev/null
+++ b/test/front/test_builder.py
@@ -0,0 +1,64 @@
+"""
+
+Part of the bsfs test suite.
+A copy of the license is provided with the project.
+Author: Matthias Baumgartner, 2022
+"""
+# imports
+import unittest
+
+# bsie imports
+from bsfs.graph import Graph
+from bsfs.triple_store import SparqlStore
+from bsfs.utils import errors, URI
+
+# objects to test
+from bsfs.front.builder import build_backend, build_graph
+
+
+## code ##
+
+class TestBuilder(unittest.TestCase):
+ def test_build_backend(self):
+ # valid config produces a valid store
+ store = build_backend({'SparqlStore': {}})
+ self.assertIsInstance(store, SparqlStore)
+ self.assertIsNone(store.uri)
+ # cannot create an invalid store
+ self.assertRaises(errors.ConfigError, build_backend, {'MyStore': {}})
+ # must pass a dict
+ self.assertRaises(TypeError, build_backend, 1234)
+ self.assertRaises(TypeError, build_backend, 'hello world')
+ self.assertRaises(TypeError, build_backend, [1,2,3])
+ # cannot create a store from an invalid config
+ self.assertRaises(errors.ConfigError, build_backend, {})
+ self.assertRaises(errors.ConfigError, build_backend, {'SparqlStore': {}, 'OtherStore': {}})
+ self.assertRaises(TypeError, build_backend, {'SparqlStore': {'hello': 'world'}})
+
+ def test_build_graph(self):
+ # valid config produces a valid graph
+ graph = build_graph({'Graph': {'backend': {'SparqlStore': {}}, 'user': 'http://example.com/me'}})
+ self.assertIsInstance(graph, Graph)
+ self.assertIsInstance(graph._backend, SparqlStore)
+ self.assertEqual(graph._user, URI('http://example.com/me'))
+ # cannot create an invalid graph
+ self.assertRaises(errors.ConfigError, build_graph, {'MyGraph': {}})
+ # must pass a dict
+ self.assertRaises(TypeError, build_graph, 1234)
+ self.assertRaises(TypeError, build_graph, 'hello world')
+ self.assertRaises(TypeError, build_graph, [1,2,3])
+ # cannot create a graph from an invalid config
+ self.assertRaises(errors.ConfigError, build_graph, {})
+ self.assertRaises(errors.ConfigError, build_graph, {'Graph': {}, 'Graph2': {}})
+ self.assertRaises(errors.ConfigError, build_graph, {'Graph': {}})
+ self.assertRaises(errors.ConfigError, build_graph, {'Graph': {'user': 'http://example.com/me'}})
+ self.assertRaises(errors.ConfigError, build_graph, {'Graph': {'backend': 'Hello world'}})
+ self.assertRaises(TypeError, build_graph, {'Graph': {'user': 'http://example.com/me', 'backend': 'Hello world'}})
+
+
+## main ##
+
+if __name__ == '__main__':
+ unittest.main()
+
+## EOF ##