From 68e373df44cf19152d6037d2dc1300b30a1630c1 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 3 Jul 2016 23:06:36 -0400 Subject: [PATCH] Use QLineEdit as a base for FakeStatusbarCommand. Reduces the amount of mocking and keeps it more true to the original. --- tests/helpers/stubs.py | 30 ++++--------------------- tests/unit/completion/test_completer.py | 7 +++--- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index f5f50a0ec..d08b35f60 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -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): diff --git a/tests/unit/completion/test_completer.py b/tests/unit/completion/test_completer.py index bb058a9af..f8d359a13 100644 --- a/tests/unit/completion/test_completer.py +++ b/tests/unit/completion/test_completer.py @@ -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