CMS 3D CMS Logo

tree_test.py
Go to the documentation of this file.
1 from __future__ import absolute_import
2 import unittest
3 from ROOT import TFile
4 from .tree import Tree
5 
6 class TreeTestCase(unittest.TestCase):
7 
8  def test_fill(self):
9  fi = TFile('tree.root','RECREATE')
10  tr = Tree('test_tree', 'A test tree')
11  tr.var('a')
12  tr.var('b')
13  tr.fill('a', 3)
14  tr.fill('a', 4)
15  tr.fill('b', 5)
16  tr.tree.Fill()
17  fi.Write()
18  fi.Close()
19 
20  def test_read(self):
21  fi = TFile('tree.root')
22  tr = fi.Get('test_tree')
23  self.assertEqual(tr.GetEntries(), 1)
24  tr.GetEntry(0)
25  self.assertEqual(tr.a, 4)
26 
27  def test_iterate(self):
28  fi = TFile('tree.root')
29  tr = fi.Get('test_tree')
30  for ev in tr:
31  self.assertEqual(ev.a, 4)
32  break
33 
34 
35 if __name__ == '__main__':
36  unittest.main()
Definition: tree.py:6
def test_fill(self)
Definition: tree_test.py:8
def test_iterate(self)
Definition: tree_test.py:27