Пример #1
0
def test_getattr_same_objects():
    tree = MockTree()
    events = Events(tree)
    branchBuilder = MockBranchBuilder()
    events.buildBranch = branchBuilder

    branch1 = MockBranch()
    branchBuilder.next = branch1
    jet_pt1 = events.jet_pt
    assert branch1 is jet_pt1

    branch2 = MockBranch()
    branchBuilder.next = branch2
    jet_pt2 = events.jet_pt

    assert branch1 is jet_pt2
    assert branch2 is not jet_pt2

    it = iter(events)
    event = next(it)

    branch3 = MockBranch()
    branchBuilder.next = branch3
    jet_pt3 = event.jet_pt

    assert branch1 is jet_pt3
    assert branch3 is not jet_pt3
Пример #2
0
def test_getattr_same_objects():
    tree = MockTree()
    events = Events(tree)
    branchBuilder = MockBranchBuilder()
    events.buildBranch = branchBuilder

    branch1 = MockBranch()
    branchBuilder.next = branch1
    jet_pt1 = events.jet_pt
    assert branch1 is jet_pt1

    branch2 = MockBranch()
    branchBuilder.next = branch2
    jet_pt2 = events.jet_pt

    assert branch1 is jet_pt2
    assert branch2 is not jet_pt2

    it = iter(events)
    event = next(it)

    branch3 = MockBranch()
    branchBuilder.next = branch3
    jet_pt3 = event.jet_pt

    assert branch1 is jet_pt3
    assert branch3 is not jet_pt3
Пример #3
0
    def test_getattr_same_objects(self):
        tree = MockTree()
        events = BEvents(tree)
        branchBuilder = MockBranchBuilder()
        events.buildBranch = branchBuilder

        branch1 = MockBranch()
        branchBuilder.next = branch1
        jet_pt1 = events.jet_pt
        self.assertIs(branch1, jet_pt1)

        branch2 = MockBranch()
        branchBuilder.next = branch2
        jet_pt2 = events.jet_pt

        self.assertIs(branch1, jet_pt2)
        self.assertIsNot(branch2, jet_pt2)

        it = iter(events)
        event = next(it)

        branch3 = MockBranch()
        branchBuilder.next = branch3
        jet_pt3 = event.jet_pt

        self.assertIs(branch1, jet_pt3)
        self.assertIsNot(branch3, jet_pt3)
Пример #4
0
def test_getattr_exception():
    tree = MockTree()
    events = Events(tree)
    events.buildBranch = MockBranchBuilder()

    with pytest.raises(AttributeError):
        events.no_such_branch
Пример #5
0
def test_getattr_exception():
    tree = MockTree()
    events = Events(tree)
    events.buildBranch = MockBranchBuilder()

    with pytest.raises(AttributeError):
        events.no_such_branch
Пример #6
0
 def __call__(self):
     chain = ROOT.TChain(self.config.treeName)
     for path in self.config.inputPaths:
         path = convert_lfn_to_pfn_or_aaa(path)
         chain.Add(path)
     events = BEvents(chain, self.config.maxEvents, self.config.start)
     events.config = self.config
     return events
Пример #7
0
def test_getattr():
    tree = MockTree()
    events = Events(tree)
    branchBuilder = MockBranchBuilder()
    events.buildBranch = branchBuilder

    branchBuilder.next = MockBranch()
    jet_pt = events.jet_pt
    assert isinstance(jet_pt, MockBranch)
Пример #8
0
    def test_getattr(self):
        tree = MockTree()
        events = BEvents(tree)
        branchBuilder = MockBranchBuilder()
        events.buildBranch = branchBuilder

        branchBuilder.next = MockBranch()
        jet_pt = events.jet_pt
        self.assertIsInstance(jet_pt, MockBranch)
Пример #9
0
def test_getattr():
    tree = MockTree()
    events = Events(tree)
    branchBuilder = MockBranchBuilder()
    events.buildBranch = branchBuilder

    branchBuilder.next = MockBranch()
    jet_pt = events.jet_pt
    assert isinstance(jet_pt, MockBranch)
Пример #10
0
    def test_pass_arguments_to_base_class(self):
        tree = MockTree(entries=1000)
        events = BEvents(tree, 100)
        self.assertEqual(100, events.nEvents)
        self.assertEqual(0, events.start)

        events = BEvents(tree, 100, 20)
        self.assertEqual(100, events.nEvents)
        self.assertEqual(20, events.start)
Пример #11
0
def test_getattr_getentry():
    tree = MockTree()
    events = Events(tree, start=10)
    branchBuilder = MockBranchBuilder()
    events.buildBranch = branchBuilder

    assert -1 == events.iEvent
    assert -1 == tree.ievent
    assert not tree.getEntry_called
    branchBuilder.next = MockBranch()
    jet_pt = events.jet_pt
    assert not tree.getEntry_called

    it = iter(events)
    event = next(it)
    tree.getEntry_called = False
    assert 0 == events.iEvent
    assert 10 == tree.ievent
    assert not tree.getEntry_called
    jet_pt = event.jet_pt
    assert not tree.getEntry_called

    tree.getEntry_called = False
    met_pt = event.met_pt
    assert tree.getEntry_called
    assert 0 == events.iEvent
    assert 10 == tree.ievent

    event = next(it)
    tree.getEntry_called = False
    assert 1 == events.iEvent
    assert 11 == tree.ievent
    assert not tree.getEntry_called
    jet_pt = event.jet_pt
    assert not tree.getEntry_called

    tree.getEntry_called = False
    met_pt = event.met_pt
    assert not tree.getEntry_called
    assert 1 == events.iEvent
    assert 11 == tree.ievent

    tree.getEntry_called = False
    njets = event.njets
    assert tree.getEntry_called
    assert 1 == events.iEvent
    assert 11 == tree.ievent
