test
CMS 3D CMS Logo

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