Fix HostBlocker.on_config_changed with no datadir

This commit is contained in:
Florian Bruhin 2016-05-07 23:35:30 +02:00
parent 6d1764e732
commit 4403f02ac5
2 changed files with 5 additions and 2 deletions

View File

@ -116,7 +116,7 @@ class HostBlocker:
self._local_hosts_file = None
else:
self._local_hosts_file = os.path.join(data_dir, 'blocked-hosts')
self.on_config_changed()
self.on_config_changed()
config_dir = standarddir.config()
if config_dir is None:
@ -274,7 +274,7 @@ class HostBlocker:
def on_config_changed(self):
"""Update files when the config changed."""
urls = config.get('content', 'host-block-lists')
if urls is None:
if urls is None and self._local_hosts_file is not None:
try:
os.remove(self._local_hosts_file)
except FileNotFoundError:

View File

@ -258,6 +258,9 @@ def test_without_datadir(config_stub, tmpdir, monkeypatch, win_registry):
for str_url in URLS_TO_CHECK:
assert not host_blocker.is_blocked(QUrl(str_url))
# To test on_config_changed
config_stub.set('content', 'host-block-lists', None)
def test_disabled_blocking_update(basedir, config_stub, download_stub,
data_tmpdir, tmpdir, win_registry):