Merge different FakeTabbedBrowser objects

This commit is contained in:
Florian Bruhin 2017-06-20 15:19:53 +02:00
parent 096b0a7a37
commit 994e8c692f
4 changed files with 29 additions and 50 deletions

View File

@ -566,6 +566,9 @@ class TabbedBrowserStub(QObject):
self.tabs = [] self.tabs = []
self.shutting_down = False self.shutting_down = False
self._qtabbar = QTabBar() self._qtabbar = QTabBar()
self.index_of = None
self.current_index = None
self.opened_url = None
def count(self): def count(self):
return len(self.tabs) return len(self.tabs)
@ -582,6 +585,26 @@ class TabbedBrowserStub(QObject):
def tabBar(self): def tabBar(self):
return self._qtabbar return self._qtabbar
def indexOf(self, _tab):
if self.index_of is None:
raise ValueError("indexOf got called with index_of None!")
elif self.index_of is RuntimeError:
raise RuntimeError
else:
return self.index_of
def currentIndex(self):
if self.current_index is None:
raise ValueError("currentIndex got called with current_index "
"None!")
return self.current_index
def currentWidget(self):
return self.tabs[self.currentIndex() - 1]
def tabopen(self, url):
self.opened_url = url
class ApplicationStub(QObject): class ApplicationStub(QObject):

View File

@ -29,27 +29,6 @@ from qutebrowser.browser import signalfilter
from qutebrowser.utils import objreg from qutebrowser.utils import objreg
class FakeTabbedBrowser:
def __init__(self):
self.index_of = None
self.current_index = None
def indexOf(self, _tab):
if self.index_of is None:
raise ValueError("indexOf got called with index_of None!")
elif self.index_of is RuntimeError:
raise RuntimeError
else:
return self.index_of
def currentIndex(self):
if self.current_index is None:
raise ValueError("currentIndex got called with current_index "
"None!")
return self.current_index
class Signaller(QObject): class Signaller(QObject):
signal = pyqtSignal(str) signal = pyqtSignal(str)
@ -84,8 +63,8 @@ def objects():
@pytest.fixture @pytest.fixture
def tabbed_browser(win_registry): def tabbed_browser(stubs, win_registry):
tb = FakeTabbedBrowser() tb = stubs.TabbedBrowserStub()
objreg.register('tabbed-browser', tb, scope='window', window=0) objreg.register('tabbed-browser', tb, scope='window', window=0)
yield tb yield tb
objreg.delete('tabbed-browser', scope='window', window=0) objreg.delete('tabbed-browser', scope='window', window=0)

View File

@ -31,15 +31,6 @@ from qutebrowser.utils import usertypes, objreg
Enum = usertypes.enum('Enum', ['foo', 'foo_bar']) Enum = usertypes.enum('Enum', ['foo', 'foo_bar'])
class FakeTabbedBrowser:
def __init__(self):
self.opened_url = None
def tabopen(self, url):
self.opened_url = url
class TestArgumentParser: class TestArgumentParser:
@pytest.fixture @pytest.fixture
@ -47,8 +38,8 @@ class TestArgumentParser:
return argparser.ArgumentParser('foo') return argparser.ArgumentParser('foo')
@pytest.fixture @pytest.fixture
def tabbed_browser(self, win_registry): def tabbed_browser(self, stubs, win_registry):
tb = FakeTabbedBrowser() tb = stubs.TabbedBrowserStub()
objreg.register('tabbed-browser', tb, scope='window', window=0) objreg.register('tabbed-browser', tb, scope='window', window=0)
yield tb yield tb
objreg.delete('tabbed-browser', scope='window', window=0) objreg.delete('tabbed-browser', scope='window', window=0)

View File

@ -137,20 +137,6 @@ class FakeMainWindow(QObject):
return self._geometry return self._geometry
class FakeTabbedBrowser:
"""A fake tabbed-browser which contains some widgets."""
def __init__(self, widgets):
self._widgets = widgets
def widgets(self):
return self._widgets
def currentIndex(self):
return 1
@pytest.fixture @pytest.fixture
def fake_window(win_registry, stubs, monkeypatch, qtbot): def fake_window(win_registry, stubs, monkeypatch, qtbot):
"""Fixture which provides a fake main windows with a tabbedbrowser.""" """Fixture which provides a fake main windows with a tabbedbrowser."""
@ -159,7 +145,7 @@ def fake_window(win_registry, stubs, monkeypatch, qtbot):
webview = QWebView() webview = QWebView()
qtbot.add_widget(webview) qtbot.add_widget(webview)
browser = FakeTabbedBrowser([webview]) browser = stubs.TabbedBrowserStub([webview])
objreg.register('tabbed-browser', browser, scope='window', window=0) objreg.register('tabbed-browser', browser, scope='window', window=0)
yield yield
@ -211,7 +197,7 @@ class TestSave:
"""Fixture which provides a window with a fake history.""" """Fixture which provides a window with a fake history."""
win = FakeMainWindow(b'fake-geometry-0', win_id=0) win = FakeMainWindow(b'fake-geometry-0', win_id=0)
objreg.register('main-window', win, scope='window', window=0) objreg.register('main-window', win, scope='window', window=0)
browser = FakeTabbedBrowser([webview]) browser = stubs.TabbedBrowserStub([webview])
objreg.register('tabbed-browser', browser, scope='window', window=0) objreg.register('tabbed-browser', browser, scope='window', window=0)
qapp = stubs.FakeQApplication(active_window=win) qapp = stubs.FakeQApplication(active_window=win)