tests: Add after= argument to wait_for

This commit is contained in:
Florian Bruhin 2017-12-04 22:07:23 +01:00
parent 3a04de62ae
commit b554e1f763

View File

@ -333,7 +333,7 @@ class Process(QObject):
else:
return value == expected
def _wait_for_existing(self, override_waited_for, **kwargs):
def _wait_for_existing(self, override_waited_for, after, **kwargs):
"""Check if there are any line in the history for wait_for.
Return: either the found line or None.
@ -345,7 +345,15 @@ class Process(QObject):
value = getattr(line, key)
matches.append(self._match_data(value, expected))
if all(matches) and (not line.waited_for or override_waited_for):
if after is None:
too_early = False
else:
too_early = ((line.timestamp, line.msecs) <
(after.timestamp, after.msecs))
if (all(matches) and
(not line.waited_for or override_waited_for) and
not too_early):
# If we waited for this line, chances are we don't mean the
# same thing the next time we use wait_for and it matches
# this line again.
@ -422,7 +430,7 @@ class Process(QObject):
pass
def wait_for(self, timeout=None, *, override_waited_for=False,
do_skip=False, divisor=1, **kwargs):
do_skip=False, divisor=1, after=None, **kwargs):
"""Wait until a given value is found in the data.
Keyword arguments to this function get interpreted as attributes of the
@ -435,6 +443,7 @@ class Process(QObject):
again.
do_skip: If set, call pytest.skip on a timeout.
divisor: A factor to decrease the timeout by.
after: If it's an existing line, ensure it's after the given one.
Return:
The matched line.
@ -456,7 +465,8 @@ class Process(QObject):
for key in kwargs:
assert key in self.KEYS
existing = self._wait_for_existing(override_waited_for, **kwargs)
existing = self._wait_for_existing(override_waited_for, after,
**kwargs)
if existing is not None:
return existing
else: