Skip to content

Commit dfbd99d

Browse files
authored
Merge pull request #153 from MShekow/master
Support for capturing signals and args and improved SignalTimeoutError messages
2 parents 05f8bcf + 56771f0 commit dfbd99d

File tree

4 files changed

+775
-64
lines changed

4 files changed

+775
-64
lines changed

docs/signals.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ of the blocker:
114114
Signals without arguments will set ``args`` to an empty list. If the time out
115115
is reached instead, ``args`` will be ``None``.
116116

117+
Getting all arguments of non-matching arguments
118+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119+
120+
.. versionadded:: 2.1
121+
122+
When using the ``check_params_cb`` parameter, it may happen that the provided signal is received multiple times with
123+
different parameter values, which may or may not match the requirements of the callback.
124+
``all_args`` then contains the list of signal parameters (as tuple) in the order they were received.
125+
126+
117127
waitSignals
118128
-----------
119129

@@ -174,7 +184,7 @@ evaluation takes place).
174184
175185
176186
order parameter
177-
^^^^^^^^^^^^^^^^^^^^^
187+
^^^^^^^^^^^^^^^
178188

179189
.. versionadded:: 2.0
180190

@@ -194,6 +204,17 @@ A third option is to set ``order="simple"`` which is like "strict", but signals
194204
in-between the provided ones, e.g. if the expected signals are ``[a, b, c]`` and the sender
195205
actually emits ``[a, a, b, a, c]``, the test completes successfully (it would fail with ``order="strict"``).
196206

207+
Getting emitted signals and arguments
208+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209+
210+
.. versionadded:: 2.1
211+
212+
To determine which of the expected signals were emitted during a ``wait()`` you can use
213+
``blocker.all_signals_and_args`` which contains a list of
214+
:class:`wait_signal.SignalAndArgs <SignalAndArgs>` objects, indicating the signals (and their arguments)
215+
in the order they were received.
216+
217+
197218
Making sure a given signal is not emitted
198219
-----------------------------------------
199220

pytestqt/qtbot.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,12 @@ def waitSignal(self, signal=None, timeout=1000, raising=None, check_params_cb=No
216216
.. versionadded:: 1.4
217217
The *raising* parameter.
218218
219+
.. versionadded:: 2.0
220+
The *check_params_cb* parameter.
221+
219222
:param Signal signal:
220-
A signal to wait for. Set to ``None`` to just use timeout.
223+
A signal to wait for, or a tuple ``(signal, signal_name_as_str)`` to improve the error message that is part
224+
of ``SignalTimeoutError``. Set to ``None`` to just use timeout.
221225
:param int timeout:
222226
How many milliseconds to wait before resuming control flow.
223227
:param bool raising:
@@ -226,7 +230,7 @@ def waitSignal(self, signal=None, timeout=1000, raising=None, check_params_cb=No
226230
This defaults to ``True`` unless ``qt_wait_signal_raising = false``
227231
is set in the config.
228232
:param Callable check_params_cb:
229-
Optional ``callable(*parameters)`` that compares the provided signal parameters to some expected parameters.
233+
Optional ``callable`` that compares the provided signal parameters to some expected parameters.
230234
It has to match the signature of ``signal`` (just like a slot function would) and return ``True`` if
231235
parameters match, ``False`` otherwise.
232236
:returns:
@@ -275,8 +279,9 @@ def waitSignals(self, signals=None, timeout=1000, raising=None, check_params_cbs
275279
blocker.wait()
276280
277281
:param list signals:
278-
A list of :class:`Signal` objects to wait for. Set to ``None`` to just use
279-
timeout.
282+
A list of :class:`Signal` objects to wait for. Alternatively: a list of (``Signal, str``) tuples of the form
283+
``(signal, signal_name_as_str)`` to improve the error message that is part of ``SignalTimeoutError``.
284+
Set to ``None`` to just use timeout.
280285
:param int timeout:
281286
How many milliseconds to wait before resuming control flow.
282287
:param bool raising:

0 commit comments

Comments
 (0)