Skip to content

Commit

Permalink
Add tests of interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Nov 16, 2024
1 parent 6d7f661 commit 8b9c866
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ import babyyoda.yoda as yoda

## Interfaces

| Interface | Status | Examples |
| ---------------------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------- |
| [histoprint](https://github.com/scikit-hep/histoprint) || [histo1d](examples/interface/histoprint/histo1d.ipynb) |
| [mplhep](https://github.com/scikit-hep/mplhep) || [histo1d](examples/interface/mplhep/histo1d.ipynb), [histo2d](examples/interface/mplhep/histo2d.ipynb) |
| [plothist](https://github.com/scikit-hep/plothist) || Does not support UHI/PlottableProtocol, only boost-histogram |
| [uproot](https://github.com/scikit-hep/uproot) || WIP: [histo1d](examples/interface/uproot/histo1d.ipynb) |
| [hist](https://github.com/scikit-hep/hist) || [histo1d](examples/interface/hist/histo1d.ipynb), [histo2d](examples/interface/hist/histo2d.ipynb) |
| [boost-histogram](https://github.com/scikit-hep/boost-histogram) || [histo1d](examples/interface/boost-histogram/histo1d.ipynb), [histo2d](examples/interface/boost-histogram/histo2d.ipynb) |
| [cuda-histogram](https://github.com/scikit-hep/cuda-histogram) || |
| [ROOT](https://github.com/root-project/root) || |
| Interface | Status | Examples |
| ---------------------------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------ |
| [histoprint](https://github.com/scikit-hep/histoprint) || [histo1d](examples/interface/histoprint/histo1d.ipynb) |
| [mplhep](https://github.com/scikit-hep/mplhep) || [histo1d](examples/interface/mplhep/histo1d.ipynb), [histo2d](examples/interface/mplhep/histo2d.ipynb) |
| [plothist](https://github.com/scikit-hep/plothist) || Does not support UHI/PlottableProtocol, only boost-histogram |
| [uproot](https://github.com/scikit-hep/uproot) || WIP: [histo1d](examples/interface/uproot/histo1d.ipynb) |
| [hist](https://github.com/scikit-hep/hist) || [histo1d](examples/interface/hist/histo1d.ipynb), [histo2d](examples/interface/hist/histo2d.ipynb) |
| [boost-histogram](https://github.com/scikit-hep/boost-histogram) || [histo1d](examples/interface/boost-histogram/histo1d.ipynb), [histo2d](examples/interface/boost-histogram/histo2d.ipynb) |
| [cuda-histogram](https://github.com/scikit-hep/cuda-histogram) || |
| [ROOT](https://github.com/root-project/root) || |

## License

Expand Down
70 changes: 70 additions & 0 deletions tests/interface/test_boost_histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest

import babyyoda
import babyyoda.read
from babyyoda import grogu
from babyyoda.test import init_yoda

yoda, yoda_available, yoda2 = init_yoda()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
def test_boost_histogram_histo1d_v2(mod):
hists = mod("tests/test_histo1d_v2.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto1D)
v.to_boost_histogram()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
@pytest.mark.skipif(not yoda2, reason="yoda >= 2.0.0 is required")
def test_boost_histogram_histo1d_v3(mod):
hists = mod("tests/test_histo1d_v3.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto1D)
v.to_boost_histogram()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
def test_boost_histogram_histo2d_v2(mod):
hists = mod("tests/test_histo2d_v2.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto2D)
v.to_boost_histogram()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
@pytest.mark.skipif(not yoda2, reason="yoda >= 2.0.0 is required")
def test_boost_histogram_histo2d_v3(mod):
hists = mod("tests/test_histo2d_v3.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto2D)
v.to_boost_histogram()
70 changes: 70 additions & 0 deletions tests/interface/test_hist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest

import babyyoda
import babyyoda.read
from babyyoda import grogu
from babyyoda.test import init_yoda

yoda, yoda_available, yoda2 = init_yoda()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
def test_hist_histo1d_v2(mod):
hists = mod("tests/test_histo1d_v2.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto1D)
v.to_hist()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
@pytest.mark.skipif(not yoda2, reason="yoda >= 2.0.0 is required")
def test_hist_histo1d_v3(mod):
hists = mod("tests/test_histo1d_v3.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto1D)
v.to_hist()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
def test_hist_histo2d_v2(mod):
hists = mod("tests/test_histo2d_v2.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto2D)
v.to_hist()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
@pytest.mark.skipif(not yoda2, reason="yoda >= 2.0.0 is required")
def test_hist_histo2d_v3(mod):
hists = mod("tests/test_histo2d_v3.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto2D)
v.to_hist()
40 changes: 40 additions & 0 deletions tests/interface/test_histoprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest
from histoprint import print_hist

import babyyoda
import babyyoda.read
from babyyoda import grogu
from babyyoda.test import init_yoda

yoda, yoda_available, yoda2 = init_yoda()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
def test_histoprint_histo1d_v2(mod):
hists = mod("tests/test_histo1d_v2.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto1D)
print_hist(v, summary=True, title=v.title())


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
@pytest.mark.skipif(not yoda2, reason="yoda >= 2.0.0 is required")
def test_histoprint_histo1d_v3(mod):
hists = mod("tests/test_histo1d_v3.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto1D)
print_hist(v, summary=True, title=v.title())
71 changes: 71 additions & 0 deletions tests/interface/test_mplhep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import mplhep
import pytest

import babyyoda
import babyyoda.read
from babyyoda import grogu
from babyyoda.test import init_yoda

yoda, yoda_available, yoda2 = init_yoda()


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
def test_mplhep_histo1d_v2(mod):
hists = mod("tests/test_histo1d_v2.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto1D)
mplhep.histplot(v)


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
@pytest.mark.skipif(not yoda2, reason="yoda >= 2.0.0 is required")
def test_mplhep_histo1d_v3(mod):
hists = mod("tests/test_histo1d_v3.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto1D)
mplhep.histplot(v)


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
def test_mplhep_histo2d_v2(mod):
hists = mod("tests/test_histo2d_v2.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto2D)
mplhep.hist2dplot(v)


@pytest.mark.parametrize(
"mod",
[
babyyoda.read,
grogu.read,
yoda.read,
],
)
@pytest.mark.skipif(not yoda2, reason="yoda >= 2.0.0 is required")
def test_mplhep_histo2d_v3(mod):
hists = mod("tests/test_histo2d_v3.yoda")
for _, v in hists.items():
assert isinstance(v, babyyoda.histo1d.UHIHisto2D)
mplhep.hist2dplot(v)

0 comments on commit 8b9c866

Please sign in to comment.