Back to index

obnam  1.1
Public Member Functions | Public Attributes
obnamlib.lockmgr_tests.LockManagerTests Class Reference

List of all members.

Public Member Functions

def locked
def fake_time
def setUp
def tearDown
def test_has_nothing_locked_initially
def test_locks_single_directory
def test_unlocks_single_directory
def test_waits_until_timeout_for_locked_directory
def test_notices_when_preexisting_lock_goes_away
def test_locks_all_directories
def test_unlocks_all_directories
def test_does_not_lock_anything_if_one_lock_fails

Public Attributes

 tempdir
 dirnames
 fs
 timeout
 now
 lm

Detailed Description

Definition at line 25 of file lockmgr_tests.py.


Member Function Documentation

Definition at line 30 of file lockmgr_tests.py.

00030 
00031     def fake_time(self):
00032         self.now += 1
00033         return self.now

def obnamlib.lockmgr_tests.LockManagerTests.locked (   self,
  dirname 
)

Definition at line 27 of file lockmgr_tests.py.

00027 
00028     def locked(self, dirname):
00029         return os.path.exists(os.path.join(dirname, 'lock'))

Here is the caller graph for this function:

Definition at line 34 of file lockmgr_tests.py.

00034 
00035     def setUp(self):
00036         self.tempdir = tempfile.mkdtemp()
00037         self.dirnames = []
00038         for x in ['a', 'b', 'c']:
00039             dirname = os.path.join(self.tempdir, x)
00040             os.mkdir(dirname)
00041             self.dirnames.append(dirname)
00042         self.fs = obnamlib.LocalFS(self.tempdir)
00043         self.timeout = 10
00044         self.now = 0
00045         self.lm = obnamlib.LockManager(self.fs, self.timeout, '')
00046         self.lm._time = self.fake_time
00047         self.lm._sleep = lambda: None
        

Definition at line 48 of file lockmgr_tests.py.

00048 
00049     def tearDown(self):
00050         shutil.rmtree(self.tempdir)
        

Definition at line 87 of file lockmgr_tests.py.

00087 
00088     def test_does_not_lock_anything_if_one_lock_fails(self):
00089         self.lm.lock([self.dirnames[-1]])
00090         self.assertRaises(obnamlib.LockFail, self.lm.lock, self.dirnames)
00091         for dirname in self.dirnames[:-1]:
00092             self.assertFalse(self.locked(dirname))
00093         self.assertTrue(self.locked(self.dirnames[-1]))
00094 
00095 

Here is the call graph for this function:

Definition at line 51 of file lockmgr_tests.py.

00051 
00052     def test_has_nothing_locked_initially(self):
00053         for dirname in self.dirnames:
00054             self.assertFalse(self.locked(dirname))

Here is the call graph for this function:

Definition at line 76 of file lockmgr_tests.py.

00076 
00077     def test_locks_all_directories(self):
00078         self.lm.lock(self.dirnames)
00079         for dirname in self.dirnames:
00080             self.assertTrue(self.locked(dirname))

Here is the call graph for this function:

Definition at line 55 of file lockmgr_tests.py.

00055 
00056     def test_locks_single_directory(self):
00057         self.lm.lock([self.dirnames[0]])
00058         self.assertTrue(self.locked(self.dirnames[0]))

Here is the call graph for this function:

Definition at line 70 of file lockmgr_tests.py.

00070 
00071     def test_notices_when_preexisting_lock_goes_away(self):
00072         self.lm.lock([self.dirnames[0]])
00073         self.lm._sleep = lambda: os.remove(self.lm._lockname(self.dirnames[0]))
00074         self.lm.lock([self.dirnames[0]])
00075         self.assertTrue(True)

Definition at line 81 of file lockmgr_tests.py.

00081 
00082     def test_unlocks_all_directories(self):
00083         self.lm.lock(self.dirnames)
00084         self.lm.unlock(self.dirnames)
00085         for dirname in self.dirnames:
00086             self.assertFalse(self.locked(dirname))

Here is the call graph for this function:

Definition at line 59 of file lockmgr_tests.py.

00059 
00060     def test_unlocks_single_directory(self):
00061         self.lm.lock([self.dirnames[0]])
00062         self.lm.unlock([self.dirnames[0]])
00063         self.assertFalse(self.locked(self.dirnames[0]))

Here is the call graph for this function:

Definition at line 64 of file lockmgr_tests.py.

00064 
00065     def test_waits_until_timeout_for_locked_directory(self):
00066         self.lm.lock([self.dirnames[0]])
00067         self.assertRaises(obnamlib.LockFail,
00068                           self.lm.lock, [self.dirnames[0]])
00069         self.assertTrue(self.now >= self.timeout)


Member Data Documentation

Definition at line 36 of file lockmgr_tests.py.

Definition at line 41 of file lockmgr_tests.py.

Definition at line 44 of file lockmgr_tests.py.

Definition at line 43 of file lockmgr_tests.py.

Definition at line 35 of file lockmgr_tests.py.

Definition at line 42 of file lockmgr_tests.py.


The documentation for this class was generated from the following file: