def test_unlock(self): """LogChecker.unlock() """ lockfileobj = LogChecker.lock(self.lockfile) LogChecker.unlock(self.lockfile, lockfileobj) self.assertFalse(os.path.exists(self.lockfile)) self.assertTrue(lockfileobj.closed)
def test_lock(self): """LogChecker.lock() """ # lock succeeded lockfileobj = LogChecker.lock(self.lockfile) self.assertNotEqual(lockfileobj, None) LogChecker.unlock(self.lockfile, lockfileobj) # locked by an another process locked_time = 4 wait_interval = 0.1 proc = self._run_locked_subprocess(self.lockfile, locked_time) for _ in range(100): if os.path.isfile(self.lockfile): break time.sleep(wait_interval) with warnings.catch_warnings(): warnings.simplefilter("ignore") lockfileobj = LogChecker.lock(self.lockfile) proc.wait() self.assertEqual(lockfileobj, None)