Skip to content

Commit

Permalink
Add read tests to ensure backwards compatibility (#358)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tmadlener authored Sep 26, 2024
1 parent d31d345 commit c427374
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 10 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ set_tests_properties(

PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
FAIL_REGULAR_EXPRESSION ""
)

add_executable(write_events write_events.cc)
Expand Down Expand Up @@ -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)
15 changes: 15 additions & 0 deletions test/backwards_compat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a725377f2bb515f7d91b953b7a1fc964
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bd4006fb7a56fa765ede88c2920eb351
2 changes: 1 addition & 1 deletion test/pytest.ini
Original file line number Diff line number Diff line change
@@ -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
32 changes: 31 additions & 1 deletion test/test_EDM4hepFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c427374

Please sign in to comment.