4
from landscape.tests.helpers import LandscapeTest
6
from landscape.lib.lock import lock_path, LockError
9
class LockTest(LandscapeTest):
12
super(LockTest, self).setUp()
13
self.filename = self.makeFile()
15
def test_lock_creates_path(self):
16
self.assertFalse(os.path.isfile(self.filename))
17
lock_path(self.filename)
18
self.assertTrue(os.path.isfile(self.filename))
20
def test_lock_with_already_locked(self):
21
unlock_path = lock_path(self.filename)
22
self.assertRaises(LockError, lock_path, self.filename)
24
lock_path(self.filename)
26
def test_lock_with_timeout(self):
27
lock_path(self.filename)
29
self.assertRaises(LockError, lock_path, self.filename, timeout=0.5)
30
self.assertTrue(started < time.time() - 0.5)