]> khamidou — GitHub mirrors - kite.git/commitdiff
refactored tests
authorkarim hamidou <khamidou@gmail.com>
Sat, 23 Nov 2013 18:56:59 +0000 (19:56 +0100)
committerkarim hamidou <khamidou@gmail.com>
Sat, 23 Nov 2013 18:56:59 +0000 (19:56 +0100)
src/back/tests/test_jsonfile.py
src/back/tests/test_lockfile.py
src/back/tests/test_users.py [deleted file]

index cf3104fa12e6b93791d31ccecfbd2fea4410cc93..7ea1237d126d2d8c519667141f073f08c94201ec 100644 (file)
@@ -3,18 +3,18 @@ import tempfile
 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()
index 3cb7911916a374961b7066d367370766c2d7cb21..9921b09bc51b93c4483b7b812a8b38c33bfeaf72 100644 (file)
@@ -3,14 +3,13 @@ from kite.lockfile import FileLock
 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
diff --git a/src/back/tests/test_users.py b/src/back/tests/test_users.py
deleted file mode 100644 (file)
index 0ac188e..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-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