Skip to content
Snippets Groups Projects
Commit c08ed97c authored by Patrick Koppenburg's avatar Patrick Koppenburg :leaves:
Browse files

Merge branch 'dfazzini_finalize_unit_tests' into 'master'

Finalize unit test coverage

See merge request !660
parents 47fb2618 af059f85
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!660Finalize unit test coverage
Pipeline #3817863 passed
......@@ -141,7 +141,7 @@ def test_create_template_interactively_changing_defaults(pytestconfig):
def test_prompt_values():
with patch('builtins.input', input_mock):
create_jobopt_template(DIR / "test_jobopt_template.yaml", True)
create_jobopt_template(DIR / "test_jobopt_template_new.yaml", True)
capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')
capmanager.suspend_global_capture(in_=True)
......@@ -149,12 +149,12 @@ def test_create_template_interactively_changing_defaults(pytestconfig):
capmanager.resume_global_capture()
config = []
with open(DIR / "test_jobopt_template.yaml") as jobopt_file:
with open(DIR / "test_jobopt_template_new.yaml") as jobopt_file:
config = yaml.safe_load(jobopt_file)
assert isinstance(config, dict)
assert config["annsvc_config"] == "test_annsvc.tck.json"
os.remove(DIR / 'test_jobopt_template.yaml')
os.remove(DIR / 'test_jobopt_template_new.yaml')
input_mock.reset_mock(return_value=True, side_effect=True)
......
......@@ -219,11 +219,11 @@ def setup_user_algorithms(userAlgPath):
else:
try:
userAlgs, publicTools = eval("module%s()" % funcName)
except ImportError:
except (AttributeError, ImportError):
raise DVImportError(
funcName,
f"Runtime error when calling the user algorithm file. User algorithm {funcName} can not be run!"
)
) from None
else:
log_click(
"INFO", "User algorithm %s%s imported successfully!" %
......
......@@ -51,13 +51,14 @@ def get_configurable_opts(configurables, with_defaults):
Returns:
- opts: dictionary containing all the configurables.
"""
import sys
from itertools import chain
from GaudiKernel.Proxy.Configurable import Configurable
opts = {}
for c in configurables:
if hasattr(c, "__opt_properties__"):
if hasattr(c, "__opt_properties__"): # pragma: no cover
# Basic structure for including GaudiConfig2 configurables
# Removed from testing since it is not fully integrated with PyConf.
opts.update(c.__opt_properties__(with_defaults))
else:
items = (chain(c.getDefaultProperties().items(),
......@@ -66,16 +67,15 @@ def get_configurable_opts(configurables, with_defaults):
for p, v in items:
if hasattr(Configurable, "PropertyReference") and isinstance(
v, Configurable.PropertyReference):
v, Configurable.PropertyReference): # pragma: no cover
# Taken from the Gaudi.Main code.
#This feature is useful for synchronizing property values set in different configurables
# with old configurable files, when read via .opts files. Standard jobs import
# options via Python files and don't use this feature. It's kept in the code just
# for completeness but removed for testing for the moment, as suggested by Marco Clemencic.
v = v.__resolve__()
if isinstance(v, str):
v = '"%s"' % v.replace('"', '\\"')
elif sys.version_info < (
3,
): # TODO: remove as soon as Python 2 gets unsupported
import types
if type(v) is types.LongType:
v = '%d' % v
elif hasattr(v, '__opt_value__'):
v = v.__opt_value__()
......
......@@ -15,10 +15,10 @@ from PyConf.Algorithms import Gaudi__Examples__VoidConsumer as VoidConsumer
from DaVinci import options
from DaVinci.optionChecker import DVImportError
from DaVinci.algorithms import (setup_algorithms, define_fsr_writer,
from DaVinci.algorithms import (setup_algorithms, define_fsr_writer, filter_on,
add_filter, apply_filters_and_unpacking,
setup_user_algorithms, unpack_locations,
configured_FunTuple)
configured_FunTuple, get_odin, get_decreports)
def test_import_main_options():
......@@ -157,7 +157,7 @@ def main():
return algs, []
""")
with pytest.raises(AttributeError):
with pytest.raises(DVImportError):
test_algs, _ = setup_user_algorithms(f"{filename}:main2")
os.remove(f"{filename}.py")
......@@ -273,3 +273,33 @@ def test_configured_funtuple():
test_dict = configured_FunTuple(config)
assert any("FunTupleBase_Particles/Tuple_TestTuple" in alg.fullname
for alg in test_dict["TestTuple"])
def test_get_odin():
"""
Check if get_odin provides a correct instance of ODIN.
"""
options.input_raw_format = 0.3
odin = get_odin(options)
assert odin.location == "/Event/createODIN/ODIN"
def test_get_decreports():
"""
Check if get_decreports provide a correct instance of HltDecReportsDecoder.
"""
options.process = "Turbo"
options.stream = "TurboSP"
decreports = get_decreports("Hlt2", options)
assert decreports.location == "/Event/Hlt2/DecReports"
def test_filter_on_and_apply_algorithms():
"""
Check if filter_on and apply_algorithms functions return a correct filtered particle location."
"""
spruce_line = "SpruceB2OC_BdToDsmK_DsmToHHH_FEST_Line"
decay_descriptor = "[B0 -> D_s- K+]CC"
data_filtered = filter_on(f"/Event/Spruce/{spruce_line}/Particles",
decay_descriptor)
assert data_filtered.location == "/Event/FilterDecays/particles"
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