# HG changeset patch
# User drewp@bigasterisk.com
# Date 1649131840 25200
# Node ID 8a9f8dc65da84d5d3c2ee316b56c02d2c7d2a910
# Parent 8d3c3e7cfb541324bad9c4e08ba73cd0ffb5f842
fix existing tests. Note bytes->str on public api arg
diff -r 8d3c3e7cfb54 -r 8a9f8dc65da8 rdfdb/graphfile.py
--- a/rdfdb/graphfile.py Mon Apr 04 11:25:05 2022 -0700
+++ b/rdfdb/graphfile.py Mon Apr 04 21:10:40 2022 -0700
@@ -114,13 +114,13 @@
one rdf file that we read from, write to, and notice external changes to
"""
- def __init__(self, notifier: INotify, path: bytes, uri: URIRef, patch: PatchCb, getSubgraph: GetSubgraph, globalPrefixes: Dict[str, URIRef],
+ def __init__(self, notifier: INotify, path: str, uri: URIRef, patch: PatchCb, getSubgraph: GetSubgraph, globalPrefixes: Dict[str, URIRef],
ctxPrefixes: Dict[str, URIRef]):
"""
uri is the context for the triples in this file. We assume
sometimes that we're the only ones with triples in this
context.
-
+
this does not include an initial reread() call
Prefixes are mutable dicts. The caller may add to them later.
@@ -256,18 +256,18 @@
def dirty(self, graph: Graph) -> None:
"""
there are new contents to write to our file
-
+
graph is the rdflib.Graph that contains the contents of the
file. It is allowed to change. Note that dirty() will probably
do the save later when the graph might be different.
-
+
after a timer has passed, write it out. Any scheduling issues
between files? i don't think so. the timer might be kind of
huge, and then we might want to take a hint from a client that
it's a good time to save the files that it was editing, like
when the mouse moves out of the client's window and might be
going towards a text file editor
-
+
"""
log.debug("%s dirty, needs write", self.path)
@@ -281,7 +281,7 @@
def flush(self) -> None:
self.writeCall = None
- tmpOut = self.path + b".rdfdb-temp"
+ tmpOut = self.path + ".rdfdb-temp"
f = open(tmpOut, 'wb')
t1 = time.time()
for p, n in (list(self.globalPrefixes.items()) + list(self.readPrefixes.items()) + list(self.ctxPrefixes.items())):
diff -r 8d3c3e7cfb54 -r 8a9f8dc65da8 rdfdb/graphfile_test.py
--- a/rdfdb/graphfile_test.py Mon Apr 04 11:25:05 2022 -0700
+++ b/rdfdb/graphfile_test.py Mon Apr 04 21:10:40 2022 -0700
@@ -1,10 +1,15 @@
import tempfile
import unittest
+from typing import cast
import mock
from rdflib import Graph, URIRef
+from twisted.internet.inotify import INotify
from rdfdb.graphfile import GraphFile
+from _pytest.assertion import truncate
+truncate.DEFAULT_MAX_LINES = 9999
+truncate.DEFAULT_MAX_CHARS = 9999
class TestGraphFileOutput(unittest.TestCase):
@@ -21,7 +26,7 @@
def getSubgraph(uri):
return Graph()
- gf = GraphFile(mock.Mock(), tf.name.encode('ascii'), URIRef('uri'), mock.Mock(), getSubgraph, {}, {})
+ gf = GraphFile(cast(INotify, mock.Mock()), tf.name, URIRef('uri'), mock.Mock(), getSubgraph, {}, {})
gf.reread()
newGraph = Graph()
@@ -29,13 +34,10 @@
gf.dirty(newGraph)
gf.flush()
wroteContent = open(tf.name, 'rb').read()
+ print(wroteContent)
self.assertEqual(
b'''@prefix : .
@prefix n: .
-@prefix rdf: .
-@prefix rdfs: .
-@prefix xml: .
-@prefix xsd: .
:boo n:two .
''', wroteContent)
diff -r 8d3c3e7cfb54 -r 8a9f8dc65da8 rdfdb/patch.py
--- a/rdfdb/patch.py Mon Apr 04 11:25:05 2022 -0700
+++ b/rdfdb/patch.py Mon Apr 04 21:10:40 2022 -0700
@@ -1,10 +1,8 @@
import json
-import unittest
from typing import Optional
from rdflib import ConjunctiveGraph, Graph, Literal, Namespace
from rdflib import URIRef
-from rdflib import URIRef as U
XSD = Namespace("http://www.w3.org/2001/XMLSchema#")
@@ -186,54 +184,3 @@
def isNoop(self):
return set(self.addQuads) == set(self.delQuads)
-
-stmt1 = U('http://a'), U('http://b'), U('http://c'), U('http://ctx1')
-
-
-class TestPatchFromDiff(unittest.TestCase):
-
- def testEmpty(self):
- g = ConjunctiveGraph()
- p = Patch.fromDiff(g, g)
- self.assertTrue(not p)
-
- def testNonEmpty(self):
- g1 = ConjunctiveGraph()
- g2 = graphFromQuads([stmt1])
- p = Patch.fromDiff(g1, g2)
- self.assertTrue(p)
-
- def testNoticesAdds(self):
- g1 = ConjunctiveGraph()
- g2 = graphFromQuads([stmt1])
- p = Patch.fromDiff(g1, g2)
- self.assertEqual(p.addQuads, [stmt1])
- self.assertEqual(p.delQuads, [])
-
- def testNoticesDels(self):
- g1 = graphFromQuads([stmt1])
- g2 = ConjunctiveGraph()
- p = Patch.fromDiff(g1, g2)
- self.assertEqual(p.addQuads, [])
- self.assertEqual(p.delQuads, [stmt1])
-
- def testQuadSequenceOkInsteadOfGraph(self):
- p = Patch.fromDiff([stmt1], ConjunctiveGraph())
- self.assertEqual(p.delQuads, [stmt1])
- p = Patch.fromDiff(ConjunctiveGraph(), [stmt1])
- self.assertEqual(p.addQuads, [stmt1])
-
-
-class TestPatchGetContext(unittest.TestCase):
-
- def testEmptyPatchCantGiveContext(self):
- p = Patch()
- self.assertRaises(ValueError, p.getContext)
-
- def testSimplePatchReturnsContext(self):
- p = Patch(addQuads=[stmt1])
- self.assertEqual(p.getContext(), U('http://ctx1'))
-
- def testMultiContextPatchFailsToReturnContext(self):
- p = Patch(addQuads=[stmt1[:3] + (U('http://ctx1'),), stmt1[:3] + (U('http://ctx2'),)])
- self.assertRaises(ValueError, p.getContext)
diff -r 8d3c3e7cfb54 -r 8a9f8dc65da8 rdfdb/patch_test.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rdfdb/patch_test.py Mon Apr 04 21:10:40 2022 -0700
@@ -0,0 +1,58 @@
+import unittest
+
+from rdflib import ConjunctiveGraph
+from rdflib import URIRef as U
+
+from rdfdb.patch import Patch
+from rdfdb.rdflibpatch import graphFromQuads
+
+stmt1 = U('http://a'), U('http://b'), U('http://c'), U('http://ctx1')
+
+
+class TestPatchFromDiff(unittest.TestCase):
+
+ def testEmpty(self):
+ g = ConjunctiveGraph()
+ p = Patch.fromDiff(g, g)
+ self.assertTrue(not p)
+
+ def testNonEmpty(self):
+ g1 = ConjunctiveGraph()
+ g2 = graphFromQuads([stmt1])
+ p = Patch.fromDiff(g1, g2)
+ self.assertTrue(p)
+
+ def testNoticesAdds(self):
+ g1 = ConjunctiveGraph()
+ g2 = graphFromQuads([stmt1])
+ p = Patch.fromDiff(g1, g2)
+ self.assertEqual(p.addQuads, [stmt1])
+ self.assertEqual(p.delQuads, [])
+
+ def testNoticesDels(self):
+ g1 = graphFromQuads([stmt1])
+ g2 = ConjunctiveGraph()
+ p = Patch.fromDiff(g1, g2)
+ self.assertEqual(p.addQuads, [])
+ self.assertEqual(p.delQuads, [stmt1])
+
+ def testQuadSequenceOkInsteadOfGraph(self):
+ p = Patch.fromDiff([stmt1], ConjunctiveGraph())
+ self.assertEqual(p.delQuads, [stmt1])
+ p = Patch.fromDiff(ConjunctiveGraph(), [stmt1])
+ self.assertEqual(p.addQuads, [stmt1])
+
+
+class TestPatchGetContext(unittest.TestCase):
+
+ def testEmptyPatchCantGiveContext(self):
+ p = Patch()
+ self.assertRaises(ValueError, p.getContext)
+
+ def testSimplePatchReturnsContext(self):
+ p = Patch(addQuads=[stmt1])
+ self.assertEqual(p.getContext(), U('http://ctx1'))
+
+ def testMultiContextPatchFailsToReturnContext(self):
+ p = Patch(addQuads=[stmt1[:3] + (U('http://ctx1'),), stmt1[:3] + (U('http://ctx2'),)])
+ self.assertRaises(ValueError, p.getContext)
diff -r 8d3c3e7cfb54 -r 8a9f8dc65da8 tasks.py
--- a/tasks.py Mon Apr 04 11:25:05 2022 -0700
+++ b/tasks.py Mon Apr 04 21:10:40 2022 -0700
@@ -19,7 +19,7 @@
def test_forever(ctx, forever=True):
watchdir = 'rdfdb'
testdir = 'rdfdb'
- ctx.run(f'pdm run pytest {testdir}', pty=True) # ptw doesn't do an initial run
+ ctx.run(f'pdm run pytest {testdir}', pty=True, warn=True) # ptw doesn't do an initial run
if forever:
ctx.run(f'pdm run ptw {watchdir} {testdir}', pty=True)