Skip to content

Commit 5df97b3

Browse files
committed
Merge commit '119e7840ded581d20c61d20b968be86a61aaeec2'
2 parents 1184543 + 119e784 commit 5df97b3

File tree

6 files changed

+54
-39
lines changed

6 files changed

+54
-39
lines changed

rdflib_sqlalchemy/SQLAlchemy.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import logging
66
import sqlalchemy
77
import hashlib
8-
from rdflib import BNode
9-
from rdflib import Literal
10-
from rdflib import RDF
11-
from rdflib import URIRef
8+
from rdflib import (
9+
BNode,
10+
Literal,
11+
RDF,
12+
URIRef
13+
)
1214
from rdflib.graph import Graph
1315
from rdflib.graph import QuotedGraph
1416
from rdflib.store import Store # , NodePickler
@@ -231,7 +233,7 @@ def createTerm(
231233
rt = Literal(termString, objLanguage)
232234
store.literalCache[((termString, objLanguage))] = rt
233235
elif objDatatype and not objLanguage:
234-
rt = Literal(termString, objDatatype)
236+
rt = Literal(termString, datatype=objDatatype)
235237
store.literalCache[((termString, objDatatype))] = rt
236238
elif not objLanguage and not objDatatype:
237239
rt = Literal(termString)
@@ -903,7 +905,7 @@ def __repr__(self):
903905
"contexts, %s classification assertions, " +
904906
"%s quoted statements, %s property/value " +
905907
"assertions, and %s other assertions>" % (
906-
len([c for c in self.contexts()]),
908+
len([ctx for ctx in self.contexts()]),
907909
typeLen, quotedLen, literalLen, assertedLen))
908910
except Exception:
909911
return "<Partitioned SQL N3 Store>"

rdflib_sqlalchemy/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,3 @@ def registerplugins():
4949
plugin.register(
5050
'SQLAlchemy', Store,
5151
'rdflib_sqlalchemy.SQLAlchemy', 'SQLAlchemy')
52-
53-
# # Work in progress
54-
# plugin.register(
55-
# 'SQLAlchemyBase', store.Store,
56-
# 'rdflib_sqlalchemy.SQLAlchemyBase', 'SQLAlchemy')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def find_version(filename):
9292
}
9393
)
9494

