def testFileLockAcquireException(self): # Expects an exception when file is not opened for read or write self._tempFileID.close() with self.assertRaises(file_lock.FileLockAcquireException): with file_lock._FileLock(self._tempFileID, fcntl.LOCK_SH) as f_err: self.assertIn("FileLock acquire failed on", f_err.exception.args[0]) with self.assertRaises(file_lock.FileLockAcquireException): with file_lock._FileLock([], fcntl.LOCK_SH) as f_err: self.assertIn("FileLock acquire failed on", f_err.exception.args[0])
def testValidLockOperation(self): # lockOperation must be one of {LOCK_UN, LOCK_SH, LOCK_EX} with self.assertRaises(AttributeError): file_lock._FileLock(self._tempFileID, fcntl.LOCK_S)
def testContextMgrWithGoodFile(self): with file_lock._FileLock(self._tempFileID, fcntl.LOCK_SH) as flock: self.assertEqual(type(flock), file_lock._FileLock)