Move cookiejar_and_cache fixture to conftest.py.

This commit is contained in:
Florian Bruhin 2015-08-30 23:11:23 +02:00
parent 8913c1883e
commit 6df00f8266
3 changed files with 41 additions and 23 deletions

View File

@ -36,6 +36,8 @@ from helpers.messagemock import message_mock
from qutebrowser.config import config
from qutebrowser.utils import objreg
from PyQt5.QtNetwork import QNetworkCookieJar
def pytest_collection_modifyitems(items):
"""Automatically add a 'gui' marker to all gui-related tests.
@ -269,3 +271,15 @@ def fake_keyevent_factory():
return evtmock
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')

View File

@ -24,12 +24,37 @@
from unittest import mock
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 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:
"""Fake QKeyPressEvent stub."""

View File

@ -33,28 +33,7 @@ from qutebrowser.keyinput import modeman
ObjectsRet = collections.namedtuple('Dispatcher', ['tb', 'cd'])
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
pytestmark = pytest.mark.usefixtures('cookiejar_and_cache')
@pytest.yield_fixture(autouse=True)