Skip to content
Snippets Groups Projects
Commit c4f7c335 authored by Marko Petric's avatar Marko Petric
Browse files

Add import test for dd4hep python modules

parent 42debfe3
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,10 @@ foreach(TEST_NAME
set_tests_properties(t_${TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED")
endforeach()
ADD_TEST( t_test_python_import "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh"
pytest ${PROJECT_SOURCE_DIR}/DDTest/python/test_import.py)
SET_TESTS_PROPERTIES( t_test_python_import PROPERTIES FAIL_REGULAR_EXPRESSION "Exception;EXCEPTION;ERROR;Error" )
if (DD4HEP_USE_GEANT4)
foreach(TEST_NAME
test_EventReaders
......@@ -58,10 +62,10 @@ if (DD4HEP_USE_GEANT4)
set_tests_properties(t_${TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED")
endforeach(TEST_NAME)
ADD_TEST( test_ddsim "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh"
ADD_TEST( t_test_ddsim "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh"
ddsim --compactFile=${CMAKE_INSTALL_PREFIX}/DDDetectors/compact/SiD.xml --runType=batch -G -N=2 --outputFile=testSid.root
--part.userParticleHandler=)
SET_TESTS_PROPERTIES( test_ddsim PROPERTIES FAIL_REGULAR_EXPRESSION "Exception;EXCEPTION;ERROR;Error" )
SET_TESTS_PROPERTIES( t_test_ddsim PROPERTIES FAIL_REGULAR_EXPRESSION "Exception;EXCEPTION;ERROR;Error" )
endif()
install(DIRECTORY include/DD4hep DESTINATION include)
\ No newline at end of file
install(DIRECTORY include/DD4hep DESTINATION include)
#!/usr/bin/env python
"""
Some imports to make sure that the DD4hep environment is complete
"""
from __future__ import absolute_import, unicode_literals, print_function
import traceback
import warnings
import pytest
parametrize = pytest.mark.parametrize
moduleNames = [
'DDDigi',
'DDG4',
'dd4hep',
'DDRec',
]
# List here the modules that are allowed to Fail.
# Ideally, this should always be empty...
ALLOWED_TO_FAIL = []
# List of modules that need graphic libraries.
# When failing, these tests are just marked as skipped with a warning
GRAPHIC_MODULES = []
@parametrize('moduleName', moduleNames)
def test_module(moduleName):
""" Try to import a module from DD4hep.
Modules that are in the ALLOWED_TO_FAIL list are shown as skipped and generate a warning
Modules that require graphic libraries (GRAPHIC_MODULES) are skipped on container
"""
try:
__import__(moduleName)
# Test whether it is correctly imported from DD4hep
except ImportError as e:
msg = "could not import %s: %s" % (moduleName, repr(e))
print(traceback.print_exc())
if moduleName in ALLOWED_TO_FAIL:
warnings.warn(msg)
pytest.skip("WARN: " + msg)
elif moduleName in GRAPHIC_MODULES:
warnings.warn(msg + "(Possibly due to system graphic libraries not present)")
pytest.skip("WARN: " + msg + "(Possibly due to system graphic libraries not present)")
else:
pytest.fail("ERROR: " + msg)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment