From 9d49f5a57d63f713b2326ada87295a62ed3ccc39 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Thu, 23 Jun 2016 08:21:55 -0400 Subject: [PATCH] Test tab completion with multiple tabbed browsers. --- tests/helpers/fixtures.py | 13 ++++++++----- tests/unit/completion/test_models.py | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index 5482d6e66..2530a1ab6 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -235,12 +235,15 @@ def session_manager_stub(stubs): @pytest.yield_fixture -def tabbed_browser_stub(stubs): - """Fixture which provides a fake tabbed-browser object.""" - stub = stubs.TabbedBrowserStub() - objreg.register('tabbed-browser', stub, scope='window', window=0) - yield stub +def tabbed_browser_stubs(stubs, win_registry): + """Fixture providing a fake tabbed-browser object on win_id 0 and 1.""" + win_registry.add_window(1) + stubs = [stubs.TabbedBrowserStub(), stubs.TabbedBrowserStub()] + objreg.register('tabbed-browser', stubs[0], scope='window', window=0) + objreg.register('tabbed-browser', stubs[1], scope='window', window=1) + yield stubs objreg.delete('tabbed-browser', scope='window', window=0) + objreg.delete('tabbed-browser', scope='window', window=1) @pytest.yield_fixture diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index eaab94d01..f7c1e141e 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -231,30 +231,39 @@ def test_session_completion(session_manager_stub): def test_tab_completion(stubs, qtbot, app_stub, win_registry, - tabbed_browser_stub): - tabbed_browser_stub.tabs = [ + tabbed_browser_stubs): + tabbed_browser_stubs[0].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) ] + tabbed_browser_stubs[1].tabs = [ + stubs.FakeWebView(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0), + ] actual = _get_completions(miscmodels.TabCompletionModel()) assert actual == [ ('0', [ ('0/1', 'https://github.com', 'GitHub'), ('0/2', 'https://wikipedia.org', 'Wikipedia'), ('0/3', 'https://duckduckgo.com', 'DuckDuckGo') + ]), + ('1', [ + ('1/1', 'https://wiki.archlinux.org', 'ArchWiki'), ]) ] def test_tab_completion_delete(stubs, qtbot, app_stub, win_registry, - tabbed_browser_stub): + tabbed_browser_stubs): """Verify closing a tab by deleting it from the completion widget.""" - tabbed_browser_stub.tabs = [ + tabbed_browser_stubs[0].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) ] + tabbed_browser_stubs[1].tabs = [ + stubs.FakeWebView(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0), + ] model = miscmodels.TabCompletionModel() index = Mock() cat = Mock() @@ -265,7 +274,7 @@ def test_tab_completion_delete(stubs, qtbot, app_stub, win_registry, 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] + actual = [tab.url() for tab in tabbed_browser_stubs[0].tabs] assert actual == [QUrl('https://github.com'), QUrl('https://duckduckgo.com')]