Use QLineEdit as a base for FakeStatusbarCommand.

Reduces the amount of mocking and keeps it more true to the original.
This commit is contained in:
Ryan Roden-Corrent 2016-07-03 23:06:36 -04:00
parent 7f690c3f3f
commit 68e373df44
2 changed files with 8 additions and 29 deletions

View File

@ -27,7 +27,7 @@ from unittest import mock
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
QNetworkCacheMetaData)
from PyQt5.QtWidgets import QCommonStyle, QWidget
from PyQt5.QtWidgets import QCommonStyle, QWidget, QLineEdit
from qutebrowser.browser.webkit import webview, history
from qutebrowser.config import configexc
@ -360,7 +360,7 @@ class FakeConfigType:
self.complete = lambda: [(val, '') for val in valid_values]
class FakeStatusbarCommand(QObject):
class FakeStatusbarCommand(QLineEdit):
"""Stub for the statusbar command prompt."""
@ -370,34 +370,12 @@ class FakeStatusbarCommand(QObject):
update_completion = pyqtSignal()
show_cmd = pyqtSignal()
hide_cmd = pyqtSignal()
textChanged = pyqtSignal()
def __init__(self, parent=None, name=None):
def __init__(self, parent=None):
super().__init__(parent)
self._cursor_pos = 0
self._text = ""
self._focus = False
def cursorPosition(self):
return self._cursor_pos
def text(self):
return self._text
def prefix(self):
return self._text[0]
def focus(self):
return self._focus
def setFocus(self):
self._focus = True
def setText(self, x):
self._text = x
def setCursorPosition(self, x):
self._cursor_pos = x
return self.text()[0]
class ConfigStub(QObject):

View File

@ -40,9 +40,11 @@ class FakeCompletionModel(QStandardItemModel):
@pytest.fixture
def cmd(stubs):
def cmd(stubs, qtbot):
"""Create the statusbar command prompt the completer uses."""
return stubs.FakeStatusbarCommand()
cmd = stubs.FakeStatusbarCommand()
qtbot.addWidget(cmd)
return cmd
@pytest.fixture
@ -183,6 +185,5 @@ def test_change_completed_part(before, newtxt, after, immediate, completer_obj,
cmd.setCursorPosition(before_pos)
completer_obj.update_cursor_part()
completer_obj.change_completed_part(newtxt, immediate)
assert cmd.focus()
assert cmd.text() == after_txt
assert cmd.cursorPosition() == after_pos