]> khamidou — GitHub mirrors - kite.git/commitdiff
basic json object loading
authorkarim hamidou <khamidou@gmail.com>
Fri, 22 Nov 2013 18:44:35 +0000 (19:44 +0100)
committerkarim hamidou <khamidou@gmail.com>
Fri, 22 Nov 2013 18:44:35 +0000 (19:44 +0100)
src/back/kite/lockfile.py
src/back/tests/test_jsonfile.py [new file with mode: 0644]

index 750a2e8fad81c65e667127b8cc51458a58814f99..d94b2d00e962dca958946d9e0a34e43e085facad 100644 (file)
@@ -4,7 +4,7 @@ class LockingException(Exception):
     pass
 
 class FileLock(object):
-    def __init__(self, name, mode):
+    def __init__(self, name, mode="r+w"):
         self.name = name
         self.fd = open(name, mode)
 
diff --git a/src/back/tests/test_jsonfile.py b/src/back/tests/test_jsonfile.py
new file mode 100644 (file)
index 0000000..cf3104f
--- /dev/null
@@ -0,0 +1,21 @@
+import unittest
+import tempfile
+import fcntl
+import os
+import kite.jsonfile
+from kite.jsonfile import JsonFile
+
+class TestJsonfile(unittest.TestCase):
+    def test_locked_loading(self):
+        fd, path = tempfile.mkstemp()
+        fd = os.fdopen(fd, "w")
+        fd.write("{}")
+        fd.close()
+        json_file = JsonFile(path)
+        self.assertEqual(json_file.data, {}, msg="Value is not deserialized correctly")
+
+        fd = open(path, "w+")
+        fd.write("[]")
+        fd.close()
+        json_file.refresh()
+        self.assertEqual(json_file.data, [], msg="Value is not refreshed correctly")