Use a fixture for FakeWebTab

We need to make sure qapp and tab_registry are available everywhere the
FakeWebTab class is used.
This commit is contained in:
Florian Bruhin 2016-07-08 18:48:24 +02:00
parent 0ab601aaf3
commit e36123735b
6 changed files with 24 additions and 18 deletions

View File

@ -122,6 +122,12 @@ def tab_registry(win_registry):
objreg.delete('tab-registry', scope='window', window=0)
@pytest.fixture
def fake_web_tab(stubs, tab_registry, qapp):
"""Fixture providing the FakeWebTab *class*."""
return stubs.FakeWebTab
def _generate_cmdline_tests():
"""Generate testcases for test_split_binding."""
# pylint: disable=invalid-name

View File

@ -304,15 +304,15 @@ def test_session_completion(session_manager_stub):
]
def test_tab_completion(stubs, qtbot, app_stub, win_registry,
def test_tab_completion(fake_web_tab, app_stub, win_registry,
tabbed_browser_stubs):
tabbed_browser_stubs[0].tabs = [
stubs.FakeWebTab(QUrl('https://github.com'), 'GitHub', 0),
stubs.FakeWebTab(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
stubs.FakeWebTab(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 2)
fake_web_tab(QUrl('https://github.com'), 'GitHub', 0),
fake_web_tab(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
fake_web_tab(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 2),
]
tabbed_browser_stubs[1].tabs = [
stubs.FakeWebTab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
]
actual = _get_completions(miscmodels.TabCompletionModel())
assert actual == [
@ -327,16 +327,16 @@ def test_tab_completion(stubs, qtbot, app_stub, win_registry,
]
def test_tab_completion_delete(stubs, qtbot, app_stub, win_registry,
def test_tab_completion_delete(fake_web_tab, qtbot, app_stub, win_registry,
tabbed_browser_stubs):
"""Verify closing a tab by deleting it from the completion widget."""
tabbed_browser_stubs[0].tabs = [
stubs.FakeWebTab(QUrl('https://github.com'), 'GitHub', 0),
stubs.FakeWebTab(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
stubs.FakeWebTab(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 2)
fake_web_tab(QUrl('https://github.com'), 'GitHub', 0),
fake_web_tab(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
fake_web_tab(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 2)
]
tabbed_browser_stubs[1].tabs = [
stubs.FakeWebTab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
]
model = miscmodels.TabCompletionModel()
view = _mock_view_index(model, 0, 1, qtbot)

View File

@ -53,9 +53,9 @@ def test_percentage_text(percentage, y, expected):
assert percentage.text() == expected
def test_tab_change(percentage, stubs, qapp):
def test_tab_change(percentage, fake_web_tab):
"""Make sure the percentage gets changed correctly when switching tabs."""
percentage.set_perc(x=None, y=10)
tab = stubs.FakeWebTab(scroll_pos_perc=(0, 20))
tab = fake_web_tab(scroll_pos_perc=(0, 20))
percentage.on_tab_changed(tab)
assert percentage.text() == '[20%]'

View File

@ -60,14 +60,14 @@ def test_load_started(progress_widget):
(100, usertypes.LoadStatus.warn, False),
(100, usertypes.LoadStatus.none, False),
])
def test_tab_changed(qapp, stubs, progress_widget, progress, load_status,
def test_tab_changed(fake_web_tab, progress_widget, progress, load_status,
expected_visible):
"""Test that progress widget value and visibility state match expectations.
Args:
progress_widget: Progress widget that will be tested.
"""
tab = stubs.FakeWebTab(progress=progress, load_status=load_status)
tab = fake_web_tab(progress=progress, load_status=load_status)
progress_widget.on_tab_changed(tab)
actual = progress_widget.value(), progress_widget.isVisible()
expected = tab.progress(), expected_visible

View File

@ -120,8 +120,8 @@ def test_on_load_status_changed(url_widget, status, expected):
(url.UrlType.warn, QUrl('www.shadysite.org/some/file/with/issues.htm')),
(url.UrlType.error, QUrl('invalid::/url')),
])
def test_on_tab_changed(url_widget, stubs, qapp, load_status, qurl):
tab_widget = stubs.FakeWebTab(load_status=load_status, url=qurl)
def test_on_tab_changed(url_widget, fake_web_tab, load_status, qurl):
tab_widget = fake_web_tab(load_status=load_status, url=qurl)
url_widget.on_tab_changed(tab_widget)
assert url_widget._urltype == load_status
assert url_widget.text() == qurl.toDisplayString()

View File

@ -61,7 +61,7 @@ class TestTabWidget:
qtbot.addWidget(w)
return w
def test_small_icon_doesnt_crash(self, widget, qtbot, stubs):
def test_small_icon_doesnt_crash(self, widget, qtbot, fake_web_tab):
"""Test that setting a small icon doesn't produce a crash.
Regression test for #1015.
@ -69,7 +69,7 @@ class TestTabWidget:
# Size taken from issue report
pixmap = QPixmap(72, 1)
icon = QIcon(pixmap)
tab = stubs.FakeWebTab()
tab = fake_web_tab()
widget.addTab(tab, icon, 'foobar')
widget.show()
qtbot.waitForWindowShown(widget)