Skip to content

Commit

Permalink
Reject CropParams with an empty ROI list
Browse files Browse the repository at this point in the history
  • Loading branch information
multimeric committed Dec 20, 2023
1 parent 1868666 commit 6a988a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/lls_core/models/crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def read_roi(cls, v: Any) -> List[Roi]:
except:
raise ValueError(f"{item} cannot be intepreted as an ROI")

if len(rois) == 0:
raise ValueError("At least one region of interest must be specified if cropping is enabled")

return rois

@validator("roi_subset", pre=True, always=True)
Expand Down
1 change: 0 additions & 1 deletion core/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def assert_h5(output_dir: Path):
[["--save-type", "h5"], assert_h5],
[["--save-type", "tiff"], assert_tiff],
[["--save-type", "tiff", "--time-start", "0", "--time-end", "1"], assert_tiff],
[["--save-type", "tiff", "--z-start", "0", "--z-end", "1"], assert_tiff],
]
)
def test_batch_deskew(flags: List[str], check_fn: Callable[[Path], None]):
Expand Down
11 changes: 10 additions & 1 deletion core/tests/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path
from lls_core.models.crop import CropParams
from lls_core.models.lattice_data import LatticeData
import pytest
from pydantic import ValidationError

def test_default_save_dir(rbc_tiny: Path):
# Test that the save dir is inferred to be the input dir
Expand All @@ -11,6 +13,13 @@ def test_auto_z_range(rbc_tiny: Path):
# Tests that the Z range is automatically set, and it is set
# based on the size of the deskewed volume
params = LatticeData(input_image=rbc_tiny, crop=CropParams(
roi_list=[]
roi_list=[[[0, 0], [0, 1], [1, 0], [1, 1]]]
))
assert params.crop.z_range == (0, 59)

def test_reject_crop():
# Tests that the parameters fail validation if cropping is specified without an ROI
with pytest.raises(ValidationError):
CropParams(
roi_list=[]
)

0 comments on commit 6a988a6

Please sign in to comment.