diff --git a/abp_blocklist_parser/BlockListParser.py b/abp_blocklist_parser/BlockListParser.py index fc16892..6ec4951 100644 --- a/abp_blocklist_parser/BlockListParser.py +++ b/abp_blocklist_parser/BlockListParser.py @@ -35,6 +35,9 @@ def __init__(self, regex_file=None, regexes=None, shortcut_sizes=None, all_shortcut_url_maps) self.remaining_regex = self._convert_to_regex(remaining_lines) + def __repr__(self): + return f"BlockListParser with {len(self.regex_lines)} entries" + def get_num_classes(self): # always supports only binary classification, blocked or not blocked return 2 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..62e32f2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +# This file only contains development requirements the final library is freestanding +pytest +requests \ No newline at end of file diff --git a/setup.py b/setup.py index 8f1a3e9..a4d3e0a 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ name='abp-blocklist-parser', license='GPL v3', url='https://github.com/englehardt/abp-blocklist-parser', - version='0.2', + version='0.3', packages=['abp_blocklist_parser'], # Dependencies diff --git a/test/test_blp.py b/test/test_blp.py new file mode 100644 index 0000000..e7bd4ba --- /dev/null +++ b/test/test_blp.py @@ -0,0 +1,33 @@ +from abp_blocklist_parser.BlockListParser import BlockListParser +import requests +import pytest + + + +@pytest.fixture(scope="module") +def block_list_parser(): + # Download blocklists + raw_lists = { + 'nocoin': 'https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/nocoin.txt', + 'ublock-resource-abuse': 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt' + } + # Initialize parsers + blockers = [ + BlockListParser(regexes=requests.get(raw_lists["nocoin"]).content.decode()), + BlockListParser(regexes=requests.get(raw_lists["ublock-resource-abuse"]).content.decode()) + ] + return blockers[0] + + +def test_should_block(block_list_parser: BlockListParser) -> None: + should_block_my_domain = block_list_parser.should_block("https://zabka.it") + assert not should_block_my_domain + +def test_should_block_and_print(block_list_parser: BlockListParser)-> None: + should_block_my_domain = block_list_parser.should_block_and_print("https://zabka.it") + assert not should_block_my_domain + +def test_should_block_with_items(block_list_parser: BlockListParser)-> None: + should_block_my_domain = block_list_parser.should_block_with_items("https://zabka.it") + assert not should_block_my_domain +