Handle an immediate callback in CallbackChecker
This commit is contained in:
parent
359d4dd427
commit
7dadc28eb7
@ -77,20 +77,24 @@ class CallbackChecker(QObject):
|
|||||||
"""Check if a value provided by a callback is the expected one."""
|
"""Check if a value provided by a callback is the expected one."""
|
||||||
|
|
||||||
got_result = pyqtSignal(object)
|
got_result = pyqtSignal(object)
|
||||||
|
UNSET = object()
|
||||||
|
|
||||||
def __init__(self, qtbot, parent=None):
|
def __init__(self, qtbot, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._qtbot = qtbot
|
self._qtbot = qtbot
|
||||||
|
self._result = self.UNSET
|
||||||
|
|
||||||
def callback(self, result):
|
def callback(self, result):
|
||||||
"""Callback which can be passed to runJavaScript."""
|
"""Callback which can be passed to runJavaScript."""
|
||||||
|
self._result = result
|
||||||
self.got_result.emit(result)
|
self.got_result.emit(result)
|
||||||
|
|
||||||
def check(self, expected):
|
def check(self, expected):
|
||||||
"""Wait until the JS result arrived and compare it."""
|
"""Wait until the JS result arrived and compare it."""
|
||||||
with self._qtbot.waitSignal(self.got_result) as blocker:
|
if self._result is self.UNSET:
|
||||||
pass
|
with self._qtbot.waitSignal(self.got_result):
|
||||||
assert blocker.args == [expected]
|
pass
|
||||||
|
assert self._result == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
Loading…
Reference in New Issue
Block a user