Skip to content

Commit 31278ad

Browse files
committed
Fix tests.
1 parent c01f34c commit 31278ad

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

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
@@ -90,10 +90,10 @@ def test_pycompat_executeSQL(self):
9090
Exception, s.pycompat_executeSQL, cursor, qStr, paramList)
9191

9292
def test_namespaces(self):
93-
self.assert_(self.graph.namespaces() != [])
93+
self.assert_(list(self.graph.namespaces()) != [])
9494

9595
def test_contexts_without_triple(self):
96-
self.assert_(self.graph.contexts() != [])
96+
self.assert_(list(self.graph.contexts()) == [])
9797

9898
def test_contexts_with_triple(self):
9999
statemnt = (michel, likes, pizza)

test/test_sqlalchemy_sqlite.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import graph_case
1010
from rdflib import Literal
1111

12-
sqlalchemy_url = Literal(os.environ.get('DBURI',"sqlite://"))
12+
sqlalchemy_url = Literal(os.environ.get(
13+
'DBURI',
14+
"sqlite://"))
1315

1416

1517
class SQLASQLiteGraphTestCase(graph_case.GraphTestCase):

0 commit comments

Comments
 (0)