示例#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_exception():
    tree = MockTree()
    events = Events(tree)
    events.buildBranch = MockBranchBuilder()

    with pytest.raises(AttributeError):
        events.no_such_branch
示例#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_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
示例#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 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)
示例#7
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)
示例#8
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)
示例#9
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
示例#10
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)
示例#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_init_branch_status():
    tree = MockTree()
    assert [] == tree.branchstatus
    events = Events(tree)
    events.buildBranch = MockBranchBuilder()
    assert [('*', 0)] == tree.branchstatus
示例#13
0
 def test_init_branch_status(self):
     tree = MockTree()
     self.assertEqual([], tree.branchstatus)
     events = BEvents(tree)
     events.buildBranch = MockBranchBuilder()
     self.assertEqual([('*', 0)], tree.branchstatus)
示例#14
0
    def test_getattr_exception(self):
        tree = MockTree()
        events = BEvents(tree)
        events.buildBranch = MockBranchBuilder()

        self.assertRaises(AttributeError, events.__getattr__, 'no_such_branch')
示例#15
0
def test_init_branch_status():
    tree = MockTree()
    assert [ ] == tree.branchstatus
    events = Events(tree)
    events.buildBranch = MockBranchBuilder()
    assert [('*', 0)] == tree.branchstatus