Skip to content

Commit

Permalink
Merge pull request #66 from neutrinoceros/hotfix_recipe_validation
Browse files Browse the repository at this point in the history
BUG: fix boundary recipe validation for functools.partial recipes
  • Loading branch information
neutrinoceros authored Nov 17, 2022
2 parents e0f59ae + 4e9cba8 commit 0a03dcf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gpgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from .api import load

__version__ = "0.7.1"
__version__ = "0.7.2"
4 changes: 3 additions & 1 deletion gpgi/_boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def _validate_recipe(recipe: BoundaryRecipeT) -> None:
import inspect

sig = inspect.signature(recipe)
params = list(sig.parameters)
params = [
name for name, p in sig.parameters.items() if p.default == inspect._empty
]
if params != [
"same_side_active_layer",
"same_side_ghost_layer",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ requires = [

[project]
name = "gpgi"
version = "0.7.1"
version = "0.7.2"
description = "A Generic Particle+Grid Interface"
authors = [
{ name = "C.M.T. Robert" },
Expand Down
36 changes: 36 additions & 0 deletions tests/test_deposit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from copy import deepcopy
from functools import partial

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -539,3 +540,38 @@ def test_warn_unused_weight_field_boundaries(sample_2D_dataset):
method="ngp",
weight_field_boundaries={"x": ("periodic", "periodic")},
)


def test_partial_boundary():
def _base_recipe(
same_side_active_layer,
same_side_ghost_layer,
opposite_side_active_layer,
opposite_side_ghost_layer,
weight_same_side_active_layer,
weight_same_side_ghost_layer,
weight_opposite_side_active_layer,
weight_opposite_side_ghost_layer,
side,
metadata,
*,
mode, # suplementary argument that is destined to be frozen with functools.partial
):
# the return value doesn't matter, this test checks that
# recipe validation doesn't fail
return same_side_active_layer # pragma: no cover

myrecipe = partial(_base_recipe, mode="test")

# define a minimal single-use dataset
ds = gpgi.load(
geometry="cartesian",
grid={
"cell_edges": {
"x": np.linspace(0, 10, 11),
"y": np.linspace(0, 10, 11),
"z": np.linspace(0, 10, 11),
},
},
)
ds.boundary_recipes.register("my", myrecipe, skip_validation=False)

0 comments on commit 0a03dcf

Please sign in to comment.