summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorÁrni Dagur <arni@dagur.eu>2020-09-22 05:20:17 +0000
committerÁrni Dagur <arni@dagur.eu>2020-09-22 05:20:17 +0000
commitb2805edbffb8f8c09558338244e93bde74e3ec77 (patch)
treec0c6c4edf03d8a5ae93e757a58b8e50570e0e961 /tests
parent04678357e0d95ba1569e65b7fc423c17f867a87f (diff)
Avoid using star import in __init__.py
Diffstat (limited to 'tests')
-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)