Skip to content
Snippets Groups Projects
Commit 7812f04f authored by Enric Tejedor Saavedra's avatar Enric Tejedor Saavedra
Browse files

[Exp PyROOT] Test pythonisation to make TIter a Python iterator

parent 84dad247
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,9 @@ ROOT_ADD_PYUNITTEST(pyroot_pyz_ttree_setbranchaddress ttree_setbranchaddress.py ...@@ -17,6 +17,9 @@ ROOT_ADD_PYUNITTEST(pyroot_pyz_ttree_setbranchaddress ttree_setbranchaddress.py
ROOT_ADD_PYUNITTEST(pyroot_pyz_ttree_branch ttree_branch.py ROOT_ADD_PYUNITTEST(pyroot_pyz_ttree_branch ttree_branch.py
COPY_TO_BUILDDIR TreeHelper.h) COPY_TO_BUILDDIR TreeHelper.h)
# TIter pythonisations
ROOT_ADD_PYUNITTEST(pyroot_pyz_titer_iterator titer_iterator.py)
# TCollection and subclasses pythonizations # TCollection and subclasses pythonizations
ROOT_ADD_PYUNITTEST(pyroot_pyz_tcollection_len tcollection_len.py) ROOT_ADD_PYUNITTEST(pyroot_pyz_tcollection_len tcollection_len.py)
ROOT_ADD_PYUNITTEST(pyroot_pyz_tcollection_listmethods tcollection_listmethods.py) ROOT_ADD_PYUNITTEST(pyroot_pyz_tcollection_listmethods tcollection_listmethods.py)
......
import unittest
import ROOT
from libcppyy import SetOwnership
class TIterIterator(unittest.TestCase):
"""
Test for the pythonization that allows instances of TIter to
behave as Python iterators.
"""
num_elems = 3
# Helpers
def create_tcollection(self):
c = ROOT.TList()
for _ in range(self.num_elems):
o = ROOT.TObject()
# Prevent immediate deletion of C++ TObjects
SetOwnership(o, False)
c.Add(o)
return c
# Tests
def test_iterator(self):
c = self.create_tcollection()
itc1 = ROOT.TIter(c)
itc2 = ROOT.TIter(c)
for _ in range(c.GetEntries()):
self.assertEqual(next(itc1), itc2.Next())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment