def test_register_tree(self): builder = BranchBuilder() tree = MockTree() builder.register_tree(tree) self.assertEqual([('*', 0)], tree.branchstatus)
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
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)
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
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
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)
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
def test_repr(): obj = BranchBuilder() repr(obj)
def test_call_no_such_branch(mockTree): obj = BranchBuilder() obj.register_tree(mockTree) result = obj(mockTree, 'no_such_branch') assert result is None
def test_call_stdvector(mockTree): obj = BranchBuilder() obj.register_tree(mockTree) result = obj(mockTree, 'trigger_path') assert isinstance(result, ROOT.vector('string'))
def test_repr(self): builder = BranchBuilder() repr(builder)
def test_call_ctypes(mockTree): obj = BranchBuilder() obj.register_tree(mockTree) result = obj(mockTree, 'jet_pt') assert isinstance(result, Branch)
def test_getattr_warning(self): builder = BranchBuilder() tree = MockTree() self.assertIsNone(builder(tree, 'EventAuxiliary'))
def test_getattr_None(self): builder = BranchBuilder() tree = MockTree() self.assertIsNone(builder(tree, 'no_such_branch'))
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
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
def test_init(self): builder = BranchBuilder()