def waitSignal(self, signal, *, timeout=5000, raising=None, check_params_cb=None): """ .. versionadded:: 1.2 Stops current test until a signal is triggered. Used to stop the control flow of a test until a signal is emitted, or a number of milliseconds, specified by ``timeout``, has elapsed. Best used as a context manager:: with qtbot.waitSignal(signal, timeout=1000): long_function_that_calls_signal() Also, you can use the :class:`SignalBlocker` directly if the context manager form is not convenient:: blocker = qtbot.waitSignal(signal, timeout=1000) blocker.connect(another_signal) long_function_that_calls_signal() blocker.wait() Any additional signal, when triggered, will make :meth:`wait` return. .. versionadded:: 1.4 The *raising* parameter. .. versionadded:: 2.0 The *check_params_cb* parameter. :param Signal signal: A signal to wait for, or a tuple ``(signal, signal_name_as_str)`` to improve the error message that is part of ``TimeoutError``. :param int timeout: How many milliseconds to wait before resuming control flow. :param bool raising: If :class:`QtBot.TimeoutError <pytestqt.plugin.TimeoutError>` should be raised if a timeout occurred. This defaults to ``True`` unless ``qt_default_raising = false`` is set in the config. :param Callable check_params_cb: Optional ``callable`` that compares the provided signal parameters to some expected parameters. It has to match the signature of ``signal`` (just like a slot function would) and return ``True`` if parameters match, ``False`` otherwise. :returns: ``SignalBlocker`` object. Call ``SignalBlocker.wait()`` to wait. .. note:: This method is also available as ``wait_signal`` (pep-8 alias) """ if signal is None: raise ValueError( f"Passing None as signal isn't supported anymore, use qtbot.wait({timeout}) instead." ) raising = self._should_raise(raising) blocker = SignalBlocker( timeout=timeout, raising=raising, check_params_cb=check_params_cb ) blocker.connect(signal) return blocker
def waitSignal(self, signal=None, timeout=1000, raising=None): """ .. versionadded:: 1.2 Stops current test until a signal is triggered. Used to stop the control flow of a test until a signal is emitted, or a number of milliseconds, specified by ``timeout``, has elapsed. Best used as a context manager:: with qtbot.waitSignal(signal, timeout=1000): long_function_that_calls_signal() Also, you can use the :class:`SignalBlocker` directly if the context manager form is not convenient:: blocker = qtbot.waitSignal(signal, timeout=1000) blocker.connect(another_signal) long_function_that_calls_signal() blocker.wait() Any additional signal, when triggered, will make :meth:`wait` return. .. versionadded:: 1.4 The *raising* parameter. :param Signal signal: A signal to wait for. Set to ``None`` to just use timeout. :param int timeout: How many milliseconds to wait before resuming control flow. :param bool raising: If :class:`QtBot.SignalTimeoutError <pytestqt.plugin.SignalTimeoutError>` should be raised if a timeout occurred. This defaults to ``True`` unless ``qt_wait_signal_raising = false`` is set in the config. :returns: ``SignalBlocker`` object. Call ``SignalBlocker.wait()`` to wait. .. note:: Cannot have both ``signals`` and ``timeout`` equal ``None``, or else you will block indefinitely. We throw an error if this occurs. .. note:: This method is also available as ``wait_signal`` (pep-8 alias) """ if raising is None: raising_val = self._request.config.getini('qt_wait_signal_raising') if not raising_val: raising = True else: raising = _parse_ini_boolean(raising_val) blocker = SignalBlocker(timeout=timeout, raising=raising) if signal is not None: blocker.connect(signal) return blocker
def waitSignal(self, signal=None, timeout=1000, raising=None): """ .. versionadded:: 1.2 Stops current test until a signal is triggered. Used to stop the control flow of a test until a signal is emitted, or a number of milliseconds, specified by ``timeout``, has elapsed. Best used as a context manager:: with qtbot.waitSignal(signal, timeout=1000): long_function_that_calls_signal() Also, you can use the :class:`SignalBlocker` directly if the context manager form is not convenient:: blocker = qtbot.waitSignal(signal, timeout=1000) blocker.connect(another_signal) long_function_that_calls_signal() blocker.wait() Any additional signal, when triggered, will make :meth:`wait` return. .. versionadded:: 1.4 The *raising* parameter. :param Signal signal: A signal to wait for. Set to ``None`` to just use timeout. :param int timeout: How many milliseconds to wait before resuming control flow. :param bool raising: If :class:`QtBot.SignalTimeoutError <pytestqt.plugin.SignalTimeoutError>` should be raised if a timeout occurred. :returns: ``SignalBlocker`` object. Call ``SignalBlocker.wait()`` to wait. .. note:: Cannot have both ``signals`` and ``timeout`` equal ``None``, or else you will block indefinitely. We throw an error if this occurs. """ if raising is None: raising = self._request.config.getini('qt_wait_signal_raising') blocker = SignalBlocker(timeout=timeout, raising=raising) if signal is not None: blocker.connect(signal) return blocker
def waitSignal(self, signal=None, timeout=1000, raising=None, check_params_cb=None): """ .. versionadded:: 1.2 Stops current test until a signal is triggered. Used to stop the control flow of a test until a signal is emitted, or a number of milliseconds, specified by ``timeout``, has elapsed. Best used as a context manager:: with qtbot.waitSignal(signal, timeout=1000): long_function_that_calls_signal() Also, you can use the :class:`SignalBlocker` directly if the context manager form is not convenient:: blocker = qtbot.waitSignal(signal, timeout=1000) blocker.connect(another_signal) long_function_that_calls_signal() blocker.wait() Any additional signal, when triggered, will make :meth:`wait` return. .. versionadded:: 1.4 The *raising* parameter. .. versionadded:: 2.0 The *check_params_cb* parameter. :param Signal signal: A signal to wait for, or a tuple ``(signal, signal_name_as_str)`` to improve the error message that is part of ``TimeoutError``. Set to ``None`` to just use timeout. :param int timeout: How many milliseconds to wait before resuming control flow. :param bool raising: If :class:`QtBot.TimeoutError <pytestqt.plugin.TimeoutError>` should be raised if a timeout occurred. This defaults to ``True`` unless ``qt_default_raising = false`` is set in the config. :param Callable check_params_cb: Optional ``callable`` that compares the provided signal parameters to some expected parameters. It has to match the signature of ``signal`` (just like a slot function would) and return ``True`` if parameters match, ``False`` otherwise. :returns: ``SignalBlocker`` object. Call ``SignalBlocker.wait()`` to wait. .. note:: Cannot have both ``signals`` and ``timeout`` equal ``None``, or else you will block indefinitely. We throw an error if this occurs. .. note:: This method is also available as ``wait_signal`` (pep-8 alias) """ raising = self._should_raise(raising) blocker = SignalBlocker( timeout=timeout, raising=raising, check_params_cb=check_params_cb ) if signal is not None: blocker.connect(signal) return blocker