Skip to content

Commit

Permalink
added python bindings test for mutable object conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed Feb 22, 2024
1 parent 4e74a02 commit 6a14b82
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ else()
PODIO_SIOBLOCK_PATH=${CMAKE_CURRENT_BINARY_DIR}
)
endif()

add_test(NAME unittest.py COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/unittests.py)
PODIO_SET_TEST_ENV(unittest.py)
set_tests_properties(unittest.py PROPERTIES WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
36 changes: 36 additions & 0 deletions tests/unittests/unittests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import unittest
import ROOT

res = ROOT.gSystem.Load("libTestDataModel.so")
if res < 0:
raise RuntimeError("Failed to load libTestDataModel.so")

from ROOT import MutableExampleMC
from ROOT import ExampleMCCollection


class Test_ObjectConversions(unittest.TestCase):
def test_conversion_mutable_to_immutable(self):
ROOT.gInterpreter.Declare(
"""
void test_accepts_immutable(ExampleMC) {}
"""
)
accepts_immutable = ROOT.test_accepts_immutable
mutable_obj = MutableExampleMC()
accepts_immutable(mutable_obj)


class Test_OneToManyRelations(unittest.TestCase):
def test_add(self):
particles = ExampleMCCollection()
parent_particle = particles.create()
daughter_particle = particles.create()

self.assertEqual(len(daughter_particle.parents()), 0)
daughter_particle.addparents(parent_particle)
self.assertEqual(len(daughter_particle.parents()), 1)


if __name__ == "__main__":
unittest.main()

0 comments on commit 6a14b82

Please sign in to comment.