From d2a1282c0b783f1f60e9ae0ddfefbcfc6f0efc39 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 6 Jan 2016 08:49:30 +0100 Subject: [PATCH] tests: Split up testprocess.wait_for. --- tests/integration/testprocess.py | 39 +++++++++++++++++++------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tests/integration/testprocess.py b/tests/integration/testprocess.py index 41415139f..10f8914ce 100644 --- a/tests/integration/testprocess.py +++ b/tests/integration/testprocess.py @@ -287,6 +287,26 @@ class Process(QObject): return line return None + def _wait_for_match(self, spy, kwargs): + """Try matching the kwargs with the given QSignalSpy.""" + for args in spy: + assert len(args) == 1 + line = args[0] + + matches = [] + + for key, expected in kwargs.items(): + value = getattr(line, key) + matches.append(self._match_data(value, expected)) + + if all(matches): + # 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. + line.waited_for = True + return line + return None + def wait_for(self, timeout=None, *, override_waited_for=False, do_skip=False, **kwargs): """Wait until a given value is found in the data. @@ -337,22 +357,9 @@ class Process(QObject): else: raise WaitForTimeout(msg) - for args in spy: - assert len(args) == 1 - line = args[0] - - matches = [] - - for key, expected in kwargs.items(): - value = getattr(line, key) - matches.append(self._match_data(value, expected)) - - if all(matches): - # 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. - line.waited_for = True - return line + match = self._wait_for_match(spy, kwargs) + if match is not None: + return match def ensure_not_logged(self, delay=500, **kwargs): """Make sure the data matching the given arguments is not logged.