summaryrefslogtreecommitdiff
path: root/tests/test_imports.py
blob: 7692483d5189694fe8bd1747b983b7cdb81915a9 (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
import re
import adblock


def get_added_classes():
    """
    Try to get the names of all classes that we added to the Python module
    from Rust. As always, we unfortunately don't have access to the Rust AST
    so we have to make do with regular expressions.
    """
    classes = []
    with open("src/lib.rs", "r", encoding="utf-8") as rs_f:
        for line in rs_f:
            match = re.match(r"m\.add_class::<(.+)>\(\)\?;", line.strip())
            if match is not None:
                classes.append(match.group(1))
    return classes


def test_added_classes():
    """
    Make sure that there's no class that we added in Rust but didn't import in
    `__init__.py` and vice versa.
    """
    added_classes = get_added_classes()
    assert added_classes == list(adblock.__all__)


def test_dunder_all_classes_imported():
    """
    Make sure that there's no class in `__all__` that we haven't imported.
    """
    for c in adblock.__all__:
        assert hasattr(adblock, c)