def test_get_block(self, sleep): x = buckets.TaskBucket(task_registry=self.registry) x.not_empty = Mock() get = x._get = Mock() calls = [0] remaining = [0] def effect(): try: if not calls[0]: raise Empty() rem = remaining[0] remaining[0] = 0 return rem, Mock() finally: calls[0] += 1 get.side_effect = effect with mock_context(Mock()) as context: x.not_empty = context x.wait = Mock() x.get(block=True) calls[0] = 0 remaining[0] = 1 x.get(block=True)
def test_get_block(self, sleep): x = buckets.TaskBucket(task_registry=self.registry) x.not_empty = Mock() get = x._get = Mock() remaining = [0] def effect(): if get.call_count == 1: raise Empty() rem = remaining[0] remaining[0] = 0 return rem, Mock() get.side_effect = effect with mock_context(Mock()) as context: x.not_empty = context x.wait = Mock() x.get(block=True) get.reset() remaining[0] = 1 x.get(block=True)