Skip to content
Snippets Groups Projects
Commit 0615ba90 authored by Eduardo Rodrigues's avatar Eduardo Rodrigues Committed by Patrick Koppenburg
Browse files

Introduce Pytest-based tests for the DaVinci configuration

parent 17de7c72
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!603Introduce Pytest-based tests for the DaVinci configuration
......@@ -17,3 +17,6 @@ gaudi_install(PYTHON)
gaudi_generate_confuserdb(DaVinci.compat.DaVinciConf)
lhcb_env(SET DAVINCIOPTS ${CMAKE_CURRENT_SOURCE_DIR}/options)
gaudi_add_tests(QMTest)
gaudi_add_tests(pytest ${CMAKE_CURRENT_SOURCE_DIR}/tests)
......@@ -125,8 +125,8 @@ def enums_as_dict(enums):
Example:
>>> class MyEnum(Enum):
a = 1
b = 2
... a = 1
... b = 2
>>> enums_as_dict(MyEnum)
{'a': 1, 'b': 2}
"""
......
###############################################################################
##############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
......@@ -8,16 +8,3 @@
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
"""
A dummy DaVinci job with no algorithm/node run.
"""
from __future__ import absolute_import
from DaVinci.config import options, run_davinci
# Basic input-like metadata required even though there is no input data
options.input_type = "ROOT"
options.dddb_tag = "dummy"
options.conddb_tag = "dummy"
run_davinci(options)
......@@ -8,21 +8,26 @@
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
"""
A dummy job with no algorithm/node run. Does not use the "DaVinci runner".
"""
from __future__ import absolute_import
from PyConf.application import configure
from PyConf.control_flow import CompositeNode
import pytest
from DaVinci.config import options
from DaVinci import options
dummy = CompositeNode("Dummy", children=[], force_order=True)
# Basic input-like metadata required even though there is no input data
options.input_type = "ROOT"
options.dddb_tag = "dummy"
options.conddb_tag = "dummy"
def test_option_set():
print(options.detectors)
config = configure(options, dummy)
def test_option_unset():
with pytest.raises(AttributeError):
print(options.evt_max)
def test_option_get_after_set():
options.evt_max = 1
print(options.evt_max)
def test_option_unknown():
with pytest.raises(AttributeError):
print(options.unknown)
##############################################################################
# (c) Copyright 2020-2021 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
......@@ -8,23 +8,22 @@
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from PyConf.Algorithms import GaudiHistoAlgorithm
from DaVinci import options, run_davinci, DVNode
# print control flow and data flow graphs
options.control_flow_file = 'control_flow.gv'
options.data_flow_file = 'data_flow.gv'
import pytest
options.ntuple_file = 'DVU_test-ntp.root'
options.histo_file = 'DVU_test-his.root'
from DaVinci.configOptions import list_data_options
# Setup datase
options.evt_max = 100
options.set_input_and_conds_from_testfiledb('Upgrade_Bd2KstarMuMu')
# define algorithm
simple_histos = GaudiHistoAlgorithm(name="SimpleHistos", HistoPrint=True)
def test_list_data_options_key_in_TestFileDB():
fileDB_key = "Upgrade_Bd2KstarMuMu"
fileDB_file = "TestFileDB"
assert list_data_options(fileDB_key, fileDB_file) == [
'Author', 'Format', 'DataType', 'Date', 'Simulation', 'CondDB', 'DDDB'
]
# run davinci
algs = DVNode(name="DVselection", algs=[simple_histos])
run_davinci(options, user=[algs])
def test_list_data_options_unknown_key_in_TestFileDB():
with pytest.raises(KeyError):
fileDB_key = "UnknownKey"
fileDB_file = "TestFileDB"
_ = list_data_options(fileDB_key, fileDB_file)
##############################################################################
# (c) Copyright 2020-2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from DaVinci import options, run_davinci, DVNode
from DaVinci.standard_particles import make_detached_mumu
from DaVinci.reco_objects import upfront_reconstruction_from_file as upfront_reconstruction
# print control flow and data flow graphs
options.control_flow_file = 'control_flow.gv'
options.data_flow_file = 'data_flow.gv'
options.ntuple_file = 'DVU_test-ntp.root'
options.histo_file = 'DVU_test-his.root'
# Setup dataset
options.evt_max = 10
options.set_input_and_conds_from_testfiledb('Upgrade_Bd2KstarMuMu')
#options.set_input_and_conds_from_testfiledb('upgrade-magdown-sim09c-up02-reco-up01-minbias-ldst')
options.input_raw_format = 4.3
print(options)
sel = DVNode(
name="Selection1", algs=upfront_reconstruction() + [make_detached_mumu()])
# run davinci
#public_tools = [stateProvider_with_simplified_geom()]
run_davinci(options, selections=[sel]) #, public_tools)
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