Skip to content

Commit

Permalink
Make python unittests work again
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Dec 12, 2023
1 parent bd20dd3 commit 1fbc233
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
7 changes: 1 addition & 6 deletions cmake/podioTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ function(PODIO_SET_TEST_ENV test)
PODIO_USE_CLANG_FORMAT=${PODIO_USE_CLANG_FORMAT}
PODIO_BASE=${PROJECT_SOURCE_DIR}
ENABLE_SIO=${ENABLE_SIO}
PODIO_BUILD_BASE=${PROJECT_BINARY_DIR}
)
if (DEFINED CACHE{PODIO_TEST_INPUT_DATA_DIR})
list(APPEND test_environment
PODIO_TEST_INPUT_DATA_DIR=${PODIO_TEST_INPUT_DATA_DIR}
)
endif()

set_property(TEST ${test}
PROPERTY ENVIRONMENT "${test_environment}"
)
Expand Down
7 changes: 3 additions & 4 deletions python/podio/test_ReaderRoot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python3
"""Python unit tests for the ROOT backend (using Frames)"""

import os
import unittest

from test_Reader import ReaderTestCaseMixin, LegacyReaderTestCaseMixin # pylint: disable=import-error
from podio.test_utils import LEGACY_DATA_AVAILABLE
from podio.test_utils import ROOT_LEGACY_INPUT_FILE

from podio.root_io import Reader, LegacyReader

Expand All @@ -17,9 +16,9 @@ def setUp(self):
self.reader = Reader('root_io/example_frame.root')


@unittest.skipIf(not LEGACY_DATA_AVAILABLE, "no legacy input data available")
@unittest.skipIf(not ROOT_LEGACY_INPUT_FILE, "no legacy input data available")
class RootLegacyReaderTestCase(LegacyReaderTestCaseMixin, unittest.TestCase):
"""Test cases for the legacy root input files and reader."""
def setUp(self):
"""Setup a reader, reading from the example files"""
self.reader = LegacyReader(os.path.join(os.environ["PODIO_TEST_INPUT_DATA_DIR"], "v00-16-06", "example.root"))
self.reader = LegacyReader(ROOT_LEGACY_INPUT_FILE)
7 changes: 3 additions & 4 deletions python/podio/test_ReaderSio.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python3
"""Python unit tests for the SIO backend (using Frames)"""

import os
import unittest

from test_Reader import ReaderTestCaseMixin, LegacyReaderTestCaseMixin # pylint: disable=import-error
from test_utils import SKIP_SIO_TESTS, LEGACY_DATA_AVAILABLE # pylint: disable=import-error
from podio.test_utils import SKIP_SIO_TESTS, SIO_LEGACY_INPUT_FILE


@unittest.skipIf(SKIP_SIO_TESTS, "no SIO support")
Expand All @@ -17,10 +16,10 @@ def setUp(self):
self.reader = Reader('sio_io/example_frame.sio')


@unittest.skipIf(SKIP_SIO_TESTS or not LEGACY_DATA_AVAILABLE, "no SIO support or data not available")
@unittest.skipIf(SKIP_SIO_TESTS or not SIO_LEGACY_INPUT_FILE, "no SIO support or data not available")
class SIOLegacyReaderTestCase(LegacyReaderTestCaseMixin, unittest.TestCase):
"""Test cases for the legacy root input files and reader."""
def setUp(self):
"""Setup a reader, reading from the example files"""
from podio.sio_io import LegacyReader # pylint: disable=import-outside-toplevel
self.reader = LegacyReader(os.path.join(os.environ["PODIO_TEST_INPUT_DATA_DIR"], "v00-16-06", "example.sio"))
self.reader = LegacyReader(SIO_LEGACY_INPUT_FILE)
21 changes: 21 additions & 0 deletions python/podio/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,24 @@
import os

SKIP_SIO_TESTS = os.environ.get("SKIP_SIO_TESTS", "1") == "1"


def _get_legacy_input(filename):
"""Try to get a legacy input file by name from the ExternalData that is
fetched by CMake.
Returns either the absolute path to the actual file or an empty string.
"""
try:
with open(os.path.join(os.environ["PODIO_BASE"], "tests", "input_files", filename), encoding="utf-8") as md5file:
md5sum = md5file.read().strip()
datafile = os.path.join(os.environ["PODIO_BUILD_BASE"], "ExternalData", "Objects", "MD5", md5sum)
if os.path.isfile(datafile):
return os.path.abspath(datafile)
except KeyError:
pass
return ""


ROOT_LEGACY_INPUT_FILE = _get_legacy_input("v00-16-06-example.root.md5")
SIO_LEGACY_INPUT_FILE = _get_legacy_input("v00-16-06-example.sio.md5")

0 comments on commit 1fbc233

Please sign in to comment.