コード例 #1
0
    def test_register_tree(self):
        builder = BranchBuilder()

        tree = MockTree()

        builder.register_tree(tree)

        self.assertEqual([('*', 0)], tree.branchstatus)
コード例 #2
0
def test_call_unknown_type(mockTree, caplog):
    obj = BranchBuilder()
    obj.register_tree(mockTree)
    with caplog.at_level(logging.WARNING):
        result = obj(mockTree, 'EventAuxiliary')
    assert result is None
    assert len(caplog.records) == 1
    assert caplog.records[0].levelname == 'WARNING'
    assert 'BranchBuilder' in caplog.records[0].name
    assert 'unknown leaf type' in caplog.records[0].msg
コード例 #3
0
    def test_getattr_same_objects_different_builders(self):

        builder1 = BranchBuilder()
        builder2 = BranchBuilder()

        tree = MockTree()
        jet_pt1 = builder1(tree, "jet_pt")
        met_pt1 = builder1(tree, "met_pt")

        jet_pt2 = builder2(tree, "jet_pt")
        met_pt2 = builder2(tree, "met_pt")

        self.assertIs(jet_pt1, jet_pt2)
        self.assertIs(met_pt1, met_pt2)
コード例 #4
0
def test_empty_chain(caplog):
    tree_name = 'tree'
    chain = ROOT.TChain(tree_name)
    # add no files to the chain

    obj = BranchBuilder()
    obj.register_tree(chain)

    with caplog.at_level(logging.WARNING):
        assert obj(chain, 'var') is None

    assert len(caplog.records) == 2
    assert caplog.records[0].levelname == 'WARNING'
    assert 'BranchBuilder' in caplog.records[0].name
    assert 'cannot get' in caplog.records[0].msg
コード例 #5
0
def test_call_ctypes_same_objects_different_builders(mockTree):
    obj1 = BranchBuilder()
    obj2 = BranchBuilder()
    obj1.register_tree(mockTree)
    obj2.register_tree(mockTree)
    result1 = obj1(mockTree, 'jet_pt')
    result2 = obj2(mockTree, 'jet_pt')
    assert result1 is result2
コード例 #6
0
    def test_getattr(self):
        builder = BranchBuilder()
        tree = MockTree()

        jet_pt = builder(tree, "jet_pt")
        met_pt = builder(tree, "met_pt")
        self.assertIsInstance(jet_pt, MockBranch)
        self.assertIsInstance(met_pt, MockBranch)
コード例 #7
0
def test_call_not_registered(mockTree, caplog):
    obj = BranchBuilder()
    with caplog.at_level(logging.WARNING):
        result = obj(mockTree, 'jet_pt')
    assert isinstance(result, Branch)
    assert len(caplog.records) == 1
    assert caplog.records[0].levelname == 'WARNING'
    assert 'BranchBuilder' in caplog.records[0].name
    assert 'tree is not registered' in caplog.records[0].msg
コード例 #8
0
def test_repr():
    obj = BranchBuilder()
    repr(obj)
コード例 #9
0
def test_call_no_such_branch(mockTree):
    obj = BranchBuilder()
    obj.register_tree(mockTree)
    result = obj(mockTree, 'no_such_branch')
    assert result is None
コード例 #10
0
def test_call_stdvector(mockTree):
    obj = BranchBuilder()
    obj.register_tree(mockTree)
    result = obj(mockTree, 'trigger_path')
    assert isinstance(result, ROOT.vector('string'))
コード例 #11
0
 def test_repr(self):
     builder = BranchBuilder()
     repr(builder)
コード例 #12
0
def test_call_ctypes(mockTree):
    obj = BranchBuilder()
    obj.register_tree(mockTree)
    result = obj(mockTree, 'jet_pt')
    assert isinstance(result, Branch)
コード例 #13
0
    def test_getattr_warning(self):
        builder = BranchBuilder()

        tree = MockTree()

        self.assertIsNone(builder(tree, 'EventAuxiliary'))
コード例 #14
0
    def test_getattr_None(self):
        builder = BranchBuilder()

        tree = MockTree()

        self.assertIsNone(builder(tree, 'no_such_branch'))
コード例 #15
0
def test_register_tree(mockTree):
    obj = BranchBuilder()
    obj.register_tree(mockTree)
    assert [mock.call('*', 0)] == mockTree.SetBranchStatus.call_args_list
    assert mockTree in obj.itsdict
コード例 #16
0
def test_register_tree_two_builders(mockTree):
    obj1 = BranchBuilder()
    obj2 = BranchBuilder()
    obj1.register_tree(mockTree)
    obj2.register_tree(mockTree)
    assert 1 == mockTree.SetBranchStatus.call_count
コード例 #17
0
 def test_init(self):
     builder = BranchBuilder()