Add adblock benchmark
This commit is contained in:
parent
08278138c4
commit
27d4796c2f
53378
tests/end2end/data/blocked-hosts
Normal file
53378
tests/end2end/data/blocked-hosts
Normal file
File diff suppressed because it is too large
Load Diff
@ -22,13 +22,16 @@ import os
|
|||||||
import os.path
|
import os.path
|
||||||
import zipfile
|
import zipfile
|
||||||
import logging
|
import logging
|
||||||
|
import shutil
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
|
|
||||||
from qutebrowser.browser import adblock
|
from qutebrowser.browser import adblock
|
||||||
from qutebrowser.utils import urlmatch
|
from qutebrowser.utils import urlmatch, standarddir
|
||||||
|
from tests.helpers import utils
|
||||||
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('qapp', 'config_tmpdir')
|
pytestmark = pytest.mark.usefixtures('qapp', 'config_tmpdir')
|
||||||
|
|
||||||
@ -471,3 +474,15 @@ def test_add_directory(config_stub, basedir, download_stub,
|
|||||||
host_blocker = adblock.HostBlocker()
|
host_blocker = adblock.HostBlocker()
|
||||||
host_blocker.adblock_update()
|
host_blocker.adblock_update()
|
||||||
assert len(host_blocker._blocked_hosts) == len(blocklist_hosts2) * 2
|
assert len(host_blocker._blocked_hosts) == len(blocklist_hosts2) * 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_adblock_benchmark(config_stub, data_tmpdir, basedir, benchmark):
|
||||||
|
blocked_hosts = os.path.join(utils.abs_datapath(), 'blocked-hosts')
|
||||||
|
shutil.copy(blocked_hosts, str(data_tmpdir))
|
||||||
|
|
||||||
|
url = QUrl('https://www.example.org/')
|
||||||
|
blocker = adblock.HostBlocker()
|
||||||
|
blocker.read_hosts()
|
||||||
|
assert blocker._blocked_hosts
|
||||||
|
|
||||||
|
benchmark(lambda: blocker.is_blocked(url))
|
||||||
|
Loading…
Reference in New Issue
Block a user