Skip to content
  • Sponsor pytest-dev/pytest-qt

  • Notifications You must be signed in to change notification settings
  • Fork 69

Commit bb1b588

Browse files
committedSep 10, 2014
Merge pull request #17 from nicoddemus/issue16
explicit emit() inside waitSignal blocks now works
2 parents 19d46f8 + 9048814 commit bb1b588

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed
 

‎.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ env:
1414
- PYTEST_VERSION=2.6.0 PYTEST_QT_FORCE_PYQT=false
1515

1616
install:
17+
- sudo apt-get update
18+
1719
# Qt
1820
- python install-qt.py
1921

‎pytestqt/_tests/test_wait_signal.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def explicit_wait(qtbot, signal, timeout):
2323
Explicit wait for the signal using blocker API.
2424
"""
2525
blocker = qtbot.waitSignal(signal, timeout)
26-
assert blocker.signal_triggered is None
26+
assert not blocker.signal_triggered
2727
blocker.wait()
2828
return blocker
2929

@@ -73,3 +73,14 @@ def test_signal_triggered(qtbot, wait_function, emit_delay, timeout,
7373
timeout = emit_delay * 4
7474
max_wait_ms = max(emit_delay, timeout)
7575
assert time.time() - start_time < (max_wait_ms / 1000.0)
76+
77+
78+
def test_explicit_emit(qtbot):
79+
"""
80+
Make sure an explicit emit() inside a waitSignal block works.
81+
"""
82+
signaller = Signaller()
83+
with qtbot.waitSignal(signaller.signal, timeout=5000) as waiting:
84+
signaller.signal.emit()
85+
86+
assert waiting.signal_triggered

‎pytestqt/plugin.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def __init__(self, timeout=1000):
280280
self._loop = QtCore.QEventLoop()
281281
self._signals = []
282282
self.timeout = timeout
283-
self.signal_triggered = None
283+
self.signal_triggered = False
284284

285285
def wait(self):
286286
"""
@@ -289,11 +289,12 @@ def wait(self):
289289
:raise ValueError: if no signals are connected and timeout is None; in
290290
this case it would wait forever.
291291
"""
292+
if self.signal_triggered:
293+
return
292294
if self.timeout is None and len(self._signals) == 0:
293295
raise ValueError("No signals or timeout specified.")
294296
if self.timeout is not None:
295297
QtCore.QTimer.singleShot(self.timeout, self._loop.quit)
296-
self.signal_triggered = False
297298
self._loop.exec_()
298299

299300
def connect(self, signal):
@@ -306,7 +307,6 @@ def connect(self, signal):
306307
signal.connect(self._quit_loop_by_signal)
307308
self._signals.append(signal)
308309

309-
310310
def _quit_loop_by_signal(self):
311311
"""
312312
quits the event loop and marks that we finished because of a signal.

0 commit comments

Comments
 (0)