Don't use objreg to get CompletionView.

The CompletionView is the parent of the Completer, so there's no need
to use objreg to get it.
See #640.
This commit is contained in:
Ryan Roden-Corrent 2016-07-27 12:14:42 -04:00
parent b9cf9d180b
commit ffc5a42d04
3 changed files with 30 additions and 19 deletions

View File

@ -125,8 +125,7 @@ class Completer(QObject):
def _model(self): def _model(self):
"""Convenience method to get the current completion model.""" """Convenience method to get the current completion model."""
completion = objreg.get('completion', scope='window', completion = self.parent()
window=self._win_id)
return completion.model() return completion.model()
def _get_completion_model(self, completion, parts, cursor_part): def _get_completion_model(self, completion, parts, cursor_part):
@ -315,8 +314,7 @@ class Completer(QObject):
self._ignore_change = False self._ignore_change = False
return return
completion = objreg.get('completion', scope='window', completion = self.parent()
window=self._win_id)
if self._cmd.prefix() != ':': if self._cmd.prefix() != ':':
# This is a search or gibberish, so we don't need to complete # This is a search or gibberish, so we don't need to complete

View File

@ -267,14 +267,6 @@ def app_stub(stubs):
objreg.delete('app') objreg.delete('app')
@pytest.yield_fixture
def completion_widget_stub(win_registry):
stub = unittest.mock.Mock()
objreg.register('completion', stub, scope='window', window=0)
yield stub
objreg.delete('completion', scope='window', window=0)
@pytest.yield_fixture @pytest.yield_fixture
def status_command_stub(stubs, qtbot, win_registry): def status_command_stub(stubs, qtbot, win_registry):
"""Fixture which provides a fake status-command object.""" """Fixture which provides a fake status-command object."""

View File

@ -22,6 +22,7 @@
import unittest.mock import unittest.mock
import pytest import pytest
from PyQt5.QtCore import QObject
from PyQt5.QtGui import QStandardItemModel from PyQt5.QtGui import QStandardItemModel
from qutebrowser.completion import completer from qutebrowser.completion import completer
@ -39,13 +40,33 @@ class FakeCompletionModel(QStandardItemModel):
self.kind = kind self.kind = kind
class CompletionWidgetStub(QObject):
"""Stub for the CompletionView."""
def __init__(self, parent=None):
super().__init__(parent)
self.hide = unittest.mock.Mock()
self.show = unittest.mock.Mock()
self.set_pattern = unittest.mock.Mock()
self.model = unittest.mock.Mock()
self.set_model = unittest.mock.Mock()
self.enabled = unittest.mock.Mock()
@pytest.fixture @pytest.fixture
def completer_obj(qtbot, status_command_stub, config_stub, monkeypatch, stubs): def completion_widget_stub():
return CompletionWidgetStub()
@pytest.fixture
def completer_obj(qtbot, status_command_stub, config_stub, monkeypatch, stubs,
completion_widget_stub):
"""Create the completer used for testing.""" """Create the completer used for testing."""
monkeypatch.setattr('qutebrowser.completion.completer.QTimer', monkeypatch.setattr('qutebrowser.completion.completer.QTimer',
stubs.InstaTimer) stubs.InstaTimer)
config_stub.data = {'completion': {'auto-open': False}} config_stub.data = {'completion': {'auto-open': False}}
return completer.Completer(status_command_stub, 0) return completer.Completer(status_command_stub, 0, completion_widget_stub)
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -166,8 +187,8 @@ def test_update_completion(txt, expected, status_command_stub, completer_obj,
assert arg.srcmodel.kind == expected assert arg.srcmodel.kind == expected
def test_completion_item_prev(completer_obj, status_command_stub, def test_completion_item_prev(completer_obj, status_command_stub, config_stub,
completion_widget_stub, config_stub, qtbot): qtbot):
"""Test that completion_item_prev emits next_prev_item.""" """Test that completion_item_prev emits next_prev_item."""
status_command_stub.setText(':') status_command_stub.setText(':')
with qtbot.waitSignal(completer_obj.next_prev_item) as blocker: with qtbot.waitSignal(completer_obj.next_prev_item) as blocker:
@ -175,8 +196,8 @@ def test_completion_item_prev(completer_obj, status_command_stub,
assert blocker.args == [True] assert blocker.args == [True]
def test_completion_item_next(completer_obj, status_command_stub, def test_completion_item_next(completer_obj, status_command_stub, config_stub,
completion_widget_stub, config_stub, qtbot): qtbot):
"""Test that completion_item_next emits next_prev_item.""" """Test that completion_item_next emits next_prev_item."""
status_command_stub.setText(':') status_command_stub.setText(':')
with qtbot.waitSignal(completer_obj.next_prev_item) as blocker: with qtbot.waitSignal(completer_obj.next_prev_item) as blocker:
@ -209,7 +230,7 @@ def test_on_selection_changed(before, newtxt, count, quick_complete, after,
indexes = [unittest.mock.Mock()] indexes = [unittest.mock.Mock()]
selection = unittest.mock.Mock() selection = unittest.mock.Mock()
selection.indexes = unittest.mock.Mock(return_value=indexes) selection.indexes = unittest.mock.Mock(return_value=indexes)
completion_widget_stub.model = unittest.mock.Mock(return_value=model) completion_widget_stub.model.return_value = model
_set_cmd_prompt(status_command_stub, before) _set_cmd_prompt(status_command_stub, before)
# schedule_completion_update is needed to pick up the cursor position # schedule_completion_update is needed to pick up the cursor position
completer_obj.schedule_completion_update() completer_obj.schedule_completion_update()