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 missing attributes for python package #363

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions python/edm4hep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
26 changes: 26 additions & 0 deletions test/test_module.py
Original file line number Diff line number Diff line change
@@ -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)
Loading