From 07f1990537838c976f4ad8b68f4792a39cc5cd12 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Wed, 18 Sep 2024 14:22:02 +0200 Subject: [PATCH] Add basic version checks to reading files --- test/test_EDM4hepFile.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/test_EDM4hepFile.py b/test/test_EDM4hepFile.py index b23a569b4..28d944086 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.Version(__version__) + return podio.version.Version(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.Version(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):