Skip to content

Commit

Permalink
Merge pull request #17 from nicoddemus/issue16
Browse files Browse the repository at this point in the history
explicit emit() inside waitSignal blocks now works
  • Loading branch information
nicoddemus committed Sep 10, 2014
2 parents 19d46f8 + 9048814 commit bb1b588
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
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

0 comments on commit bb1b588

Please sign in to comment.