From 1380fef600fd70f35677567e4bec7c6e42f99013 Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Sat, 24 Mar 2018 21:08:55 +0000 Subject: [PATCH] Add test for parsing multiple lines --- tests/unit/browser/test_adblock.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/browser/test_adblock.py b/tests/unit/browser/test_adblock.py index d6ebb3877..573ac3ad8 100644 --- a/tests/unit/browser/test_adblock.py +++ b/tests/unit/browser/test_adblock.py @@ -94,6 +94,7 @@ def create_blocklist(directory, blocked_hosts=BLOCKLIST_HOSTS, name: name to give to the blocklist file line_format: 'etc_hosts' --> /etc/hosts format 'one_per_line' --> one host per line format + 'all_on_one_line' --> pathological example with one line 'not_correct' --> Not a correct hosts file format. """ blocklist_file = directory / name @@ -106,6 +107,8 @@ def create_blocklist(directory, blocked_hosts=BLOCKLIST_HOSTS, elif line_format == 'one_per_line': for host in blocked_hosts: blocklist.write(host + '\n') + elif line_format == 'all_on_one_line': + blocklist.write('127.0.0.1 ' + ' '.join(blocked_hosts) + '\n') elif line_format == 'not_correct': for host in blocked_hosts: blocklist.write(host + ' This is not a correct hosts file\n') @@ -247,6 +250,15 @@ def test_successful_update(config_stub, basedir, download_stub, assert_urls(host_blocker, whitelisted=[]) +def test_parsing_multiple_hosts_on_line(config_stub, basedir, download_stub, + data_tmpdir, tmpdir, win_registry, caplog): + """Ensure multiple hosts on a line get parsed correctly""" + host_blocker = adblock.HostBlocker() + bytes_host_line = ' '.join(BLOCKLIST_HOSTS).encode('utf-8') + host_blocker._parse_line(bytes_host_line) + assert_urls(host_blocker, whitelisted=[]) + + def test_failed_dl_update(config_stub, basedir, download_stub, data_tmpdir, tmpdir, win_registry, caplog): """One blocklist fails to download.