8000 test: add a meta test to make sure that v4/objects/ files are imported · python-gitlab/python-gitlab@9c8c804 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c8c804

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 8dfed0c commit 9c8c804

File tree

1 file changed

+32
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)
0