Skip to content

Commit

Permalink
Improve Python test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Radonirinaunimi committed Nov 5, 2024
1 parent 5ab2b87 commit 5c3bf0e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
53 changes: 48 additions & 5 deletions pineappl_py/tests/test_boc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest
from pineappl.boc import Channel, Kinematics, Order, ScaleFuncForm


Expand All @@ -10,11 +11,53 @@ def test_init(self):


class TestKinematics:
def test_init(self):
kin = Kinematics.Scale(0)
scale_func = ScaleFuncForm.Scale(0)
assert isinstance(kin, Kinematics)
assert isinstance(scale_func, ScaleFuncForm)
@pytest.mark.parametrize(
"kintype, argument, expected_type",
[
("Scale", 0, Kinematics),
("Scale", 1, Kinematics),
("Scale", 2, Kinematics),
("X", 0, Kinematics),
("X", 1, Kinematics),
("X", 2, Kinematics),
],
)
def test_init(self, kintype: str, argument: int, expected_type: Kinematics):
kin_method = getattr(Kinematics, kintype)
result = kin_method(argument)
assert isinstance(result, expected_type)


class TestScaleFuncForm:
@pytest.mark.parametrize(
"scaletype, argument, expected_type",
[
("NoScale", [0], ScaleFuncForm),
("Scale", [0], ScaleFuncForm),
("QuadraticSum", [0, 1], ScaleFuncForm),
("QuadraticMean", [0, 1], ScaleFuncForm),
("QuadraticSumOver4", [0, 1], ScaleFuncForm),
("LinearMean", [0, 1], ScaleFuncForm),
("LinearSum", [0, 1], ScaleFuncForm),
("ScaleMax", [0, 1], ScaleFuncForm),
("ScaleMin", [0, 1], ScaleFuncForm),
("Prod", [0, 1], ScaleFuncForm),
("S2plusS1half", [0, 1], ScaleFuncForm),
("Pow4Sum", [0, 1], ScaleFuncForm),
("WgtAvg", [0, 1], ScaleFuncForm),
("S2plusS1fourth", [0, 1], ScaleFuncForm),
("ExpProd2", [0, 1], ScaleFuncForm),
],
)
def test_init(
self,
scaletype: ScaleFuncForm,
argument: list,
expected_type: ScaleFuncForm,
):
scale_method = getattr(ScaleFuncForm, scaletype)
result = scale_method(*argument)
assert isinstance(result, expected_type)


class TestOrder:
Expand Down
5 changes: 4 additions & 1 deletion pineappl_py/tests/test_subgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ def fake_importonlysubgrid(self, nb_dim: int = 2) -> tuple:
return subgrid, [*x_grids, scale, array]

def test_subgrid_methods(self, fake_grids):
# TODO: extract the values of the scales and x grids
grid = self.fake_grid(fake_grids)
test_subgrid, infos = self.fake_importonlysubgrid()
x1s, x2s, mu2s, _ = (obj for obj in infos)
grid.set_subgrid(0, 0, 0, test_subgrid.into())
extr_subgrid = grid.subgrid(0, 0, 0)
assert isinstance(extr_subgrid, SubgridEnum)

# Check that the subgrid can be scaled
extr_subgrid.scale(factor=100)
assert isinstance(extr_subgrid.into(), SubgridEnum)

@pytest.mark.parametrize("nb_dim", [1, 2, 3, 4])
def test_subgrid_arrays(self, nb_dim):
"""This simply checks that the commands run without raising any
Expand Down

0 comments on commit 5c3bf0e

Please sign in to comment.