Move cookiejar_and_cache fixture to conftest.py.
This commit is contained in:
parent
8913c1883e
commit
6df00f8266
@ -36,6 +36,8 @@ from helpers.messagemock import message_mock
|
|||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.utils import objreg
|
from qutebrowser.utils import objreg
|
||||||
|
|
||||||
|
from PyQt5.QtNetwork import QNetworkCookieJar
|
||||||
|
|
||||||
|
|
||||||
def pytest_collection_modifyitems(items):
|
def pytest_collection_modifyitems(items):
|
||||||
"""Automatically add a 'gui' marker to all gui-related tests.
|
"""Automatically add a 'gui' marker to all gui-related tests.
|
||||||
@ -269,3 +271,15 @@ def fake_keyevent_factory():
|
|||||||
return evtmock
|
return evtmock
|
||||||
|
|
||||||
return fake_keyevent
|
return fake_keyevent
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.yield_fixture
|
||||||
|
def cookiejar_and_cache(stubs):
|
||||||
|
"""Fixture providing a fake cookie jar and cache."""
|
||||||
|
jar = QNetworkCookieJar()
|
||||||
|
cache = stubs.FakeNetworkCache()
|
||||||
|
objreg.register('cookie-jar', jar)
|
||||||
|
objreg.register('cache', cache)
|
||||||
|
yield
|
||||||
|
objreg.delete('cookie-jar')
|
||||||
|
objreg.delete('cache')
|
||||||
|
@ -24,12 +24,37 @@
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
|
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
|
||||||
from PyQt5.QtNetwork import QNetworkRequest
|
from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
|
||||||
|
QNetworkCacheMetaData)
|
||||||
from PyQt5.QtWidgets import QCommonStyle
|
from PyQt5.QtWidgets import QCommonStyle
|
||||||
|
|
||||||
from qutebrowser.config import configexc
|
from qutebrowser.config import configexc
|
||||||
|
|
||||||
|
|
||||||
|
class FakeNetworkCache(QAbstractNetworkCache):
|
||||||
|
|
||||||
|
def cacheSize(self):
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def data(self, _url):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def insert(self, _dev):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def metaData(self, _url):
|
||||||
|
return QNetworkCacheMetaData()
|
||||||
|
|
||||||
|
def prepare(self, _metadata):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def remove(self, _url):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def updateMetaData(self, _url):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FakeKeyEvent:
|
class FakeKeyEvent:
|
||||||
|
|
||||||
"""Fake QKeyPressEvent stub."""
|
"""Fake QKeyPressEvent stub."""
|
||||||
|
@ -33,28 +33,7 @@ from qutebrowser.keyinput import modeman
|
|||||||
|
|
||||||
ObjectsRet = collections.namedtuple('Dispatcher', ['tb', 'cd'])
|
ObjectsRet = collections.namedtuple('Dispatcher', ['tb', 'cd'])
|
||||||
|
|
||||||
class FakeNetworkCache(QAbstractNetworkCache):
|
pytestmark = pytest.mark.usefixtures('cookiejar_and_cache')
|
||||||
|
|
||||||
def cacheSize(self):
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def data(self, _url):
|
|
||||||
return None
|
|
||||||
|
|
||||||
def insert(self, _dev):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def metaData(self, _url):
|
|
||||||
return QNetworkCacheMetaData()
|
|
||||||
|
|
||||||
def prepare(self, _metadata):
|
|
||||||
return None
|
|
||||||
|
|
||||||
def remove(self, _url):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def updateMetaData(self, _url):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture(autouse=True)
|
@pytest.yield_fixture(autouse=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user