Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: tests/test_filters_blocks.py

Issue 30053555: Issue 7471 - Add an API for working with blocks of filters (Closed) Base URL: https://hg.adblockplus.org/python-abp
Patch Set: Adjust the API in response to review comments Created May 9, 2019, 4:22 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/data/filterlist.txt ('k') | tests/test_rpy.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_filters_blocks.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_filters_blocks.py
@@ -0,0 +1,60 @@
+# This file is part of Adblock Plus <https://adblockplus.org/>,
+# Copyright (C) 2006-present eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+"""Tests for abp.filters.blocks."""
+
+from __future__ import unicode_literals
+
+import json
+import os
+
+import pytest
+
+from abp.filters import parse_filterlist, SelectorType, FilterAction
+from abp.filters.blocks import to_blocks
+
+DATA_PATH = os.path.join(os.path.dirname(__file__), 'data')
+
+
+@pytest.fixture()
+def fl_lines():
+ with open(os.path.join(DATA_PATH, 'filterlist.txt')) as f:
+ return list(parse_filterlist(f))
+
+
+@pytest.fixture()
+def expected_blocks():
+ with open(os.path.join(DATA_PATH, 'expected_blocks.json')) as f:
+ return json.load(f)
+
+
+def test_to_blocks(fl_lines):
+ blocks = list(to_blocks(fl_lines))
+ assert len(blocks) == 2
+ block = blocks[0]
+ assert block.variables['foo'] == 'bar'
+ assert block.variables['baz'] == ('some_tricky?variable=with&funny=chars#'
+ 'and-stuff')
+ assert block.description == 'Example block 1\nAnother comment'
+ # Don't test the filters thouroughly: filter parsing is tested elsewhere.
+ assert len(block.filters) == 2
+ assert block.filters[0].selector['type'] == SelectorType.URL_PATTERN
+ assert block.filters[1].action == FilterAction.SHOW
+
+
+def test_to_dict(fl_lines, expected_blocks):
+ blocks = [b.to_dict() for b in to_blocks(fl_lines)]
+ print(json.dumps(blocks, indent=2))
+ assert blocks == expected_blocks
« no previous file with comments | « tests/data/filterlist.txt ('k') | tests/test_rpy.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld