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:
parent
7f690c3f3f
commit
68e373df44
@ -27,7 +27,7 @@ from unittest import mock
|
|||||||
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
|
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
|
||||||
from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
|
from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
|
||||||
QNetworkCacheMetaData)
|
QNetworkCacheMetaData)
|
||||||
from PyQt5.QtWidgets import QCommonStyle, QWidget
|
from PyQt5.QtWidgets import QCommonStyle, QWidget, QLineEdit
|
||||||
|
|
||||||
from qutebrowser.browser.webkit import webview, history
|
from qutebrowser.browser.webkit import webview, history
|
||||||
from qutebrowser.config import configexc
|
from qutebrowser.config import configexc
|
||||||
@ -360,7 +360,7 @@ class FakeConfigType:
|
|||||||
self.complete = lambda: [(val, '') for val in valid_values]
|
self.complete = lambda: [(val, '') for val in valid_values]
|
||||||
|
|
||||||
|
|
||||||
class FakeStatusbarCommand(QObject):
|
class FakeStatusbarCommand(QLineEdit):
|
||||||
|
|
||||||
"""Stub for the statusbar command prompt."""
|
"""Stub for the statusbar command prompt."""
|
||||||
|
|
||||||
@ -370,34 +370,12 @@ class FakeStatusbarCommand(QObject):
|
|||||||
update_completion = pyqtSignal()
|
update_completion = pyqtSignal()
|
||||||
show_cmd = pyqtSignal()
|
show_cmd = pyqtSignal()
|
||||||
hide_cmd = pyqtSignal()
|
hide_cmd = pyqtSignal()
|
||||||
textChanged = pyqtSignal()
|
|
||||||
|
|
||||||
def __init__(self, parent=None, name=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
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):
|
def prefix(self):
|
||||||
return self._text[0]
|
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
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigStub(QObject):
|
class ConfigStub(QObject):
|
||||||
|
@ -40,9 +40,11 @@ class FakeCompletionModel(QStandardItemModel):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cmd(stubs):
|
def cmd(stubs, qtbot):
|
||||||
"""Create the statusbar command prompt the completer uses."""
|
"""Create the statusbar command prompt the completer uses."""
|
||||||
return stubs.FakeStatusbarCommand()
|
cmd = stubs.FakeStatusbarCommand()
|
||||||
|
qtbot.addWidget(cmd)
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -183,6 +185,5 @@ def test_change_completed_part(before, newtxt, after, immediate, completer_obj,
|
|||||||
cmd.setCursorPosition(before_pos)
|
cmd.setCursorPosition(before_pos)
|
||||||
completer_obj.update_cursor_part()
|
completer_obj.update_cursor_part()
|
||||||
completer_obj.change_completed_part(newtxt, immediate)
|
completer_obj.change_completed_part(newtxt, immediate)
|
||||||
assert cmd.focus()
|
|
||||||
assert cmd.text() == after_txt
|
assert cmd.text() == after_txt
|
||||||
assert cmd.cursorPosition() == after_pos
|
assert cmd.cursorPosition() == after_pos
|
||||||
|
Loading…
Reference in New Issue
Block a user