def test_switch_to_idle_mode(self): mocked_queue = MagicMock() mocked_idle = MagicMock(side_effect=ValueError) mocked_idle_event = MagicMock() mocked_queue.get.side_effect = Empty() with patch.multiple("gitfs.worker.sync", idle=mocked_idle_event): worker = SyncWorker( "name", "email", "name", "email", strategy="strategy", commit_queue=mocked_queue, ) worker.on_idle = mocked_idle worker.timeout = 1 worker.min_idle_times = -1 with pytest.raises(ValueError): worker.work() mocked_queue.get.assert_called_once_with(timeout=1, block=True) assert mocked_idle_event.set.call_count == 1 assert mocked_idle.call_count == 1
def get(self, **kwargs): from six.moves.queue import Empty self._got = kwargs try: return self._items.pop() except IndexError: raise Empty()
def __call__(self): if 0 < self.timeout: import time waittime = min(self.timeout, self.waittime) self.timeout -= self.waittime time.sleep(waittime) else: raise Empty("No data found in queue within timeout")
def test_work(self): mocked_queue = MagicMock() mocked_idle = MagicMock(side_effect=ValueError) mocked_queue.get.side_effect = Empty() worker = SyncWorker("name", "email", "name", "email", strategy="strategy", commit_queue=mocked_queue) worker.on_idle = mocked_idle worker.timeout = 1 worker.min_idle_times = 1 with pytest.raises(ValueError): worker.work() mocked_queue.get.assert_called_once_with(timeout=1, block=True) assert mocked_idle.call_count == 1
def __call__(self): raise Empty("No data found in queue")
def get(self, timeout=None): if self.cin.poll(timeout): return self.cin.recv() else: raise Empty()
def get(self, *args, **kwargs): try: return self.q.pop(0) except IndexError: raise Empty()