From c4cca4755eff3d77a2beada0d0cc67b706086088 Mon Sep 17 00:00:00 2001 From: zaowen Date: Wed, 5 Sep 2018 20:55:22 -0500 Subject: [PATCH] Add adblock import directory unit test --- qutebrowser/browser/adblock.py | 1 - tests/unit/browser/test_adblock.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/adblock.py b/qutebrowser/browser/adblock.py index fc7de9e37..2673fced8 100644 --- a/qutebrowser/browser/adblock.py +++ b/qutebrowser/browser/adblock.py @@ -178,7 +178,6 @@ class HostBlocker: for filenames in os.scandir(filename): if not filenames.name.startswith('.')\ and filenames.is_file(): - print( filenames.name ) self._import_local(filenames.path) else: self._import_local(filename) diff --git a/tests/unit/browser/test_adblock.py b/tests/unit/browser/test_adblock.py index ec43aa772..afb556559 100644 --- a/tests/unit/browser/test_adblock.py +++ b/tests/unit/browser/test_adblock.py @@ -433,3 +433,22 @@ def test_config_change(config_stub, basedir, download_stub, host_blocker.read_hosts() for str_url in URLS_TO_CHECK: assert not host_blocker.is_blocked(QUrl(str_url)) + + +def test_add_directory(config_stub, basedir, download_stub, + data_tmpdir, tmpdir): + """Ensure adblocker can import all files in a directory.""" + blocklist_hosts2 = [] + for i in BLOCKLIST_HOSTS[1:]: + blocklist_hosts2.append('1' + i) + + create_blocklist(tmpdir, blocked_hosts=BLOCKLIST_HOSTS, + name='blocked-hosts', line_format='one_per_line') + create_blocklist(tmpdir, blocked_hosts=blocklist_hosts2, + name='blocked-hosts2', line_format='one_per_line') + + config_stub.val.content.host_blocking.lists = [tmpdir.strpath] + config_stub.val.content.host_blocking.enabled = True + host_blocker = adblock.HostBlocker() + host_blocker.adblock_update() + assert len(host_blocker._blocked_hosts) == (len(blocklist_hosts2) * 2)