Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test importing all submodules of scikit-decide #436

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions tests/test_import_all_submodules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2022 AIRBUS and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import importlib
import logging
import pkgutil

logger = logging.getLogger(__name__)


def find_abs_modules(package, include_private=False):
"""Find names of all submodules in the package."""
path_list = []
for modinfo in pkgutil.walk_packages(package.__path__, f"{package.__name__}."):
if not modinfo.ispkg:
if include_private or not (
modinfo.name.split(".")[-1].startswith("_")
): # skip module names with leading _
path_list.append(modinfo.name)
return path_list


def try_importing_all_submodules(package):
modules_with_errors = []
for m in find_abs_modules(package):
try:
importlib.import_module(m)
except Exception as e:
modules_with_errors.append(m)
print(f"{m}: {e.__class__.__name__}: {e}")
if len(modules_with_errors) > 0:
raise ImportError(
f"{len(modules_with_errors)} submodules of {package.__name__} cannot be imported\n"
+ f"{modules_with_errors}"
)


def test_importing_all_submodules():
import skdecide

try_importing_all_submodules(skdecide)


if __name__ == "__main__":
test_importing_all_submodules()