@@ -0,0 +1,3250 @@
+#!/usr/bin/env python%0Afrom alphatwirl import Events%0Aimport unittest%0A%0A##____________________________________________________________________________%7C%7C%0Aclass MockFile(object):%0A    pass%0A%0A##____________________________________________________________________________%7C%7C%0Aclass MockTree(object):%0A    def __init__(self, Entries = 100):%0A        self.Entries = Entries%0A        self.iEvent = -1%0A        self.branch1 = 1111%0A    def GetDirectory(self):%0A        return MockFile()%0A    def GetEntries(self):%0A        return self.Entries%0A    def GetEntry(self, ientry):%0A        if ientry %3C self.Entries:%0A            nbytes = 10%0A            self.iEvent = ientry%0A        else:%0A            nbytes = 0%0A            self.iEvent = -1%0A        return nbytes%0A%0A##____________________________________________________________________________%7C%7C%0Aclass TestMockTree(unittest.TestCase):%0A%0A    def test_mocktree(self):%0A        tree = MockTree(Entries = 3)%0A        self.assertIsInstance(tree.GetDirectory(), MockFile)%0A        self.assertEqual(3, tree.GetEntries())%0A%0A        self.assertEqual(-1, tree.iEvent)%0A%0A        nbytes = 10%0A        self.assertEqual(nbytes, tree.GetEntry(0))%0A        self.assertEqual(0, tree.iEvent)%0A        self.assertEqual(nbytes, tree.GetEntry(1))%0A        self.assertEqual(1, tree.iEvent)%0A        self.assertEqual(nbytes, tree.GetEntry(2))%0A        self.assertEqual(2, tree.iEvent)%0A        self.assertEqual(0, tree.GetEntry(3))%0A        self.assertEqual(-1, tree.iEvent)%0A%0A##____________________________________________________________________________%7C%7C%0Aclass TestEvents(unittest.TestCase):%0A%0A    def setUp(self):%0A        self.tree = MockTree()%0A        self.events = Events(self.tree)%0A%0A    def test_init(self):%0A        tree = MockTree()%0A        events = Events(tree)%0A        events = Events(tree, 100)%0A%0A        self.assertIs(tree, events.tree)%0A%0A    def test_nEevent(self):%0A        entreis = 100%0A        tree = MockTree(entreis)%0A        events = Events(tree)%0A        self.assertEqual(100, events.nEvents) # default the same as entries%0A%0A        events = Events(tree, -1)%0A        self.assertEqual(100, events.nEvents) # the same as entries%0A%0A        events = Events(tree, 50)%0A        self.assertEqual(50, events.nEvents)%0A%0A        events = Events(tree, 120)%0A        self.assertEqual(100, events.nEvents)%0A%0A        events = Events(tree, 100)%0A        self.assertEqual(100, events.nEvents)%0A%0A    def test_iter(self):%0A        entreis = 4%0A        tree = MockTree(entreis)%0A        events = Events(tree)%0A        it = iter(events)%0A        event = next(it)%0A        self.assertEqual(0, tree.iEvent)%0A        event = next(it)%0A        self.assertEqual(1, tree.iEvent)%0A        event = next(it)%0A        self.assertEqual(2, tree.iEvent)%0A        event = next(it)%0A        self.assertEqual(3, tree.iEvent)%0A        self.assertRaises(StopIteration, next, it)%0A        self.assertEqual(3, tree.iEvent) # it remains at the last event%0A%0A    def test_getattr(self):%0A        entreis = 5%0A        tree = MockTree(entreis)%0A        events = Events(tree)%0A        it = iter(events)%0A        event = next(it)%0A        self.assertEqual(1111, event.branch1)%0A        tree.branch1 = 2222%0A        self.assertEqual(2222, event.branch1)%0A%0A##____________________________________________________________________________%7C%7C%0A

add test_Events.py