From: karim hamidou Date: Sat, 23 Nov 2013 18:56:59 +0000 (+0100) Subject: refactored tests X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b4ec9b9b4a970b1e7137a3170aeafb61499040b5;p=kite.git refactored tests --- diff --git a/src/back/tests/test_jsonfile.py b/src/back/tests/test_jsonfile.py index cf3104f..7ea1237 100644 --- a/src/back/tests/test_jsonfile.py +++ b/src/back/tests/test_jsonfile.py @@ -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() diff --git a/src/back/tests/test_lockfile.py b/src/back/tests/test_lockfile.py index 3cb7911..9921b09 100644 --- a/src/back/tests/test_lockfile.py +++ b/src/back/tests/test_lockfile.py @@ -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 index 0ac188e..0000000 --- a/src/back/tests/test_users.py +++ /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