From 25684535e85a8bbb05b65b0da2304273d1d90ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81rni=20Dagur?= Date: Mon, 27 Jul 2020 20:35:50 +0000 Subject: Update upstream library to 0.3.0, respond to API changes (#10) * Update upstream library to 0.3.0, respond to API changes * Change pypi publishing criteria in CI * Create test to make sure the version numbers are the same everywhere --- tests/test_engine.py | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'tests/test_engine.py') diff --git a/tests/test_engine.py b/tests/test_engine.py index 28e25e6..a3d2898 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -1,40 +1,62 @@ import adblock import pytest +SMALL_FILTER_LIST = """ +||wikipedia.org^ +||old.reddit.com^ +||lobste.rs^ +""" -def test_engine_arguments(): - # None of these should panic - adblock.Engine() - adblock.Engine([]) - adblock.Engine(network_filters=None) - adblock.Engine(network_filters=[]) - adblock.Engine(load_network=False, load_cosmetic=True, debug=False) - adblock.Engine(debug=True) + +def empty_engine(): + return adblock.Engine(adblock.FilterSet()) + + +def test_engine_creation_and_blocking(): + filter_set = adblock.FilterSet(debug=True) + filter_set.add_filter_list(SMALL_FILTER_LIST) + engine = adblock.Engine(filter_set=filter_set) + + blocker_result_wikipedia = engine.check_network_urls( + url="https://wikipedia.org/img.png", + source_url="https://google.com/", + request_type="image", + ) + assert isinstance(blocker_result_wikipedia, adblock.BlockerResult) + assert blocker_result_wikipedia.matched + + blocker_result_facebook = engine.check_network_urls( + "https://facebook.com/directory/img.png", + "https://old.reddit.com/r/all", + "image", + ) + assert isinstance(blocker_result_facebook, adblock.BlockerResult) + assert not blocker_result_facebook.matched def test_serde_file(tmpdir): path = str(tmpdir / "cache.dat") - engine0 = adblock.Engine() + engine0 = empty_engine() with pytest.raises(FileNotFoundError): # We haven't created the cache.dat file, so we should get an exception # when attempting to deserialize. engine0.deserialize_from_file(path) - engine1 = adblock.Engine() + engine1 = empty_engine() serialization_result = engine1.serialize_to_file(path) assert serialization_result is None - engine2 = adblock.Engine() + engine2 = empty_engine() deserialization_result = engine2.deserialize_from_file(path) assert deserialization_result is None def test_serde(): - engine = adblock.Engine() + engine = empty_engine() serialization_result = engine.serialize() assert isinstance(serialization_result, bytes) - engine2 = adblock.Engine() + engine2 = empty_engine() deserialization_result = engine2.deserialize(serialization_result) assert deserialization_result is None -- cgit v1.2.3