import fcntl
import os
import kite.jsonfile
+import tmpdir
from kite.jsonfile import JsonFile
-class TestJsonfile(unittest.TestCase):
+class TestJsonfile(tmpdir.TestCaseWithTempFile):
def test_locked_loading(self):
- fd, path = tempfile.mkstemp()
- fd = os.fdopen(fd, "w")
+ fd = os.fdopen(self.tmpfd, "w")
fd.write("{}")
fd.close()
- json_file = JsonFile(path)
+ json_file = JsonFile(self.tmpfile)
self.assertEqual(json_file.data, {}, msg="Value is not deserialized correctly")
- fd = open(path, "w+")
+ fd = open(self.tmpfile, "w+")
fd.write("[]")
fd.close()
json_file.refresh()
import unittest
import tempfile
import fcntl
+import tmpdir
-class TestLockfile(unittest.TestCase):
+class TestLockfile(tmpdir.TestCaseWithTempFile):
def test_lock(self):
- fd, path = tempfile.mkstemp()
- print "PATH ", path
- with FileLock(path, "r+w"):
+ with FileLock(self.tmpfile, "r+w"):
try:
- fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ fcntl.flock(self.tmpfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
assert False, "Flock should have failed"
except IOError:
pass
+++ /dev/null
-import os
-import unittest
-import tempfile
-import fcntl
-import kite.users
-
-class TestLockfile(unittest.TestCase):
- def test_creation(self):
- tmpdir = tempfile.mkdtemp()
- kite.users.create_user("charles", _base_folder=tmpdir)
- self.assertTrue(os.path.exists(os.path.join(tmpdir, "charles")))
-
- try:
- # Creating the file twice raises an error
- kite.users.create_user("charles", _base_folder=tmpdir)
- assert False, "Exception should have been raised"
- except kite.users.UserError:
- pass