Пример #12
0
def test_getattr_getentry():
    tree = MockTree()
    events = Events(tree, start=10)
    branchBuilder = MockBranchBuilder()
    events.buildBranch = branchBuilder

    assert -1 == events.iEvent
    assert -1 == tree.ievent
    assert not tree.getEntry_called
    branchBuilder.next = MockBranch()
    jet_pt = events.jet_pt
    assert not tree.getEntry_called

    it = iter(events)
    event = next(it)
    tree.getEntry_called = False
    assert 0 == events.iEvent
    assert 10 == tree.ievent
    assert not tree.getEntry_called
    jet_pt = event.jet_pt
    assert not tree.getEntry_called

    tree.getEntry_called = False
    met_pt = event.met_pt
    assert tree.getEntry_called
    assert 0 == events.iEvent
    assert 10 == tree.ievent

    event = next(it)
    tree.getEntry_called = False
    assert 1 == events.iEvent
    assert 11 == tree.ievent
    assert not tree.getEntry_called
    jet_pt = event.jet_pt
    assert not tree.getEntry_called

    tree.getEntry_called = False
    met_pt = event.met_pt
    assert not tree.getEntry_called
    assert 1 == events.iEvent
    assert 11 == tree.ievent

    tree.getEntry_called = False
    njets = event.njets
    assert tree.getEntry_called
    assert 1 == events.iEvent
    assert 11 == tree.ievent
Пример #13
0
    def test_getattr_getentry(self):
        tree = MockTree()
        events = BEvents(tree, start=10)
        branchBuilder = MockBranchBuilder()
        events.buildBranch = branchBuilder

        self.assertEqual(-1, events.iEvent)
        self.assertEqual(-1, tree.ievent)
        self.assertFalse(tree.getEntry_called)
        branchBuilder.next = MockBranch()
        jet_pt = events.jet_pt
        self.assertFalse(tree.getEntry_called)

        it = iter(events)
        event = next(it)
        tree.getEntry_called = False
        self.assertEqual(0, events.iEvent)
        self.assertEqual(10, tree.ievent)
        self.assertFalse(tree.getEntry_called)
        jet_pt = event.jet_pt
        self.assertFalse(tree.getEntry_called)

        tree.getEntry_called = False
        met_pt = event.met_pt
        self.assertTrue(tree.getEntry_called)
        self.assertEqual(0, events.iEvent)
        self.assertEqual(10, tree.ievent)

        event = next(it)
        tree.getEntry_called = False
        self.assertEqual(1, events.iEvent)
        self.assertEqual(11, tree.ievent)
        self.assertFalse(tree.getEntry_called)
        jet_pt = event.jet_pt
        self.assertFalse(tree.getEntry_called)

        tree.getEntry_called = False
        met_pt = event.met_pt
        self.assertFalse(tree.getEntry_called)
        self.assertEqual(1, events.iEvent)
        self.assertEqual(11, tree.ievent)

        tree.getEntry_called = False
        njets = event.njets
        self.assertTrue(tree.getEntry_called)
        self.assertEqual(1, events.iEvent)
        self.assertEqual(11, tree.ievent)
Пример #14
0
def use_BEvents():
    inputFile = ROOT.TFile.Open(inputPath)
    tree = inputFile.Get(treeName)
    events = BEvents(tree)
    jet_pt = events.jet_pt
    for event in events:
        for i in range(len(jet_pt)):
            jet_pt[i]
Пример #15
0
def use_BEvents():
    inputFile = ROOT.TFile.Open(inputPath)
    tree = inputFile.Get(treeName)
    events = BEvents(tree)
    jet_pt = events.jet_pt
    trigger_path = events.trigger_path
    trigger_version = events.trigger_version
    for event in events:
        for i in range(len(jet_pt)):
            jet_pt[i]
Пример #16
0
 def test_init_branch_status(self):
     tree = MockTree()
     self.assertEqual([], tree.branchstatus)
     events = BEvents(tree)
     events.buildBranch = MockBranchBuilder()
     self.assertEqual([('*', 0)], tree.branchstatus)
Пример #17
0
def test_init_branch_status():
    tree = MockTree()
    assert [] == tree.branchstatus
    events = Events(tree)
    events.buildBranch = MockBranchBuilder()
    assert [('*', 0)] == tree.branchstatus
Пример #18
0
def test_init_branch_status():
    tree = MockTree()
    assert [ ] == tree.branchstatus
    events = Events(tree)
    events.buildBranch = MockBranchBuilder()
    assert [('*', 0)] == tree.branchstatus
Пример #19
0
 def test_repr(self):
     tree = MockTree()
     events = BEvents(tree)
     repr(events)
Пример #20
0
    def test_getattr_exception(self):
        tree = MockTree()
        events = BEvents(tree)
        events.buildBranch = MockBranchBuilder()

        self.assertRaises(AttributeError, events.__getattr__, 'no_such_branch')