95-
install_requires = ["rdflib>=3.4.1-dev",
95+
install_requires = ["rdflib>=4.0",
9696
"SQLAlchemy"]
9797

9898
if sys.version_info[0] >= 3:

test/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,3 @@
33

44
plugin.register('SQLAlchemy', store.Store,
55
'rdflib_sqlalchemy.SQLAlchemy', 'SQLAlchemy')
6-
7-
plugin.register('SQLAlchemyASS', store.Store,
8-
'rdflib_sqlalchemy.SQLAlchemyASS', 'SQLAlchemy')
9-
10-
plugin.register('SQLAlchemyBase', store.Store,
11-
'rdflib_sqlalchemy.SQLAlchemyBase', 'SQLAlchemy')
12-
13-
plugin.register('SQLAlchemyFOPL', store.Store,
14-
'rdflib_sqlalchemy.SQLAlchemyFOPL', 'SQLAlchemy')

test/test.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from rdflib import Graph, BNode, Literal, URIRef, RDFS, RDF, plugin
1+
from rdflib import Graph, BNode, Literal, URIRef, RDFS, RDF, plugin, Namespace
22
from rdflib.store import Store
33
import os
44

@@ -7,27 +7,54 @@
77

88

99
def investigate_len_issue():
10+
import shutil, commands
1011
store = plugin.get('SQLAlchemy', Store)(
1112
identifier=URIRef("rdflib_test"),
1213
configuration=Literal("sqlite:///%(here)s/development.sqlite" % {
1314
"here": os.getcwd()}))
14-
g = Graph(store)
15-
print(len(g))
15+
g0 = Graph('Sleepycat')
16+
g0.open('/tmp/foo', create=True)
17+
print("Len g0 on opening: %s\n" % len(g0))
18+
g1 = Graph(store)
19+
print("Len g1 on opening: %s\n" % len(g1))
1620
statementId = BNode()
17-
g.add((statementId, RDF.type, RDF.Statement))
18-
g.add((statementId, RDF.subject,
21+
print("Adding %s\n\t%s\n\t%s\n" % (statementId, RDF.type, RDF.Statement))
22+
g0.add((statementId, RDF.type, RDF.Statement))
23+
g1.add((statementId, RDF.type, RDF.Statement))
24+
print("Adding %s\n\t%s\n\t%s\n" % (statementId, RDF.subject,
1925
URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
20-
g.add((statementId, RDF.predicate, RDFS.label))
21-
g.add((statementId, RDF.object, Literal("Conjunctive Graph")))
22-
print(len(g))
23-
for s, p, o in g:
24-
print(type(s))
25-
26-
for s, p, o in g.triples((None, RDF.object, None)):
27-
print(o)
28-
29-
g.remove((statementId, RDF.type, RDF.Statement))
30-
print(len(g))
26+
g0.add((statementId, RDF.subject,
27+
URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
28+
g1.add((statementId, RDF.subject,
29+
URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
30+
print("Adding %s\n\t%s\n\t%s\n" % (statementId, RDF.predicate, RDFS.label))
31+
g0.add((statementId, RDF.predicate, RDFS.label))
32+
g1.add((statementId, RDF.predicate, RDFS.label))
33+
print("Adding %s\n\t%s\n\t%s\n" % (
34+
statementId, RDF.object, Literal("Conjunctive Graph")))
35+
g0.add((statementId, RDF.object, Literal("Conjunctive Graph")))
36+
print("Len g0 after adding 4 triples %s\n" % len(g0))
37+
g1.add((statementId, RDF.object, Literal("Conjunctive Graph")))
38+
print("Len g1 after adding 4 triples %s\n" % len(g1))
39+
print(g0.serialize(format="nt") + "\n")
40+
for s, p, o in g0:
41+
print("s = %s\n\tp = %s\n\to = %s\n" % (
42+
repr(s), repr(p), repr(o)))
43+
print(g1.serialize(format="nt") + "\n")
44+
for s, p, o in g1:
45+
print("s = %s\n\tp = %s\n\to = %s\n" % (
46+
repr(s), repr(p), repr(o)))
47+
commands.getoutput('cp development.sqlite devcopy.sqlite')
48+
print("Removing %s\n\t%s\n\t%s\n" % (statementId, RDF.type, RDF.Statement))
49+
g0.remove((statementId, RDF.type, RDF.Statement))
50+
print("Len g0 after removal %s\n" % len(g0))
51+
g1.remove((statementId, RDF.type, RDF.Statement))
52+
print("Len g1 after removal %s\n" % len(g1))
53+
print(g0.serialize(format="nt") + "\n")
54+
print(g1.serialize(format="nt") + "\n")
55+
g0.close()
56+
shutil.rmtree('/tmp/foo')
57+
g1.close()
3158
os.unlink("%(here)s/development.sqlite" % {"here": os.getcwd()})
3259

3360
if __name__ == '__main__':

test/test_sqlalchemy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ def test__parse_rfc1738_args(self):
7878
self.assertRaises(ValueError, _parse_rfc1738_args, 'Not parseable')
7979

8080
def test_namespaces(self):
81-
self.assert_(self.graph.namespaces() != [])
81+
self.assert_(list(self.graph.namespaces()) != [])
8282

8383
def test_contexts_without_triple(self):
84-
self.assert_(self.graph.contexts() != [])
84+
self.assert_(list(self.graph.contexts()) == [])
8585

8686
def test_contexts_with_triple(self):
8787
statemnt = (michel, likes, pizza)

0 commit comments

Comments
 (0)