示例#1
0
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)
示例#2
0
    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
示例#3
0
    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
示例#4
0
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
示例#5
0
 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)
示例#6
0
def test_wait_for_with_incorrect_conditions():
    with pytest.raises(ExpiredWaitingException):
        wait_for(lambda: 'text', lambda r: len(r) == 0)
示例#7
0
def test_wait_for_with_correct_conditions():
    text = 'Text'
    assert wait_for(lambda: text, lambda r: len(r) > 0) is text
示例#8
0
def test_wait_for_without_conditions():
    text = 'Text'
    assert wait_for(lambda: text, None) is text
示例#9
0
 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)