Пример #1
0
    def test_non_blocking_does_not_wait_for_lock(self):
        locked_fd = self.exclusive_lock(self.lockfile)

        with self.assertRaises(IOError):
            with open(self.lockfile, 'w') as fd:
                with Flock(fd, blocking=False) as lock:
                    pass

        self.unlock(locked_fd)
Пример #2
0
    def test_file_is_unlocked_after_context(self):
        with open(self.lockfile, 'w') as fd:
            with Flock(fd) as lock:
                pass

            self.assertUnlocked(self.lockfile)
Пример #3
0
    def test_timeout_is_ignored_when_not_blocking(self):
        self.lock(self.lockfile_path)

        with self.assertRaises(IOError):
            with Flock(self.lockfile_handle, blocking=False, timeout=1) as lock:
                pass
Пример #4
0
 def test_file_is_locked_within_context(self):
     with open(self.lockfile, 'w') as fd:
         with Flock(fd) as lock:
             self.assertLocked(self.lockfile)
Пример #5
0
    def test_it_raise_timeouterror_if_timeout_is_reached(self):
        self.lock(self.lockfile_path)

        with self.assertRaises(TimeoutError):
            with Flock(self.lockfile_handle, timeout=1) as lock:
                pass
Пример #6
0
    def test_it_can_be_acquired_within_context(self):

        with Flock(self.lockfile_handle) as lock:
            lock.release()
            lock.acquire()
            self.assertLocked(self.lockfile_path)
Пример #7
0
    def test_non_blocking_does_not_wait_for_lock(self):
        self.lock(self.lockfile_path)

        with self.assertRaises(IOError):
            with Flock(self.lockfile_handle, blocking=False) as lock:
                pass
Пример #8
0
    def test_file_is_unlocked_after_context(self):
        with Flock(self.lockfile_handle) as lock:
            pass

        self.assertUnlocked(self.lockfile_path)
Пример #9
0
 def test_file_is_locked_within_context(self):
     with Flock(self.lockfile_handle) as lock:
         self.assertLocked(self.lockfile_path)