Esempio n. 1
0
def test_build(config, files, mockroot, mockevents):
    config['check_files'] = False
    obj = BuildEvents(config)
    mockroot.TFile.Open.side_effect = files
    events = obj()
    assert [mock.call('tree')] == mockroot.TChain.call_args_list
    chain = mockroot.TChain()
    assert [
        mock.call('/path/to/input1/tree.root'),
        mock.call('/path/to/input2/tree.root'),
    ] == chain.Add.call_args_list
    assert [mock.call(chain, 123, 11)] == mockevents.call_args_list
Esempio n. 2
0
def test_build_raise(config, files, mockroot, caplog):
    config['check_files'] = True
    config['skip_error_files'] = False
    obj = BuildEvents(config)
    mockroot.TFile.Open.side_effect = files
    if all([f.good for f in files]):
        return

    with caplog.at_level(logging.WARNING):
        with pytest.raises(OSError):
            events = obj()

    assert len(caplog.records) == 1
    assert caplog.records[0].levelname == 'ERROR'
    assert 'cannot open' in caplog.records[0].msg
Esempio n. 3
0
def test_build_skip(config, files, mockroot, mockevents, caplog):
    config['check_files'] = True
    config['skip_error_files'] = True
    obj = BuildEvents(config)
    mockroot.TFile.Open.side_effect = files
    with caplog.at_level(logging.WARNING):
        events = obj()
    assert [mock.call('tree')] == mockroot.TChain.call_args_list
    chain = mockroot.TChain()
    file_paths = [p for p, f in zip(config['file_paths'], files) if f.good]
    assert [mock.call(p) for p in file_paths] == chain.Add.call_args_list
    assert [mock.call(chain, 123, 11)] == mockevents.call_args_list

    assert len(caplog.records) == sum([not f.good for f in files])

    if all([f.good for f in files]):
        return

    assert caplog.records[0].levelname == 'WARNING'
    assert 'cannot open' in caplog.records[0].msg
Esempio n. 4
0
def obj(config, mockroot):
    return BuildEvents(config)