diff --git a/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt b/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt index fbad8754c13079a2c7e4db88601a7d7c239e0740..112a55883f2ccf365d68fca62e97498aec6afa0e 100644 --- a/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt +++ b/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt @@ -16,3 +16,6 @@ ROOT_ADD_PYUNITTEST(pyroot_pyz_ttree_setbranchaddress ttree_setbranchaddress.py COPY_TO_BUILDDIR TreeHelper.h) ROOT_ADD_PYUNITTEST(pyroot_pyz_ttree_branch ttree_branch.py COPY_TO_BUILDDIR TreeHelper.h) + +# TCollection and subclasses pythonizations +ROOT_ADD_PYUNITTEST(pyroot_pyz_tcollection_len tcollection_len.py) diff --git a/bindings/pyroot_experimental/PyROOT/test/tcollection_len.py b/bindings/pyroot_experimental/PyROOT/test/tcollection_len.py new file mode 100644 index 0000000000000000000000000000000000000000..cc6eca9e8c89b14e0525cd61a872a2e6ca856ec2 --- /dev/null +++ b/bindings/pyroot_experimental/PyROOT/test/tcollection_len.py @@ -0,0 +1,31 @@ +import unittest + +import ROOT + + +class TCollectionLen(unittest.TestCase): + """ + Test for the pythonization that allows to access the number of elements of a + TCollection (or subclass) by calling `len` on it. + """ + + num_elems = 3 + tobject_list = [ ROOT.TObject() for _ in range(num_elems) ] + + # Helpers + def add_elems_check_len(self, c): + for elem in self.tobject_list: + c.Add(elem) + + self.assertEqual(len(c), self.num_elems) + self.assertEqual(len(c), c.GetEntries()) + + # Tests + def test_tlist(self): + self.add_elems_check_len(ROOT.TList()) + + def test_tobjarray(self): + self.add_elems_check_len(ROOT.TObjArray()) + + def test_thashtable(self): + self.add_elems_check_len(ROOT.THashTable())