diff --git a/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt b/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt index 9b9331cc231c9d393f4bebe1c21b50d643236632..974ee928af231edda07807778636b2b1d396f63d 100644 --- a/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt +++ b/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt @@ -17,6 +17,9 @@ ROOT_ADD_PYUNITTEST(pyroot_pyz_ttree_setbranchaddress ttree_setbranchaddress.py ROOT_ADD_PYUNITTEST(pyroot_pyz_ttree_branch ttree_branch.py COPY_TO_BUILDDIR TreeHelper.h) +# TIter pythonisations +ROOT_ADD_PYUNITTEST(pyroot_pyz_titer_iterator titer_iterator.py) + # TCollection and subclasses pythonizations ROOT_ADD_PYUNITTEST(pyroot_pyz_tcollection_len tcollection_len.py) ROOT_ADD_PYUNITTEST(pyroot_pyz_tcollection_listmethods tcollection_listmethods.py) diff --git a/bindings/pyroot_experimental/PyROOT/test/titer_iterator.py b/bindings/pyroot_experimental/PyROOT/test/titer_iterator.py new file mode 100644 index 0000000000000000000000000000000000000000..84fa536c4cc1833ec67f6557d628abc6b7e8590d --- /dev/null +++ b/bindings/pyroot_experimental/PyROOT/test/titer_iterator.py @@ -0,0 +1,33 @@ +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())