Use existing tabbed_browser_stubs fixture in tests

This commit is contained in:
Florian Bruhin 2017-10-04 06:30:39 +02:00
parent 8c660d1bf4
commit 7cbb2b079f
5 changed files with 27 additions and 54 deletions

View File

@ -66,18 +66,11 @@ def objects():
return Objects(signal_filter=signal_filter, signaller=signaller)
@pytest.fixture
def tabbed_browser(stubs, win_registry):
tb = stubs.TabbedBrowserStub()
objreg.register('tabbed-browser', tb, scope='window', window=0)
yield tb
objreg.delete('tabbed-browser', scope='window', window=0)
@pytest.mark.parametrize('index_of, emitted', [(0, True), (1, False)])
def test_filtering(objects, tabbed_browser, index_of, emitted):
tabbed_browser.current_index = 0
tabbed_browser.index_of = index_of
def test_filtering(objects, tabbed_browser_stubs, index_of, emitted):
browser = tabbed_browser_stubs[0]
browser.current_index = 0
browser.index_of = index_of
objects.signaller.signal.emit('foo')
if emitted:
assert objects.signaller.filtered_signal_arg == 'foo'
@ -86,9 +79,10 @@ def test_filtering(objects, tabbed_browser, index_of, emitted):
@pytest.mark.parametrize('index_of, verb', [(0, 'emitting'), (1, 'ignoring')])
def test_logging(caplog, objects, tabbed_browser, index_of, verb):
tabbed_browser.current_index = 0
tabbed_browser.index_of = index_of
def test_logging(caplog, objects, tabbed_browser_stubs, index_of, verb):
browser = tabbed_browser_stubs[0]
browser.current_index = 0
browser.index_of = index_of
with caplog.at_level(logging.DEBUG, logger='signals'):
objects.signaller.signal.emit('foo')
@ -99,9 +93,10 @@ def test_logging(caplog, objects, tabbed_browser, index_of, verb):
@pytest.mark.parametrize('index_of', [0, 1])
def test_no_logging(caplog, objects, tabbed_browser, index_of):
tabbed_browser.current_index = 0
tabbed_browser.index_of = index_of
def test_no_logging(caplog, objects, tabbed_browser_stubs, index_of):
browser = tabbed_browser_stubs[0]
browser.current_index = 0
browser.index_of = index_of
with caplog.at_level(logging.DEBUG, logger='signals'):
objects.signaller.link_hovered.emit('foo')
@ -109,9 +104,10 @@ def test_no_logging(caplog, objects, tabbed_browser, index_of):
assert not caplog.records
def test_runtime_error(objects, tabbed_browser):
def test_runtime_error(objects, tabbed_browser_stubs):
"""Test that there's no crash if indexOf() raises RuntimeError."""
tabbed_browser.current_index = 0
tabbed_browser.index_of = RuntimeError
browser = tabbed_browser_stubs[0]
browser.current_index = 0
browser.index_of = RuntimeError
objects.signaller.signal.emit('foo')
assert objects.signaller.filtered_signal_arg is None

View File

@ -37,13 +37,6 @@ class TestArgumentParser:
def parser(self):
return argparser.ArgumentParser('foo')
@pytest.fixture
def tabbed_browser(self, stubs, win_registry):
tb = stubs.TabbedBrowserStub()
objreg.register('tabbed-browser', tb, scope='window', window=0)
yield tb
objreg.delete('tabbed-browser', scope='window', window=0)
def test_name(self, parser):
assert parser.name == 'foo'
@ -60,14 +53,14 @@ class TestArgumentParser:
match="Unrecognized arguments: --foo"):
parser.parse_args(['--foo'])
def test_help(self, parser, tabbed_browser):
def test_help(self, parser, tabbed_browser_stubs):
parser.add_argument('--help', action=argparser.HelpAction, nargs=0)
with pytest.raises(argparser.ArgumentParserExit):
parser.parse_args(['--help'])
expected_url = QUrl('qute://help/commands.html#foo')
assert tabbed_browser.opened_url == expected_url
assert tabbed_browser_stubs[1].opened_url == expected_url
@pytest.mark.parametrize('types, value, expected', [

View File

@ -38,19 +38,12 @@ class TestSet:
"""Tests for :set."""
@pytest.fixture
def tabbed_browser(self, qapp, stubs, win_registry):
tb = stubs.TabbedBrowserStub()
objreg.register('tabbed-browser', tb, scope='window', window=0)
yield tb
objreg.delete('tabbed-browser', scope='window', window=0)
def test_set_no_args(self, commands, tabbed_browser):
def test_set_no_args(self, commands, tabbed_browser_stubs):
"""Run ':set'.
Should open qute://settings."""
commands.set(win_id=0)
assert tabbed_browser.opened_url == QUrl('qute://settings')
assert tabbed_browser_stubs[0].opened_url == QUrl('qute://settings')
def test_get(self, config_stub, commands, message_mock):
"""Run ':set url.auto_search?'.

View File

@ -37,12 +37,12 @@ def backforward_widget(qtbot):
(False, True, '[>]'),
(True, True, '[<>]'),
])
def test_backforward_widget(backforward_widget, stubs,
def test_backforward_widget(backforward_widget, tabbed_browser_stubs,
fake_web_tab, can_go_back, can_go_forward,
expected_text):
"""Ensure the Backforward widget shows the correct text."""
tab = fake_web_tab(can_go_back=can_go_back, can_go_forward=can_go_forward)
tabbed_browser = stubs.TabbedBrowserStub()
tabbed_browser = tabbed_browser_stubs[0]
tabbed_browser.current_index = 1
tabbed_browser.tabs = [tab]
backforward_widget.on_tab_cur_url_changed(tabbed_browser)
@ -58,10 +58,10 @@ def test_backforward_widget(backforward_widget, stubs,
assert not backforward_widget.isVisible()
def test_none_tab(backforward_widget, stubs, fake_web_tab):
def test_none_tab(backforward_widget, tabbed_browser_stubs, fake_web_tab):
"""Make sure nothing crashes when passing None as tab."""
tab = fake_web_tab(can_go_back=True, can_go_forward=True)
tabbed_browser = stubs.TabbedBrowserStub()
tabbed_browser = tabbed_browser_stubs[0]
tabbed_browser.current_index = 1
tabbed_browser.tabs = [tab]
backforward_widget.on_tab_cur_url_changed(tabbed_browser)

View File

@ -138,20 +138,12 @@ class FakeMainWindow(QObject):
@pytest.fixture
def fake_window(win_registry, stubs, monkeypatch, qtbot):
def fake_window(tabbed_browser_stubs):
"""Fixture which provides a fake main windows with a tabbedbrowser."""
win0 = FakeMainWindow(b'fake-geometry-0', win_id=0)
objreg.register('main-window', win0, scope='window', window=0)
webview = QWebView()
qtbot.add_widget(webview)
browser = stubs.TabbedBrowserStub([webview])
objreg.register('tabbed-browser', browser, scope='window', window=0)
yield
objreg.delete('main-window', scope='window', window=0)
objreg.delete('tabbed-browser', scope='window', window=0)
class TestSaveAll:
@ -192,13 +184,12 @@ class TestSave:
return state
@pytest.fixture
def fake_history(self, win_registry, stubs, monkeypatch, webview):
def fake_history(self, stubs, tabbed_browser_stubs, monkeypatch, webview):
"""Fixture which provides a window with a fake history."""
win = FakeMainWindow(b'fake-geometry-0', win_id=0)
objreg.register('main-window', win, scope='window', window=0)
browser = stubs.TabbedBrowserStub([webview])
objreg.register('tabbed-browser', browser, scope='window', window=0)
browser = tabbed_browser_stubs[0]
qapp = stubs.FakeQApplication(active_window=win)
monkeypatch.setattr(sessions, 'QApplication', qapp)