Skip to content

Commit

Permalink
Add a test importing all submodules of scikit-decide
Browse files Browse the repository at this point in the history
  • Loading branch information
nhuet committed Oct 22, 2024
1 parent 88cce97 commit e491028
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/test_import_all_submodules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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):
"""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:
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()

0 comments on commit e491028

Please sign in to comment.