From 994e8c692f4357a5fa0529ca8fab5c1707699d5c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 20 Jun 2017 15:19:53 +0200 Subject: [PATCH] Merge different FakeTabbedBrowser objects --- tests/helpers/stubs.py | 23 +++++++++++++++++++++++ tests/unit/browser/test_signalfilter.py | 25 ++----------------------- tests/unit/commands/test_argparser.py | 13 ++----------- tests/unit/misc/test_sessions.py | 18 ++---------------- 4 files changed, 29 insertions(+), 50 deletions(-) diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index 8b2a235d3..0551f5a86 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -566,6 +566,9 @@ class TabbedBrowserStub(QObject): self.tabs = [] self.shutting_down = False self._qtabbar = QTabBar() + self.index_of = None + self.current_index = None + self.opened_url = None def count(self): return len(self.tabs) @@ -582,6 +585,26 @@ class TabbedBrowserStub(QObject): def tabBar(self): 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): diff --git a/tests/unit/browser/test_signalfilter.py b/tests/unit/browser/test_signalfilter.py index 4c02f89c4..b56e4ecc0 100644 --- a/tests/unit/browser/test_signalfilter.py +++ b/tests/unit/browser/test_signalfilter.py @@ -29,27 +29,6 @@ from qutebrowser.browser import signalfilter 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): signal = pyqtSignal(str) @@ -84,8 +63,8 @@ def objects(): @pytest.fixture -def tabbed_browser(win_registry): - tb = FakeTabbedBrowser() +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) diff --git a/tests/unit/commands/test_argparser.py b/tests/unit/commands/test_argparser.py index cf9eef016..b44fd5dce 100644 --- a/tests/unit/commands/test_argparser.py +++ b/tests/unit/commands/test_argparser.py @@ -31,15 +31,6 @@ from qutebrowser.utils import usertypes, objreg 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: @pytest.fixture @@ -47,8 +38,8 @@ class TestArgumentParser: return argparser.ArgumentParser('foo') @pytest.fixture - def tabbed_browser(self, win_registry): - tb = FakeTabbedBrowser() + 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) diff --git a/tests/unit/misc/test_sessions.py b/tests/unit/misc/test_sessions.py index 59b335f78..e77b6aa02 100644 --- a/tests/unit/misc/test_sessions.py +++ b/tests/unit/misc/test_sessions.py @@ -137,20 +137,6 @@ class FakeMainWindow(QObject): 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 def fake_window(win_registry, stubs, monkeypatch, qtbot): """Fixture which provides a fake main windows with a tabbedbrowser.""" @@ -159,7 +145,7 @@ def fake_window(win_registry, stubs, monkeypatch, qtbot): webview = QWebView() qtbot.add_widget(webview) - browser = FakeTabbedBrowser([webview]) + browser = stubs.TabbedBrowserStub([webview]) objreg.register('tabbed-browser', browser, scope='window', window=0) yield @@ -211,7 +197,7 @@ class TestSave: """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 = FakeTabbedBrowser([webview]) + browser = stubs.TabbedBrowserStub([webview]) objreg.register('tabbed-browser', browser, scope='window', window=0) qapp = stubs.FakeQApplication(active_window=win)