Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:42

0001 #!/usr/bin/env python
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 from __future__ import absolute_import, unicode_literals, print_function
0007 import traceback
0008 import warnings
0009 import pytest
0010 
0011 parametrize = pytest.mark.parametrize
0012 
0013 ImportFehler = ImportError
0014 FEHLER = "ERROR: "
0015 
0016 moduleNames = [
0017     'dd4hep',
0018     'DDRec',
0019     'dddigi',
0020     ]
0021 
0022 # List here the modules that are allowed to Fail.
0023 # Ideally, this should always be empty...
0024 ALLOWED_TO_FAIL = []
0025 
0026 # List of modules that need graphic libraries.
0027 # When failing, these tests are just marked as skipped with a warning
0028 GRAPHIC_MODULES = []
0029 
0030 
0031 @parametrize('moduleName', moduleNames)
0032 def test_module(moduleName):
0033   """ Try to import a module from DD4hep.
0034 
0035       Modules that are in the ALLOWED_TO_FAIL list are shown as skipped and generate a warning
0036 
0037       Modules that require graphic libraries (GRAPHIC_MODULES) are skipped on container
0038   """
0039 
0040   try:
0041     __import__(moduleName)
0042 
0043     # Test whether it is correctly imported from DD4hep
0044 
0045   except ImportFehler as e:
0046     msg = "could not import %s: %s" % (moduleName, repr(e))
0047     print(traceback.print_exc())
0048 
0049     if moduleName in ALLOWED_TO_FAIL:
0050       warnings.warn(msg, stacklevel=2)
0051       pytest.skip("WARN: " + msg)
0052     elif moduleName in GRAPHIC_MODULES:
0053       warnings.warn(msg + "(Possibly due to system graphic libraries not present)", stacklevel=2)
0054       pytest.skip("WARN: " + msg + "(Possibly due to system graphic libraries not present)")
0055     else:
0056       pytest.fail(FEHLER + msg)