Prevent test_adblock from creating real config dir.
Don't create ~/.config/qute_test by mocking out standdarddir.config for all tests in this module. This adds config_tmpdir to fixtures.py and moves temp_datadir from test_adblock to fixtures.py as it will be needed more broadly.
This commit is contained in:
parent
9c9b367887
commit
a6695ea1be
@ -30,6 +30,7 @@ import itertools
|
||||
import textwrap
|
||||
import unittest.mock
|
||||
import types
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
@ -405,3 +406,29 @@ def mode_manager(win_registry, config_stub, qapp):
|
||||
objreg.register('mode-manager', mm, scope='window', window=0)
|
||||
yield mm
|
||||
objreg.delete('mode-manager', scope='window', window=0)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_tmpdir(monkeypatch, tmpdir):
|
||||
"""Set tmpdir/config as the configdir.
|
||||
|
||||
Use this to avoid creating a 'real' config dir (~/.config/qute_test).
|
||||
"""
|
||||
tmpdir = tmpdir / 'config'
|
||||
path = str(tmpdir)
|
||||
os.mkdir(path)
|
||||
monkeypatch.setattr('qutebrowser.utils.standarddir.config', lambda: path)
|
||||
return tmpdir
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def data_tmpdir(monkeypatch, tmpdir):
|
||||
"""Set tmpdir/data as the datadir.
|
||||
|
||||
Use this to avoid creating a 'real' data dir (~/.local/share/qute_test).
|
||||
"""
|
||||
tmpdir = tmpdir / 'data'
|
||||
path = str(tmpdir)
|
||||
os.mkdir(path)
|
||||
monkeypatch.setattr('qutebrowser.utils.standarddir.data', lambda: path)
|
||||
return tmpdir
|
||||
|
@ -30,7 +30,7 @@ from qutebrowser.browser import adblock
|
||||
from qutebrowser.utils import objreg
|
||||
from qutebrowser.commands import cmdexc
|
||||
|
||||
pytestmark = pytest.mark.usefixtures('qapp')
|
||||
pytestmark = pytest.mark.usefixtures('qapp', 'config_tmpdir')
|
||||
|
||||
# TODO See ../utils/test_standarddirutils for OSError and caplog assertion
|
||||
|
||||
@ -54,13 +54,6 @@ URLS_TO_CHECK = ('http://localhost',
|
||||
'http://qutebrowser.org')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def data_tmpdir(monkeypatch, tmpdir):
|
||||
"""Set tmpdir as datadir."""
|
||||
tmpdir = str(tmpdir)
|
||||
monkeypatch.setattr('qutebrowser.utils.standarddir.data', lambda: tmpdir)
|
||||
|
||||
|
||||
class BaseDirStub:
|
||||
|
||||
"""Mock for objreg.get('args') called in adblock.HostBlocker.read_hosts."""
|
||||
@ -348,7 +341,7 @@ def test_blocking_with_whitelist(config_stub, basedir, download_stub,
|
||||
# by creating a file named blocked-hosts,
|
||||
# Exclude localhost from it, since localhost is in HostBlocker.WHITELISTED
|
||||
filtered_blocked_hosts = BLOCKLIST_HOSTS[1:]
|
||||
blocklist = create_blocklist(tmpdir,
|
||||
blocklist = create_blocklist(data_tmpdir,
|
||||
blocked_hosts=filtered_blocked_hosts,
|
||||
name='blocked-hosts',
|
||||
line_format='one_per_line')
|
||||
|
Loading…
Reference in New Issue
Block a user