From c4273740084315961e241d15e8a82296668f9b3d Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Thu, 26 Sep 2024 10:31:05 +0200 Subject: [PATCH] Add read tests to ensure backwards compatibility (#358) * Add backwards compatibility tests using downloaded files * Add basic version checks to reading files * Run pytest with more output * Update test files to the tagged versions * Avoid polluting the test output to make them fail The gaudi_fixtures that have been introduced with v39 include the full python file otherwise, which matches the FAIL_REGULAR_EXPRESSION and makes the test fail even though they are actually passing --- CMakeLists.txt | 2 +- test/CMakeLists.txt | 11 ++++++- test/backwards_compat/CMakeLists.txt | 15 +++++++++ ...le_rntuple_v00-99-01_podio_v01-01.root.md5 | 1 + ...ep_example_v00-99-01_podio_v01-01.root.md5 | 1 + test/pytest.ini | 2 +- test/test_EDM4hepFile.py | 32 ++++++++++++++++++- 7 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 test/backwards_compat/CMakeLists.txt create mode 100644 test/backwards_compat/input_files/edm4hep_example_rntuple_v00-99-01_podio_v01-01.root.md5 create mode 100644 test/backwards_compat/input_files/edm4hep_example_v00-99-01_podio_v01-01.root.md5 diff --git a/CMakeLists.txt b/CMakeLists.txt index b666959d6..19a52a3d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,9 +67,9 @@ find_package(nlohmann_json 3.10.5) add_subdirectory(edm4hep) add_subdirectory(utils) -add_subdirectory(test) add_subdirectory(tools) add_subdirectory(python) +add_subdirectory(test) #--- create uninstall target --------------------------------------------------- include(cmake/EDM4HEPUninstall.cmake) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b45e8f03e..351fa7673 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,7 +44,6 @@ set_tests_properties( PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - FAIL_REGULAR_EXPRESSION "" ) add_executable(write_events write_events.cc) @@ -127,3 +126,13 @@ set_property(TEST py_test_module APPEND PROPERTY ENVIRONMENT add_subdirectory(utils) add_subdirectory(tools) + + +include(ExternalData) +list(APPEND ExternalData_URL_TEMPLATES + "https://key4hep.web.cern.ch:443/testFiles/EDM4hep/%(hash)" +) + +add_subdirectory(backwards_compat) + +ExternalData_Add_Target(backward_compat_tests) diff --git a/test/backwards_compat/CMakeLists.txt b/test/backwards_compat/CMakeLists.txt new file mode 100644 index 000000000..bb1b6cb59 --- /dev/null +++ b/test/backwards_compat/CMakeLists.txt @@ -0,0 +1,15 @@ +ExternalData_Add_Test(backward_compat_tests + NAME backwards_compat_v00-99 COMMAND pytest -v --inputfile=DATA{${CMAKE_CURRENT_SOURCE_DIR}/input_files/edm4hep_example_v00-99-01_podio_v01-01.root}) +set_test_env(backwards_compat_v00-99) + +ExternalData_Add_Test(backward_compat_tests + NAME backwards_compat_rntuple_v00-99 COMMAND pytest -v --inputfile=DATA{${CMAKE_CURRENT_SOURCE_DIR}/input_files/edm4hep_example_rntuple_v00-99-01_podio_v01-01.root}) +set_test_env(backwards_compat_rntuple_v00-99) + +set_tests_properties( + backwards_compat_v00-99 + backwards_compat_rntuple_v00-99 + + PROPERTIES + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test +) diff --git a/test/backwards_compat/input_files/edm4hep_example_rntuple_v00-99-01_podio_v01-01.root.md5 b/test/backwards_compat/input_files/edm4hep_example_rntuple_v00-99-01_podio_v01-01.root.md5 new file mode 100644 index 000000000..e96350842 --- /dev/null +++ b/test/backwards_compat/input_files/edm4hep_example_rntuple_v00-99-01_podio_v01-01.root.md5 @@ -0,0 +1 @@ +a725377f2bb515f7d91b953b7a1fc964 diff --git a/test/backwards_compat/input_files/edm4hep_example_v00-99-01_podio_v01-01.root.md5 b/test/backwards_compat/input_files/edm4hep_example_v00-99-01_podio_v01-01.root.md5 new file mode 100644 index 000000000..da099571b --- /dev/null +++ b/test/backwards_compat/input_files/edm4hep_example_v00-99-01_podio_v01-01.root.md5 @@ -0,0 +1 @@ +bd4006fb7a56fa765ede88c2920eb351 diff --git a/test/pytest.ini b/test/pytest.ini index 10cf4e47f..5ae511141 100644 --- a/test/pytest.ini +++ b/test/pytest.ini @@ -1,2 +1,2 @@ [pytest] -addopts = --ignore=test_rdf.py --ignore=tools --ignore=utils +addopts = --ignore=test_rdf.py --ignore=tools --ignore=utils -p no:gaudi_fixtures diff --git a/test/test_EDM4hepFile.py b/test/test_EDM4hepFile.py index b23a569b4..85b76f43e 100644 --- a/test/test_EDM4hepFile.py +++ b/test/test_EDM4hepFile.py @@ -4,11 +4,14 @@ """ import os +import re import podio import edm4hep import pytest from itertools import count +from edm4hep import __version__ + from conftest import options # For now simply copy these from createEDM4hepFile.py @@ -30,6 +33,29 @@ def inputfile_name(pytestconfig): return pytestconfig.getoption("inputfile") +VERSIONED_FILE_RGX = re.compile( + r"edm4hep_example_(?:rntuple_)?v(\d+-\d+(?:-\d+)?)_podio_v(\d+-\d+(?:-\d+)?).root" +) + + +@pytest.fixture(scope="module") +def expected_edm4hep_version(inputfile_name): + """Get the expected edm4hep version from the file name""" + rgx_match = re.match(VERSIONED_FILE_RGX, inputfile_name) + if not rgx_match: + return podio.version.parse(__version__) + return podio.version.parse(rgx_match.group(1).replace("-", ".")) + + +@pytest.fixture(scope="module") +def expected_podio_version(inputfile_name): + """Get the expected edm4hep version from the file name""" + rgx_match = re.match(VERSIONED_FILE_RGX, inputfile_name) + if not rgx_match: + return podio.version.build_version + return podio.version.parse(rgx_match.group(2).replace("-", ".")) + + @pytest.fixture(scope="module") def reader(inputfile_name): """Get the reader for the passed filename""" @@ -77,9 +103,13 @@ def check_cov_matrix(cov_matrix, n_dim): assert cov_matrix[i] == next(counter) -def test_basic_file_contents(events): +def test_basic_file_contents( + reader, events, expected_edm4hep_version, expected_podio_version +): """Make sure the basic file contents are OK""" assert len(events) == FRAMES + assert reader.current_file_version("edm4hep") == expected_edm4hep_version + assert reader.current_file_version() == expected_podio_version def test_EventHeaderCollection(event):