From e1e7b9e37f16ce7eceb6d4a161491ae7f97d5a04 Mon Sep 17 00:00:00 2001
From: Enric Tejedor Saavedra <enric.tejedor.saavedra@cern.ch>
Date: Fri, 30 Nov 2018 16:48:01 +0100
Subject: [PATCH] [Exp PyROOT] Add test for len in TCollection and subclasses

---
 .../PyROOT/test/CMakeLists.txt                |  3 ++
 .../PyROOT/test/tcollection_len.py            | 31 +++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 bindings/pyroot_experimental/PyROOT/test/tcollection_len.py

diff --git a/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt b/bindings/pyroot_experimental/PyROOT/test/CMakeLists.txt
index fbad8754c13..112a55883f2 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 00000000000..cc6eca9e8c8
--- /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())
-- 
GitLab