diff --git a/bindings/pyroot_experimental/PyROOT/test/ttree_branch_attr.py b/bindings/pyroot_experimental/PyROOT/test/ttree_branch_attr.py index e367e61b0165c88a5969875b1ca6bf4a09336998..7d098574afd8ef2ae789eb3886305c1f4b2e3a9a 100644 --- a/bindings/pyroot_experimental/PyROOT/test/ttree_branch_attr.py +++ b/bindings/pyroot_experimental/PyROOT/test/ttree_branch_attr.py @@ -9,12 +9,13 @@ class TTreeBranchAttr(unittest.TestCase): Test for the pythonization that allows to access top-level tree branches/leaves as attributes (i.e. `mytree.mybranch`) - Since this pythonization is common to TTree and its subclasses, TChain is - also tested here. + Since this pythonization is common to TTree and its subclasses, TChain and TNtuple + are also tested here. """ filename = 'treebranchattr.root' treename = 'mytree' + tuplename = 'mytuple' nentries = 1 arraysize = 10 more = 10 @@ -29,6 +30,11 @@ class TTreeBranchAttr(unittest.TestCase): cls.arraysize, cls.more, 'RECREATE') + ROOT.CreateTNtuple(cls.filename, + cls.tuplename, + cls.nentries, + cls.more, + 'UPDATE') # Helper def get_file_objects(self): @@ -41,21 +47,30 @@ class TTreeBranchAttr(unittest.TestCase): c.Add(self.filename) c.Add(self.filename) + nt = f.Get(self.tuplename) + SetOwnership(nt, False) + # Read first entry - for ds in t,c: + for ds in t,c,nt: ds.GetEntry(0) - return f,t,c + return f,t,c,nt # Tests def test_basic_type_branch(self): - f,t,c = self.get_file_objects() + f,t,c,nt = self.get_file_objects() + # TTree, TChain for ds in t,c: self.assertEqual(ds.floatb, self.more) + # TNtuple + self.assertEqual(nt.x, 0.) + self.assertEqual(nt.y, self.more) + self.assertEqual(nt.z, 2*self.more) + def test_array_branch(self): - f,t,c = self.get_file_objects() + f,t,c,_ = self.get_file_objects() for ds in t,c: a = ds.arrayb @@ -64,7 +79,7 @@ class TTreeBranchAttr(unittest.TestCase): self.assertEqual(a[j], j) def test_vector_branch(self): - f,t,c = self.get_file_objects() + f,t,c,_ = self.get_file_objects() for ds in t,c: v = ds.vectorb @@ -73,7 +88,7 @@ class TTreeBranchAttr(unittest.TestCase): self.assertEqual(v[j], j) def test_struct_branch(self): - f,t,c = self.get_file_objects() + f,t,c,_ = self.get_file_objects() for ds in t,c: ms = ds.structb @@ -82,14 +97,14 @@ class TTreeBranchAttr(unittest.TestCase): self.assertEqual(ms.myint2, 0) def test_struct_branch_leaflist(self): - f,t,c = self.get_file_objects() + f,t,c,_ = self.get_file_objects() for ds in t,c: self.assertEqual(ds.myintll1, self.more) self.assertEqual(ds.myintll2, 0) def test_alias_branch(self): - f,t,c = self.get_file_objects() + f,t,c,_ = self.get_file_objects() for ds in t,c: ds.SetAlias('myalias', 'floatb')