Skip to content

Commit 77b1cb0

Browse files
committed
Added capturing signals and their arguments for MultiSignalBlocker (see all_signals_and_args). Cleaned up large parts of the code of MultiSignalBlocker for better readability. Updated documentation. Added tests. #151
1 parent 23de0d1 commit 77b1cb0

File tree

4 files changed

+584
-69
lines changed

4 files changed

+584
-69
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.0
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>` ``namedtuple`` 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
@@ -215,8 +215,12 @@ def waitSignal(self, signal=None, timeout=1000, raising=None, check_params_cb=No
215215
.. versionadded:: 1.4
216216
The *raising* parameter.
217217
218+
.. versionadded:: 2.0
219+
The *check_params_cb* parameter.
220+
218221
:param Signal signal:
219-
A signal to wait for. Set to ``None`` to just use timeout.
222+
A signal to wait for, or a tuple (signal, signal_name_as_str) to improve the error message that is part
223+
of ``SignalTimeoutError``. Set to ``None`` to just use timeout.
220224
:param int timeout:
221225
How many milliseconds to wait before resuming control flow.
222226
:param bool raising:
@@ -225,7 +229,7 @@ def waitSignal(self, signal=None, timeout=1000, raising=None, check_params_cb=No
225229
This defaults to ``True`` unless ``qt_wait_signal_raising = false``
226230
is set in the config.
227231
:param Callable check_params_cb:
228-
Optional ``callable(*parameters)`` that compares the provided signal parameters to some expected parameters.
232+
Optional ``callable`` that compares the provided signal parameters to some expected parameters.
229233
It has to match the signature of ``signal`` (just like a slot function would) and return ``True`` if
230234
parameters match, ``False`` otherwise.
231235
:returns:
@@ -274,8 +278,9 @@ def waitSignals(self, signals=None, timeout=1000, raising=None, check_params_cbs
274278
blocker.wait()
275279
276280
:param list signals:
277-
A list of :class:`Signal` objects to wait for. Set to ``None`` to just use
278-
timeout.
281+
A list of :class:`Signal` objects to wait for. Alternatively: a list of (``Signal, str``) tuples of the form
282+
``(signal, signal_name_as_str)`` to improve the error message that is part of ``SignalTimeoutError``.
283+
Set to ``None`` to just use timeout.
279284
:param int timeout:
280285
How many milliseconds to wait before resuming control flow.
281286
:param bool raising:

0 commit comments

Comments
 (0)