Skip to content

Commit

Permalink
fix: test imports (#43)
Browse files Browse the repository at this point in the history
* adjusted tests

* formatting
  • Loading branch information
zbilodea authored Jan 18, 2024
1 parent 0bc85c7 commit a3be06b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
21 changes: 11 additions & 10 deletions tests/test_copy_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
def test_copy():
od.copy_root(
"/Users/zobil/Documents/odapt/tests/samples/copy.root",
data_path("uproot-HZZ.root"),
skhep_testdata.data_path("uproot-HZZ.root"),
counter_name=lambda counted: "N" + counted,
)
od_file = uproot.open("/Users/zobil/Documents/odapt/tests/samples/copy.root")
file = uproot.open(data_path("uproot-HZZ.root"))
file = uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))

print(file["events"].keys())
for key in od_file["events"].keys():
assert key in file["events"].keys()
Expand All @@ -23,11 +24,12 @@ def test_copy():
def test_drop_branch():
od.copy_root(
"/Users/zobil/Documents/odapt/tests/samples/drop_branches.root",
data_path("uproot-HZZ.root"),
skhep_testdata.data_path("uproot-HZZ.root"),
drop_branches=["MClepton_py", "Jet_Px"],
counter_name=lambda counted: "N" + counted,
)
original = uproot.open(data_path("uproot-HZZ.root"))
original = uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))

file = uproot.open("/Users/zobil/Documents/odapt/tests/samples/drop_branches.root")
assert "MClepton_py" not in file["events"]
assert "Jet_Px" not in file["events"]
Expand All @@ -43,7 +45,7 @@ def test_drop_branch():
def test_add_branch():
od.copy_root(
"/Users/zobil/Documents/odapt/tests/samples/drop_branches.root",
data_path("uproot-HZZ.root"),
skhep_testdata.data_path("uproot-HZZ.root"),
drop_branches=["MClepton_py", "Jet_Px"],
counter_name=lambda counted: "N" + counted,
)
Expand Down Expand Up @@ -71,20 +73,19 @@ def test_add_branch():
def test_hepdata_example():
od.copy_root(
"/Users/zobil/Documents/odapt/tests/samples/copy_hepdata.root",
data_path("uproot-hepdata-example.root"),
skhep_testdata.data_path("uproot-hepdata-example.root"),
counter_name=lambda counted: "N" + counted,
)
od_file = uproot.open(
"/Users/zobil/Documents/odapt/tests/samples/copy_hepdata.root"
)
file = uproot.open(data_path("uproot-hepdata-example.root"))
file = uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root"))

print(file["hprof"].classname)
print(od_file.classnames())
for key in od_file.keys(cycle=False):
assert key in file.keys(cycle=False)
print(key)
if key == "hpxpy":
for array in od_file[key].values():
assert (
array in file[key].values()
) # did check if this works and it does
assert array in file[key].values()
14 changes: 9 additions & 5 deletions tests/test_parquet_to_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@


def test_hepdata():
arrays = uproot.open(data_path("uproot-hepdata-example.root"))["ntuple;1"].arrays()
arrays = uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root"))[
"ntuple;1"
].arrays()

ak.to_parquet(arrays, "uproot-hepdata-example.parquet")
parquet_to_root(
"uproot-hepdata-example.root", "uproot-hepdata-example.parquet", name="ntuple"
)
test = uproot.open("uproot-hepdata-example.root")
original = uproot.open(data_path("uproot-hepdata-example.root"))
original = uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root"))

for key in original["ntuple"].keys():
assert key in test["ntuple"].keys()
for key in test["ntuple"].keys():
Expand All @@ -23,7 +27,8 @@ def test_hepdata():


def test_hzz():
file = uproot.open(data_path("uproot-HZZ.root"))
file = uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))

tree = file["events"]
groups = []
count_branches = []
Expand Down Expand Up @@ -79,8 +84,7 @@ def test_hzz():
counter_name=lambda counted: "N" + counted,
)
test = uproot.open("tests/samples/parquet_HZZ.root")

original = uproot.open(data_path("uproot-HZZ.root"))
original = uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))

for key in original["events"].keys():
assert key in test["events"].keys()
Expand Down
27 changes: 20 additions & 7 deletions tests/test_root_to_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ def HZZ_test():
f = uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))
original = f["events"].arrays()
od.root_to_parquet(
input_file=skhep_testdata.data_path("uproot-HZZ.root"),
output_file="test.parquet",
in_file=skhep_testdata.data_path("uproot-HZZ.root"),
out_file="test.parquet",
step_size="100 MB",
)
from_parquet = ak.from_parquet("/Users/zobil/Documents/odapt/test.parquet")
for key in f["events"].keys():
assert ak.all(from_parquet[0][key] == original[key])


def specify_tree():
f = uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))
original = f["events"].arrays()
od.root_to_parquet(
in_file=skhep_testdata.data_path("uproot-HZZ.root"),
out_file="test.parquet",
tree="events",
step_size="100 MB",
)
from_parquet = ak.from_parquet("/Users/zobil/Documents/odapt/test.parquet")
Expand All @@ -23,8 +37,8 @@ def Zmumu_test():
f = uproot.open(skhep_testdata.data_path("uproot-Zmumu.root"))
original = f["events"].arrays()
od.root_to_parquet(
input_file=skhep_testdata.data_path("uproot-Zmumu.root"),
output_file="test1.parquet",
in_file=skhep_testdata.data_path("uproot-Zmumu.root"),
out_file="test1.parquet",
step_size="100 MB",
)
from_parquet = ak.from_parquet("/Users/zobil/Documents/odapt/test1.parquet")
Expand All @@ -35,11 +49,10 @@ def Zmumu_test():
def break_trees():
with pytest.raises(AttributeError):
od.root_to_parquet(
input_file=skhep_testdata.data_path("uproot-hepdata-example.root"),
output_file="test2.parquet",
in_file=skhep_testdata.data_path("uproot-hepdata-example.root"),
out_file="test2.parquet",
step_size="100 MB",
)
# with pytest.raises(AttributeError):


break_trees()

0 comments on commit a3be06b

Please sign in to comment.