diff --git a/python/edm4hep/__init__.py b/python/edm4hep/__init__.py index a5cef54e4..1cf2df10d 100644 --- a/python/edm4hep/__init__.py +++ b/python/edm4hep/__init__.py @@ -27,5 +27,12 @@ # Make TAB completion work for utils setattr(edm4hep, 'utils', edm4hep.utils) +# set package attributes for edm4hep +edm4hep.__version__ = __version__ +edm4hep.__name__ = __name__ +edm4hep.__spec__ = __spec__ +edm4hep.__path__ = __path__ +edm4hep.__file__ = __file__ + # Make `import edm4hep` work sys.modules['edm4hep'] = edm4hep diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 264780c36..f402792fe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -117,5 +117,12 @@ if(HepMC3_FOUND AND HepPDT_FOUND ) ) endif() +add_test(NAME py_test_module COMMAND python ${CMAKE_CURRENT_LIST_DIR}/test_module.py) +set_test_env(py_test_module) +set_property(TEST py_test_module APPEND PROPERTY ENVIRONMENT + ${ENVIRONMENT} + PYTHONPATH=${PROJECT_SOURCE_DIR}/python:$ENV{PYTHONPATH} +) + add_subdirectory(utils) add_subdirectory(tools) diff --git a/test/test_module.py b/test/test_module.py new file mode 100644 index 000000000..0ff4724c5 --- /dev/null +++ b/test/test_module.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +"""Check the attributes of edm4hep package""" + +import edm4hep +from ROOT import gInterpreter +from importlib.util import find_spec + +if gInterpreter.LoadFile("edm4hep/EDM4hepVersion.h") != 0: + raise ImportError("Error while loading file edm4hep/EDM4hepVersion.h") + +# __version__ +version = edm4hep.version.build_version +assert edm4hep.__version__ == f"{version.major}.{version.minor}.{version.patch}" + +# import attributes +name = "edm4hep" +expected_spec = find_spec(name) +assert edm4hep.__name__ == name +assert edm4hep.__name__ == expected_spec.name +assert edm4hep.__spec__ == expected_spec +assert edm4hep.__path__ == expected_spec.submodule_search_locations +assert edm4hep.__file__ == expected_spec.origin + +# utils +assert "utils" in dir(edm4hep)