Skip to content

Commit 73e2216

Browse files
test: add a meta test to make sure that v4/objects/ files are imported
Add a test to make sure that all of the `gitlab/v4/objects/` files are imported in `gitlab/v4/objects/__init__.py`
1 parent 8af403c commit 73e2216

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Ensure objects defined in gitlab.v4.objects are imported in
3+
`gitlab/v4/objects/__init__.py`
4+
5+
"""
6+
import os
7+
import pkgutil
8+
from typing import Set
9+
10+
import gitlab.v4.objects
11+
12+
13+
def test_verify_v4_objects_imported() -> None:
14+
assert len(gitlab.v4.objects.__path__) == 1
15+
v4_objects_init_file = os.path.join(gitlab.v4.objects.__path__[0], "__init__.py")
16+
17+
init_files: Set[str] = set()
18+
with open(v4_objects_init_file, "r") as in_file:
19+
for line in in_file.readlines():
20+
if line.startswith("from ."):
21+
init_files.add(line.rstrip())
22+
23+
object_files = set()
24+
for module in pkgutil.iter_modules(gitlab.v4.objects.__path__):
25+
object_files.add(f"from .{module.name} import *")
26+
27+
missing_in_init = object_files - init_files
28+
error_message = (
29+
f"\nThe file {v4_objects_init_file!r} is missing the following imports"
30+
)
31+
for missing in sorted(missing_in_init):
32+
error_message += f"\n {missing}"
33+
34+
assert not missing_in_init, error_message

0 commit comments

Comments
 (0)