Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read tests to ensure backwards compatibility #358

Merged
merged 7 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading