Skip to content

Commit

Permalink
add a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Feb 12, 2024
1 parent 77d63b0 commit 5fe2425
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/yt_napari/_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,20 @@ class CoveringGrid(BaseModel):
fields: List[ytField] = Field(
None, description="list of fields to load for this selection"
)
left_edge: Optional[Left_Edge] = Field(
left_edge: Left_Edge = Field(
None,
description="the left edge (min x, min y, min z)",
)
right_edge: Optional[Right_Edge] = Field(
right_edge: Right_Edge = Field(
None,
description="the right edge (max x, max y, max z)",
)
level: Optional[int] = Field(0, description="Grid level to sample at")
num_ghost_zones: Optional[int] = Field(
None,
level: int = Field(0, description="Grid level to sample at")
num_ghost_zones: int = Field(
0,
description="Number of ghost zones to include",
)
rescale: Optional[bool] = Field(
False, description="rescale the final image between 0,1"
)
rescale: bool = Field(False, description="rescale the final image between 0,1")


class Slice(BaseModel):
Expand Down Expand Up @@ -116,7 +114,9 @@ class SelectionObject(_ytBaseModel):
regions: List[Region] = Field(None, description="a list of regions to load")
slices: List[Slice] = Field(None, description="a list of slices to load")
covering_grids: List[CoveringGrid] = Field(
None, description="a list of covering grids to load")
None, description="a list of covering grids to load"
)


class DataContainer(_ytBaseModel):
filename: str = Field(None, description="the filename for the dataset")
Expand Down
45 changes: 45 additions & 0 deletions src/yt_napari/_tests/test_covering_grid_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest

from yt_napari._data_model import InputModel
from yt_napari._model_ingestor import _choose_ref_layer, _process_validated_model
from yt_napari._schema_version import schema_name

jdicts = []
jdicts.append(
{
"$schema": schema_name,
"datasets": [
{
"filename": "_ytnapari_load_grid",
"selections": {
"covering_grids": [
{
"fields": [{"field_name": "density", "field_type": "gas"}],
"left_edge": {"value": (0.4, 0.4, 0.4)},
"right_edge": {"value": (0.5, 0.5, 0.5)},
"level": 0,
"rescale": 1,
}
]
},
}
],
}
)


@pytest.mark.parametrize("jdict", jdicts)
def test_covering_grid_validation(jdict):
_ = InputModel.model_validate(jdict)


@pytest.mark.parametrize("jdict", jdicts)
def test_slice_load(yt_ugrid_ds_fn, jdict):
im = InputModel.model_validate(jdict)
layer_lists, _ = _process_validated_model(im)
ref_layer = _choose_ref_layer(layer_lists)
_ = ref_layer.align_sanitize_layers(layer_lists)

im_data = layer_lists[0][0]
assert im_data.min() == 0
assert im_data.max() == 1

0 comments on commit 5fe2425

Please sign in to comment.