CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
chain_test.py
Go to the documentation of this file.
1 import unittest
2 import os
3 import shutil
4 
5 from PhysicsTools.HeppyCore.framework.chain import Chain
6 
7 class ChainTestCase(unittest.TestCase):
8 
9  def setUp(self):
10  self.file = '../../test/test_tree.root'
11  self.chain = Chain(self.file, 'test_tree')
12 
13  def test_file(self):
14  self.assertTrue(os.path.isfile(self.file))
15 
16  def test_guess_name(self):
17  self.assertRaises(ValueError,
18  Chain, 'self.file')
19 
20  def test_load_1(self):
21  self.assertEqual(len(self.chain), 100)
22 
23  def test_load_2(self):
24  tmpfile = self.file.replace('test_tree', 'test_tree_2_tmp')
25  shutil.copyfile(self.file, tmpfile)
26  chain = Chain(self.file.replace('.root', '*.root'), 'test_tree')
27  self.assertEqual(len(chain), 200)
28  os.remove(tmpfile)
29 
30  def test_iterate(self):
31  for ev in self.chain:
32  pass
33  self.assertTrue(True)
34 
35  def test_get(self):
36  event = self.chain[2]
37  self.assertEqual(event.var1, 2.)
38 
39 
40 if __name__ == '__main__':
41  unittest.main()