Skip to content

Commit 482a34c

Browse files
committed
Added tests for RNTupleField
1 parent 9049d27 commit 482a34c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE
2+
3+
import pytest
4+
import skhep_testdata
5+
6+
import uproot
7+
8+
9+
def test_field_class():
10+
filename = skhep_testdata.data_path("DAOD_TRUTH3_RC2.root")
11+
with uproot.open(filename) as f:
12+
obj = f["RNT:CollectionTree"]
13+
jets = obj["AntiKt4TruthDressedWZJetsAux:"]
14+
assert len(jets) == 6
15+
16+
pt = jets["pt"]
17+
assert len(pt) == 0
18+
19+
20+
def test_array_methods():
21+
filename = skhep_testdata.data_path(
22+
"Run2012BC_DoubleMuParked_Muons_rntuple_1000evts.root"
23+
)
24+
with uproot.open(filename) as f:
25+
obj = f["Events"]
26+
nMuon_array = obj["nMuon"].array()
27+
Muon_pt_array = obj["Muon_pt"].array()
28+
assert nMuon_array.tolist() == [len(l) for l in Muon_pt_array]
29+
30+
nMuon_arrays = obj["nMuon"].arrays()
31+
assert len(nMuon_arrays.fields) == 1
32+
assert len(nMuon_arrays) == 1000
33+
assert nMuon_arrays["nMuon"].tolist() == nMuon_array.tolist()
34+
35+
filename = skhep_testdata.data_path("DAOD_TRUTH3_RC2.root")
36+
with uproot.open(filename) as f:
37+
obj = f["RNT:CollectionTree"]
38+
jets = obj["AntiKt4TruthDressedWZJetsAux:"].arrays()
39+
assert len(jets[0].pt) == 5

0 commit comments

Comments
 (0)