From 409de10fb4377593dcec8ff78f0a865ce96b8b7a Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Mon, 20 Jun 2016 21:58:12 -0400 Subject: [PATCH] Unit test delete_cur_item for tab completion model. --- tests/helpers/stubs.py | 3 +++ tests/unit/completion/test_models.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index 4c504af34..c0b9c4cf3 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -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): diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 4f3e61b6c..19bd3c2de 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -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')