Skip to content

Commit

Permalink
Adding test which checks for all the collections
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt committed Nov 1, 2023
1 parent 5633e27 commit c0b3324
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
7 changes: 1 addition & 6 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,5 @@ if(HepMC3_FOUND AND HepPDT_FOUND )
)
endif()

if (nlohmann_json_FOUND)
add_test(NAME convert_events COMMAND edm4hep2json edm4hep_events.root)
set_property(TEST convert_events PROPERTY DEPENDS write_events)
set_test_env(convert_events)
endif()

add_subdirectory(utils)
add_subdirectory(tools)
12 changes: 12 additions & 0 deletions test/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if (nlohmann_json_FOUND)
add_test(NAME convert_events
COMMAND edm4hep2json ${CMAKE_CURRENT_BINARY_DIR}/../edm4hep_events.root)
set_property(TEST convert_events PROPERTY DEPENDS write_events)
set_test_env(convert_events)

add_test(NAME test_convert_all_collections
COMMAND python ${CMAKE_CURRENT_LIST_DIR}/test_all_collections.py
${PROJECT_SOURCE_DIR}/edm4hep.yaml
${PROJECT_SOURCE_DIR}/tools/include/edm4hep2json.hxx)
set_test_env(test_convert_all_collections)
endif()
44 changes: 44 additions & 0 deletions test/tools/test_all_collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'''
Tests if all collection header files are included in the cxx file.
'''

import sys
import argparse
import yaml


def test(yamlfile_path, cxxfile_path):
'''
Test itself.
Takes two parameters, Podio YAML file location and cxx file to be checked.
'''

with open(yamlfile_path, mode='r', encoding="utf-8") as yamlfile:
datamodel = yaml.safe_load(yamlfile)

with open(cxxfile_path, mode='r', encoding="utf-8") as cxxfile:
cxxfile_lines = cxxfile.readlines()

datatypes = datamodel['datatypes']

for collname in datatypes:
include_string = '#include "' + collname.replace('::', '/') + \
'Collection.h"'
include_found = False
for line in cxxfile_lines:
if include_string in line:
include_found = True

if not include_found:
print('ERROR: Following collection not included in the cxx file.')
print(' ' + collname)
sys.exit(2)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Test all collections')
parser.add_argument('yamlfile')
parser.add_argument('cxxfile')
args = parser.parse_args()

test(args.yamlfile, args.cxxfile)
3 changes: 2 additions & 1 deletion tools/src/edm4hep2json.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ int main(int argc, char** argv) {
}

if (!std::filesystem::exists(inFilePath)) {
std::cerr << "ERROR: Input .root file can't be read!" << std::endl;
std::cerr << "ERROR: Input .root file can't be read!\n "
<< inFilePath << std::endl;
return EXIT_FAILURE;
}

Expand Down

0 comments on commit c0b3324

Please sign in to comment.