Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explicit emit() inside waitSignal blocks now works #17

Merged
merged 2 commits into from
Sep 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ env:
- PYTEST_VERSION=2.6.0 PYTEST_QT_FORCE_PYQT=false

install:
- sudo apt-get update

# Qt
- python install-qt.py

Expand Down
13 changes: 12 additions & 1 deletion pytestqt/_tests/test_wait_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def explicit_wait(qtbot, signal, timeout):
Explicit wait for the signal using blocker API.
"""
blocker = qtbot.waitSignal(signal, timeout)
assert blocker.signal_triggered is None
assert not blocker.signal_triggered
blocker.wait()
return blocker

Expand Down Expand Up @@ -73,3 +73,14 @@ def test_signal_triggered(qtbot, wait_function, emit_delay, timeout,
timeout = emit_delay * 4
max_wait_ms = max(emit_delay, timeout)
assert time.time() - start_time < (max_wait_ms / 1000.0)


def test_explicit_emit(qtbot):
"""
Make sure an explicit emit() inside a waitSignal block works.
"""
signaller = Signaller()
with qtbot.waitSignal(signaller.signal, timeout=5000) as waiting:
signaller.signal.emit()

assert waiting.signal_triggered
6 changes: 3 additions & 3 deletions pytestqt/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def __init__(self, timeout=1000):
self._loop = QtCore.QEventLoop()
self._signals = []
self.timeout = timeout
self.signal_triggered = None
self.signal_triggered = False

def wait(self):
"""
Expand All @@ -289,11 +289,12 @@ def wait(self):
:raise ValueError: if no signals are connected and timeout is None; in
this case it would wait forever.
"""
if self.signal_triggered:
return
if self.timeout is None and len(self._signals) == 0:
raise ValueError("No signals or timeout specified.")
if self.timeout is not None:
QtCore.QTimer.singleShot(self.timeout, self._loop.quit)
self.signal_triggered = False
self._loop.exec_()

def connect(self, signal):
Expand All @@ -306,7 +307,6 @@ def connect(self, signal):
signal.connect(self._quit_loop_by_signal)
self._signals.append(signal)


def _quit_loop_by_signal(self):
"""
quits the event loop and marks that we finished because of a signal.
Expand Down