summaryrefslogtreecommitdiff
path: root/tests/test_imports.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_imports.py')
-rw-r--r--tests/test_imports.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_imports.py b/tests/test_imports.py
new file mode 100644
index 0000000..7692483
--- /dev/null
+++ b/tests/test_imports.py
@@ -0,0 +1,34 @@
1import re
2import adblock
3
4
5def get_added_classes():
6 """
7 Try to get the names of all classes that we added to the Python module
8 from Rust. As always, we unfortunately don't have access to the Rust AST
9 so we have to make do with regular expressions.
10 """
11 classes = []
12 with open("src/lib.rs", "r", encoding="utf-8") as rs_f:
13 for line in rs_f:
14 match = re.match(r"m\.add_class::<(.+)>\(\)\?;", line.strip())
15 if match is not None:
16 classes.append(match.group(1))
17 return classes
18
19
20def test_added_classes():
21 """
22 Make sure that there's no class that we added in Rust but didn't import in
23 `__init__.py` and vice versa.
24 """
25 added_classes = get_added_classes()
26 assert added_classes == list(adblock.__all__)
27
28
29def test_dunder_all_classes_imported():
30 """
31 Make sure that there's no class in `__all__` that we haven't imported.
32 """
33 for c in adblock.__all__:
34 assert hasattr(adblock, c)