Test Completer.schedule_completion_update.
update_completion is only used internally, so instead test the real public entry point which is schedule_completion_update. This required mocking out QTimer to fire immediately so the test didn't have to do flaky artificial delays.
This commit is contained in:
parent
b48b7eddc8
commit
aedf5b930a
@ -381,6 +381,28 @@ class FakeTimer(QObject):
|
||||
return self._started
|
||||
|
||||
|
||||
class InstaTimer(QObject):
|
||||
|
||||
"""Stub for a QTimer that fires instantly on start().
|
||||
|
||||
Useful to test a time-based event without inserting an artificial delay.
|
||||
"""
|
||||
|
||||
timeout = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
def start(self):
|
||||
self.timeout.emit()
|
||||
|
||||
def setSingleShot(self, yes):
|
||||
pass
|
||||
|
||||
def setInterval(self, interval):
|
||||
pass
|
||||
|
||||
|
||||
class FakeConfigType:
|
||||
|
||||
"""A stub to provide valid_values for typ attribute of a SettingValue."""
|
||||
|
@ -48,8 +48,10 @@ def cmd(stubs, qtbot):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def completer_obj(qtbot, cmd, config_stub):
|
||||
def completer_obj(qtbot, cmd, config_stub, monkeypatch, stubs):
|
||||
"""Create the completer used for testing."""
|
||||
monkeypatch.setattr('qutebrowser.completion.completer.QTimer',
|
||||
stubs.InstaTimer)
|
||||
config_stub.data = {'completion': {'auto-open': False}}
|
||||
return completer.Completer(cmd, 0)
|
||||
|
||||
@ -162,7 +164,7 @@ def test_update_completion(txt, expected, cmd, completer_obj,
|
||||
"""Test setting the completion widget's model based on command text."""
|
||||
# this test uses | as a placeholder for the current cursor position
|
||||
_set_cmd_prompt(cmd, txt)
|
||||
completer_obj.update_completion()
|
||||
completer_obj.schedule_completion_update()
|
||||
if expected is None:
|
||||
assert not completion_widget_stub.set_model.called
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user