tests: Add after= argument to wait_for
This commit is contained in:
parent
3a04de62ae
commit
b554e1f763
@ -333,7 +333,7 @@ class Process(QObject):
|
|||||||
else:
|
else:
|
||||||
return value == expected
|
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.
|
"""Check if there are any line in the history for wait_for.
|
||||||
|
|
||||||
Return: either the found line or None.
|
Return: either the found line or None.
|
||||||
@ -345,7 +345,15 @@ class Process(QObject):
|
|||||||
value = getattr(line, key)
|
value = getattr(line, key)
|
||||||
matches.append(self._match_data(value, expected))
|
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
|
# 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
|
# same thing the next time we use wait_for and it matches
|
||||||
# this line again.
|
# this line again.
|
||||||
@ -422,7 +430,7 @@ class Process(QObject):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def wait_for(self, timeout=None, *, override_waited_for=False,
|
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.
|
"""Wait until a given value is found in the data.
|
||||||
|
|
||||||
Keyword arguments to this function get interpreted as attributes of the
|
Keyword arguments to this function get interpreted as attributes of the
|
||||||
@ -435,6 +443,7 @@ class Process(QObject):
|
|||||||
again.
|
again.
|
||||||
do_skip: If set, call pytest.skip on a timeout.
|
do_skip: If set, call pytest.skip on a timeout.
|
||||||
divisor: A factor to decrease the timeout by.
|
divisor: A factor to decrease the timeout by.
|
||||||
|
after: If it's an existing line, ensure it's after the given one.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
The matched line.
|
The matched line.
|
||||||
@ -456,7 +465,8 @@ class Process(QObject):
|
|||||||
for key in kwargs:
|
for key in kwargs:
|
||||||
assert key in self.KEYS
|
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:
|
if existing is not None:
|
||||||
return existing
|
return existing
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user