summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNicholas Car <nicholas.car@surroundaustralia.com>2021-07-03 00:41:24 +1000
committerNicholas Car <nicholas.car@surroundaustralia.com>2021-07-03 00:41:24 +1000
commit3ad2cdd661dd98bcca2dfd0e19a384ab3abcd71b (patch)
tree66a9cdb5362617b2b5f6659476bde9e36abcbea5 /test
parentbf892c97e3da1b2c938a2d07c2a597680d4a5ab4 (diff)
parentc59de84101830c3deced0032af1d5ae735728f1d (diff)
downloadrdflib-3ad2cdd661dd98bcca2dfd0e19a384ab3abcd71b.tar.gz
Merge remote-tracking branch 'origin/docco_clean' into docco_clean
Diffstat (limited to 'test')
-rw-r--r--test/test_store_berkeleydb.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/test/test_store_berkeleydb.py b/test/test_store_berkeleydb.py
new file mode 100644
index 00000000..634b7221
--- /dev/null
+++ b/test/test_store_berkeleydb.py
@@ -0,0 +1,114 @@
+import unittest
+from tempfile import mktemp
+from rdflib import ConjunctiveGraph, URIRef
+from rdflib.store import VALID_STORE
+
+
+class BerkeleyDBTestCase(unittest.TestCase):
+ def setUp(self):
+ self.store_name = "BerkeleyDB"
+ self.path = mktemp()
+ self.g = ConjunctiveGraph(store=self.store_name)
+ self.rt = self.g.open(self.path, create=True)
+ assert self.rt == VALID_STORE, "The underlying store is corrupt"
+ assert len(self.g) == 0, "There must be zero triples in the graph just after store (file) creation"
+ data = """
+ PREFIX : <https://example.org/>
+
+ :a :b :c .
+ :d :e :f .
+ :d :g :h .
+ """
+ self.g.parse(data=data, format="ttl")
+
+ def tearDown(self):
+ self.g.close()
+
+ def test_write(self):
+ assert len(self.g) == 3, "There must be three triples in the graph after the first data chunk parse"
+ data2 = """
+ PREFIX : <https://example.org/>
+
+ :d :i :j .
+ """
+ self.g.parse(data=data2, format="ttl")
+ assert len(self.g) == 4, "There must be four triples in the graph after the second data chunk parse"
+ data3 = """
+ PREFIX : <https://example.org/>
+
+ :d :i :j .
+ """
+ self.g.parse(data=data3, format="ttl")
+ assert len(self.g) == 4, "There must still be four triples in the graph after the thrd data chunk parse"
+
+ def test_read(self):
+ sx = None
+ for s in self.g.subjects(predicate=URIRef("https://example.org/e"), object=URIRef("https://example.org/f")):
+ sx = s
+ assert sx == URIRef("https://example.org/d")
+
+ def test_sparql_query(self):
+ q = """
+ PREFIX : <https://example.org/>
+
+ SELECT (COUNT(*) AS ?c)
+ WHERE {
+ :d ?p ?o .
+ }"""
+
+ c = 0
+ for row in self.g.query(q):
+ c = int(row.c)
+ assert c == 2, "SPARQL COUNT must return 2"
+
+ def test_sparql_insert(self):
+ q = """
+ PREFIX : <https://example.org/>
+
+ INSERT DATA {
+ :x :y :z .
+ }"""
+
+ self.g.update(q)
+ assert len(self.g) == 4, "After extra triple insert, length must be 4"
+
+ def test_multigraph(self):
+ q = """
+ PREFIX : <https://example.org/>
+
+ INSERT DATA {
+ GRAPH :m {
+ :x :y :z .
+ }
+ GRAPH :n {
+ :x :y :z .
+ }
+ }"""
+
+ self.g.update(q)
+
+ q = """
+ SELECT (COUNT(?g) AS ?c)
+ WHERE {
+ SELECT DISTINCT ?g
+ WHERE {
+ GRAPH ?g {
+ ?s ?p ?o
+ }
+ }
+ }
+ """
+ c = 0
+ for row in self.g.query(q):
+ c = int(row.c)
+ assert c == 3, "SPARQL COUNT must return 3 (default, :m & :n)"
+
+ def test_open_shut(self):
+ assert len(self.g) == 3, "Initially we must have 3 triples from setUp"
+ self.g.close()
+ self.g = None
+
+ # reopen the graph
+ self.g = ConjunctiveGraph("BerkeleyDB")
+ self.g.open(self.path, create=False)
+ assert len(self.g) == 3, "After close and reopen, we should still have the 3 originally added triples"