summaryrefslogtreecommitdiff
path: root/tests/test_engine.py
blob: 28e25e6fcb2aef17bf4c4ad2de5acc3c1c51ea9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import adblock
import pytest


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 test_serde_file(tmpdir):
    path = str(tmpdir / "cache.dat")

    engine0 = adblock.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()
    serialization_result = engine1.serialize_to_file(path)
    assert serialization_result is None

    engine2 = adblock.Engine()
    deserialization_result = engine2.deserialize_from_file(path)
    assert deserialization_result is None


def test_serde():
    engine = adblock.Engine()
    serialization_result = engine.serialize()
    assert isinstance(serialization_result, bytes)

    engine2 = adblock.Engine()
    deserialization_result = engine2.deserialize(serialization_result)
    assert deserialization_result is None