Unit test delete_cur_item for tab completion model.

This commit is contained in:
Ryan Roden-Corrent 2016-06-20 21:58:12 -04:00
parent 8321c1a90f
commit 409de10fb4
2 changed files with 27 additions and 0 deletions

View File

@ -532,6 +532,9 @@ class TabbedBrowserStub(QObject):
def page_title(self, i):
return self.tabs[i].title
def on_tab_close_requested(self, idx):
del self.tabs[idx]
class ApplicationStub(QObject):

View File

@ -21,6 +21,7 @@
import collections
from datetime import datetime
from unittest.mock import Mock
import pytest
from PyQt5.QtCore import QUrl
@ -201,6 +202,29 @@ def test_tab_completion(stubs, qtbot, app_stub, win_registry,
]
def test_tab_completion_delete(stubs, qtbot, app_stub, win_registry,
tabbed_browser_stub):
"""Verify closing a tab by deleting it from the completion widget."""
tabbed_browser_stub.tabs = [
stubs.FakeWebView(QUrl('https://github.com'), 'GitHub', 0),
stubs.FakeWebView(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
stubs.FakeWebView(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 2)
]
model = miscmodels.TabCompletionModel()
index = Mock()
cat = Mock()
completion_widget = Mock()
index.isValid = Mock(return_value=True)
index.parent = Mock(return_value=cat)
index.data = Mock(return_value='0/2')
cat.child = Mock(return_value=index)
completion_widget.currentIndex = Mock(return_value=index)
model.delete_cur_item(completion_widget)
actual = [tab.url() for tab in tabbed_browser_stub.tabs]
assert actual == [QUrl('https://github.com'),
QUrl('https://duckduckgo.com')]
def test_setting_section_completion(monkeypatch, stubs):
module = 'qutebrowser.completion.models.configmodel'
_patch_configdata(monkeypatch, stubs, module + '.configdata.DATA')