changeset 601:f67e58bf2f3e pytest2

added test for error in test_writelock_acquire and test_haveReadLocks improved for different conditions
author pkumar <contactprashantat@gmail.com>
date Wed, 29 Jun 2011 15:56:40 +0530
parents b2366bb97894
children cc24cc284cde
files MoinMoin/util/_tests/test_lock.py
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/util/_tests/test_lock.py	Wed Jun 29 12:12:45 2011 +0530
+++ b/MoinMoin/util/_tests/test_lock.py	Wed Jun 29 15:56:40 2011 +0530
@@ -136,15 +136,23 @@
         """ util.lock: WriteLock: acquire """
         lock = WriteLock(self.lock_dir)
         assert lock.acquire(0.1)
+        with pytest.raises(RuntimeError):
+            assert lock.acquire(0.1)
 
     def test_haveReadLocks(self):
         """check if there is a ReadLock """
-        write_lock = WriteLock(self.lock_dir)
+        timeout = 2.0 
+        write_lock = WriteLock(self.lock_dir, timeout)
         read_lock = ReadLock(self.lock_dir)
-        read_lock.acquire()
-        result = write_lock._haveReadLocks()
-        assert result, ('should return True but got False')
-    
+        # acquired ReadLock
+        read_lock.acquire(0.1)
+        result_before = write_lock._haveReadLocks()
+        assert result_before
+        # try to acquire WriteLock
+        write_lock.acquire()
+        result_after = write_lock._haveReadLocks()
+        assert result_after == False
+
 class TestReadLock(object):
     def setup_method(self, method):
         self.test_dir = tempfile.mkdtemp('', 'lock_')