File indexing completed on 2026-09-27 08:18:15
0001
0002 """
0003 Some imports to make sure that the DD4hep environment is complete.
0004 Since it can be disabled in CMake, the import of DDG4 is tested in another file.
0005 """
0006 import traceback
0007 import warnings
0008 import pytest
0009
0010 parametrize = pytest.mark.parametrize
0011
0012 ImportFehler = ImportError
0013 FEHLER = "ERROR: "
0014
0015 moduleNames = [
0016 'dd4hep',
0017 'DDRec',
0018 'dddigi',
0019 ]
0020
0021
0022
0023 ALLOWED_TO_FAIL = []
0024
0025
0026
0027 GRAPHIC_MODULES = []
0028
0029
0030 @parametrize('moduleName', moduleNames)
0031 def test_module(moduleName):
0032 """ Try to import a module from DD4hep.
0033
0034 Modules that are in the ALLOWED_TO_FAIL list are shown as skipped and generate a warning
0035
0036 Modules that require graphic libraries (GRAPHIC_MODULES) are skipped on container
0037 """
0038
0039 try:
0040 __import__(moduleName)
0041
0042
0043
0044 except ImportFehler as e:
0045 msg = "could not import %s: %s" % (moduleName, repr(e))
0046 print(traceback.print_exc())
0047
0048 if moduleName in ALLOWED_TO_FAIL:
0049 warnings.warn(msg, stacklevel=2)
0050 pytest.skip("WARN: " + msg)
0051 elif moduleName in GRAPHIC_MODULES:
0052 warnings.warn(msg + "(Possibly due to system graphic libraries not present)", stacklevel=2)
0053 pytest.skip("WARN: " + msg + "(Possibly due to system graphic libraries not present)")
0054 else:
0055 pytest.fail(FEHLER + msg)