File: test_public_api.py

package info (click to toggle)
fenics-dolfinx 1%3A0.9.0-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,376 kB
  • sloc: cpp: 33,701; python: 22,338; makefile: 230; sh: 170; xml: 55
file content (37 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright (C) 2022 Nathan Sime
#
# This file is part of DOLFINx (https://www.fenicsproject.org)
#
# SPDX-License-Identifier:    LGPL-3.0-or-later

import importlib
import pkgutil

import pytest


def collect_pkg_modules_recursive(name):
    module = importlib.import_module(name)
    submodules = list(a.name for a in pkgutil.iter_modules(module.__path__, prefix=f"{name}."))
    subpackages = list(
        a.name for a in pkgutil.iter_modules(module.__path__, prefix=f"{name}.") if a.ispkg
    )
    for subpackage in subpackages:
        pkg_submodules = collect_pkg_modules_recursive(subpackage)
        submodules.extend(pkg_submodules)
    return list(set(submodules))


@pytest.mark.skip("Test fails when using shared linking with nanobind")
def test_all_implemented():
    """flake8 does not catch its warning code F822: whether the public API
    offered by the members of __all__ are implemented. We therefore manually
    check.

    """
    module_names = collect_pkg_modules_recursive("dolfinx")
    for module_name in module_names:
        module = importlib.import_module(module_name)
        if hasattr(module, "__all__"):
            for member in module.__all__:
                assert hasattr(module, member)