diff options
author | John L. Villalovos <john@sodarock.com> | 2022-01-16 19:06:35 -0800 |
---|---|---|
committer | John L. Villalovos <john@sodarock.com> | 2022-01-16 19:06:35 -0800 |
commit | 71899e48586076dce0da9c1ba512d5e20c30ceb0 (patch) | |
tree | 292e3590821e1a0a538b2a469ac6bcf5bce16964 | |
parent | 8af403cb2b1c48acd6e9ebd392554926835c3893 (diff) | |
download | gitlab-jlvillal/objects_imported.tar.gz |
test: add a meta test to make sure that v4/objects/ files are importedjlvillal/objects_imported
Add a test to make sure that all of the `gitlab/v4/objects/` files are
imported in `gitlab/v4/objects/__init__.py`
-rw-r--r-- | tests/meta/test_v4_objects_imported.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/meta/test_v4_objects_imported.py b/tests/meta/test_v4_objects_imported.py new file mode 100644 index 0000000..de0dec7 --- /dev/null +++ b/tests/meta/test_v4_objects_imported.py @@ -0,0 +1,34 @@ +""" +Ensure objects defined in gitlab.v4.objects are imported in +`gitlab/v4/objects/__init__.py` + +""" +import os +import pkgutil +from typing import Set + +import gitlab.v4.objects + + +def test_verify_v4_objects_imported() -> None: + assert len(gitlab.v4.objects.__path__) == 1 + v4_objects_init_file = os.path.join(gitlab.v4.objects.__path__[0], "__init__.py") + + init_files: Set[str] = set() + with open(v4_objects_init_file, "r") as in_file: + for line in in_file.readlines(): + if line.startswith("from ."): + init_files.add(line.rstrip()) + + object_files = set() + for module in pkgutil.iter_modules(gitlab.v4.objects.__path__): + object_files.add(f"from .{module.name} import *") + + missing_in_init = object_files - init_files + error_message = ( + f"\nThe file {v4_objects_init_file!r} is missing the following imports:" + ) + for missing in sorted(missing_in_init): + error_message += f"\n {missing}" + + assert not missing_in_init, error_message |