19 """Test suite to validate that all modules inside a package can be imported
24 from importlib
import import_module
25 from pathlib
import Path
33 CONDA_BUILD_TEST = os.getenv(
"CONDA_BUILD_STATE") ==
"TEST"
36 DEFAULT_PYTEST_ARGUMENTS = [
39 "--junit-xml=junit-imports.xml",
43 HERE = Path(__file__).parent.absolute()
44 BUILDDIR = (HERE / Path(
".")).resolve()
45 SRCDIR = (HERE / Path(
".")).resolve()
46 TOPBUILDDIR = (HERE / Path(
"../..")).resolve()
49 EXCLUDEFILE = SRCDIR /
"exclude-modules.txt"
54 PYTHONMODDIR = Path(import_module(PACKAGE).__path__[0])
57 PYTHONMODDIR = TOPBUILDDIR /
"python" / PACKAGE
63 """Read all excluded file paths from the given source file
67 with open(str(source),
"r")
as fobj:
69 if isinstance(line, bytes):
70 line = line.decode(
"utf-8")
71 content = line.strip().split(
"#", 1)[0].strip()
74 except FileNotFoundError
as exc:
75 warnings.warn(str(exc))
80 """Returns the paths to all python module files
82 return {str(x.relative_to(path.parent))
for x
in path.rglob(
"*.py")}
86 """Returns the module name for a given file path
88 >>> path_to_name("lal/__init__.py")
90 >>> path_to_name("lal/module.py")
93 name = filepath.replace(
".py",
"").
replace(
r"/",
".")
94 if name.endswith(
".__init__"):
108 @pytest.mark.parametrize("module", MODULES)
110 """Test that the named module can be imported
112 if module
in EXCLUDE:
113 pytest.skip(
"excluded {}".format(str(module)))
114 import_module(module)
119 if __name__ ==
"__main__":
120 args = sys.argv[1:]
or DEFAULT_PYTEST_ARGUMENTS
121 sys.exit(pytest.main(args=[__file__] + args))
static int replace(int c, void *param)
def test_import(module)
Test that the named module can be imported.
def path_to_name(filepath)
Returns the module name for a given file path.
def read_exclude_file(source)
Read all excluded file paths from the given source file.
def find_modules(path)
Returns the paths to all python module files.