Commits

Anonymous committed 47807b4

[tests/test_rdflib,bugfix][s]: use temp directory for RDFLib store directory to avoid failing due to store directory not existing.

* also refactor test into a class with setup and teardown (to create/remove store dir)

Comments (0)

Files changed (1)

ordf/tests/test_rdflib.py

 """
 Test rdflib storage of models
 """
+import tempfile
+import shutil
+
 from ordf.tests import test_graph, identifier
 from ordf.handler import Handler
 from ordf.handler.rdf import RDFLib
 
-rdf = RDFLib("data/rdflib", store="Sleepycat")
 
-def test_01_create():
-    rdf[identifier] = test_graph()
+class TestRdflibStorage:
+    @classmethod
+    def setup_class(self):
+        self.tmpdir = tempfile.mkdtemp()
+        self.rdf = RDFLib(self.tmpdir, store="Sleepycat")
 
-def test_02_read():
-    g = rdf[identifier]
+    @classmethod
+    def teardown_class(self):
+        shutil.rmtree(self.tmpdir)
 
-def test_03_delete():
-    del rdf[identifier]
+    def test_01_create(self):
+        self.rdf[identifier] = test_graph()
 
-def test_04_graphops():
-    rdf.put(graph=test_graph())
-    rdf.get(test_graph())
-    rdf.remove(test_graph())
+    def test_02_read(self):
+        g = self.rdf[identifier]
 
-def test_05_handler():
-    handler = Handler()
-    handler.register_reader(rdf)
-    handler.register_writer(rdf)
-    ctx = handler.context("rdflib_test", "rdflib_test")
-    ctx.add(test_graph())
-    ctx.commit()
+    def test_03_delete(self):
+        del self.rdf[identifier]
 
-    for cs in handler.history(identifier):
-        rdf.remove(cs)
-    rdf.remove(test_graph())
+    def test_04_graphops(self):
+        self.rdf.put(graph=test_graph())
+        self.rdf.get(test_graph())
+        self.rdf.remove(test_graph())
+
+    def test_05_handler(self):
+        handler = Handler()
+        handler.register_reader(self.rdf)
+        handler.register_writer(self.rdf)
+        ctx = handler.context("rdflib_test", "rdflib_test")
+        ctx.add(test_graph())
+        ctx.commit()
+
+        for cs in handler.history(identifier):
+            self.rdf.remove(cs)
+        self.rdf.remove(test_graph())
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.