def test_wait_for_with_by_demand_after(): class Error(Exception): pass def demand(): raise Error() with pytest.raises(Error): wait_for(lambda: 'text', lambda r: len(r) == 0, demand)
def insist(self, condition=visible, *others, **kwargs): """ asserts conditions on self by default it is forced to assert without self pre-loading if available via _open (kwargs['forced']=True) """ opts = merge(dict(forced=True), kwargs) conditions = [condition] + list(others) acquire = self._finder if opts["forced"] else self._get wait_for(acquire, until=conditions) return self
def test_wait_for_with_passed_waiting(): class Code(object): def __init__(self): self._number = 1 def plus_one(self): self._number += 1 return self._number c = Code() assert wait_for(lambda: c.plus_one(), lambda r: r == 25, wait_time=4) == 25
def _get(self): """ loads self via _open, asserts _conditions on it, and returns what was found by _finder i.e. = 'smart' _finder""" return wait_for(self._finder, until=self._conditions, by_demand_after=self._open)
def test_wait_for_with_incorrect_conditions(): with pytest.raises(ExpiredWaitingException): wait_for(lambda: 'text', lambda r: len(r) == 0)
def test_wait_for_with_correct_conditions(): text = 'Text' assert wait_for(lambda: text, lambda r: len(r) > 0) is text
def test_wait_for_without_conditions(): text = 'Text' assert wait_for(lambda: text, None) is text