|
| 1 | +""" |
| 2 | +Ensure objects defined in gitlab.v4.objects are imported in |
| 3 | +`gitlab/v4/objects/__init__.py` |
| 4 | +
|
| 5 | +""" |
| 6 | +importpkgutil |
| 7 | +fromtypingimportSet |
| 8 | + |
| 9 | +importgitlab.v4.objects |
| 10 | + |
| 11 | + |
| 12 | +deftest_verify_v4_objects_imported()->None: |
| 13 | +assertlen(gitlab.v4.objects.__path__)==1 |
| 14 | + |
| 15 | +init_files:Set[str]=set() |
| 16 | +withopen(gitlab.v4.objects.__file__,"r")asin_file: |
| 17 | +forlineinin_file.readlines(): |
| 18 | +ifline.startswith("from ."): |
| 19 | +init_files.add(line.rstrip()) |
| 20 | + |
| 21 | +object_files=set() |
| 22 | +formoduleinpkgutil.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 | +formissinginsorted(missing_in_init): |
| 30 | +error_message+=f"\n{missing}" |
| 31 | + |
| 32 | +assertnotmissing_in_init,error_message |