Skip to content

Commit 58129a9

Browse files
Update tests to remove unneccessary code
1 parent 4fedf5d commit 58129a9

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

tests/test_roi_size_filter.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def test_basic_region_selection():
1010
arr = np.full((5, 5), np.nan)
1111
arr[1:4, 1:4] = True
12-
mask = PixelMask(arr, keep_zeros=True)
12+
mask = PixelMask(arr)
1313
selector = FilterROIBySize(min_region_size=5, connectivity=1)
1414
result = selector.apply(mask)
1515
expected_mask = np.full(arr.shape, np.nan)
@@ -21,7 +21,7 @@ def test_region_smaller_than_threshold_is_excluded():
2121
arr = np.full((5, 5), np.nan)
2222
arr[0, 0:2] = True
2323
arr[2:4, 2:5] = True
24-
mask = PixelMask(arr, keep_zeros=True)
24+
mask = PixelMask(arr)
2525
selector = FilterROIBySize(min_region_size=5, connectivity=1)
2626
result = selector.apply(mask)
2727
expected = np.zeros_like(arr, dtype=float)
@@ -33,7 +33,7 @@ def test_region_smaller_than_threshold_is_excluded():
3333
def test_no_regions_above_threshold_raises():
3434
arr = np.full((4, 4), np.nan)
3535
arr[0, 0] = True
36-
mask = PixelMask(arr, keep_zeros=True)
36+
mask = PixelMask(arr)
3737
selector = FilterROIBySize(min_region_size=5, connectivity=1)
3838
with pytest.raises(RuntimeError, match="No regions found above min_region_size threshold"):
3939
selector.apply(mask)
@@ -43,7 +43,7 @@ def test_custom_connectivity():
4343
arr = np.full((3, 3), np.nan)
4444
arr[0, 0] = True
4545
arr[1, 1] = True
46-
mask = PixelMask(arr, keep_zeros=True)
46+
mask = PixelMask(arr)
4747

4848
# Default (1-connectivity) — should raise
4949
selector_default = FilterROIBySize(min_region_size=2, connectivity=1)
@@ -64,7 +64,7 @@ def test_custom_connectivity():
6464

6565
def test_empty_mask_raises():
6666
arr = np.full((4, 4), np.nan)
67-
mask = PixelMask(arr, keep_zeros=True)
67+
mask = PixelMask(arr)
6868
selector = FilterROIBySize(min_region_size=1, connectivity=1)
6969
with pytest.raises(RuntimeError, match="No regions found above min_region_size threshold"):
7070
selector.apply(mask)
@@ -83,15 +83,15 @@ def test_multiple_large_regions_are_all_included():
8383
arr = np.full((6, 6), np.nan)
8484
arr[0:2, 0:2] = True
8585
arr[4:6, 4:6] = True
86-
mask = PixelMask(arr, keep_zeros=True)
86+
mask = PixelMask(arr)
8787
selector = FilterROIBySize(min_region_size=4, connectivity=1)
8888
result = selector.apply(mask)
8989
assert np.sum(~np.isnan(result.mask)) == 8
9090

9191

9292
def test_all_true_mask_returns_full_mask():
9393
arr = np.ones((3, 3), dtype=bool)
94-
mask = PixelMask(arr, keep_zeros=True)
94+
mask = PixelMask(arr)
9595
selector = FilterROIBySize(min_region_size=1, connectivity=1)
9696
result = selector.apply(mask)
9797
assert np.all(result.mask == 1)
@@ -107,7 +107,7 @@ def test_edge_connected_region():
107107
arr[-1, :] = True # bottom edge
108108
arr[:, 0] = True # left edge
109109
arr[:, -1] = True # right edge
110-
mask = PixelMask(arr, keep_zeros=True)
110+
mask = PixelMask(arr)
111111
selector = FilterROIBySize(min_region_size=16, connectivity=1)
112112
result = selector.apply(mask)
113113
# There are 16 edge pixels in a 5x5 array (corners counted only once)
@@ -117,7 +117,7 @@ def test_edge_connected_region():
117117
def test_min_pixels_threshold_variation():
118118
arr = np.full((5, 5), np.nan)
119119
arr[1:3, 1:3] = True
120-
mask = PixelMask(arr, keep_zeros=True)
120+
mask = PixelMask(arr)
121121
selector = FilterROIBySize(min_region_size=4, connectivity=1)
122122
result = selector.apply(mask)
123123
assert np.sum(~np.isnan(result.mask)) == 4
@@ -130,7 +130,7 @@ def test_touching_regions_are_separated():
130130
arr = np.full((5, 5), np.nan)
131131
arr[1:3, 1:3] = True
132132
arr[3:4, 3:5] = True
133-
mask = PixelMask(arr, keep_zeros=True)
133+
mask = PixelMask(arr)
134134

135135
# Step 1: Check intermediate labeling for 1-connectivity
136136
binary_array = ~np.isnan(mask.mask)
@@ -146,7 +146,7 @@ def test_touching_regions_are_separated():
146146

147147
# Step 2: Check intermediate labeling for 2-connectivity
148148
structure2 = np.ones((3, 3), dtype=int) # 2-connectivity
149-
labeled_array2, num_features2 = ndi.label(binary_array, structure=structure2)
149+
_, num_features2 = ndi.label(binary_array, structure=structure2)
150150
assert num_features2 == 1, f"Expected 1 region for 2-connectivity, got {num_features2}"
151151

152152
selector8 = FilterROIBySize(min_region_size=6, connectivity=2)
@@ -158,7 +158,7 @@ def test_structure_input_variants():
158158
"""Test that selector.connectivity is the same for 1 and the equivalent custom array."""
159159
arr = np.full((4, 4), np.nan)
160160
arr[1:3, 1:3] = True
161-
mask = PixelMask(arr, keep_zeros=True)
161+
mask = PixelMask(arr)
162162

163163
# Integer
164164
selector_int = FilterROIBySize(min_region_size=4, connectivity=1)
@@ -176,16 +176,12 @@ def test_structure_input_variants():
176176

177177

178178
def test_invalid_connectivity_none_raises():
179-
arr = np.full((4, 4), np.nan)
180-
arr[1:3, 1:3] = True
181179
with pytest.raises(
182180
ValueError, match="Unsupported connectivity type: <class 'NoneType'>. Must be an integer or numpy array."
183181
):
184182
FilterROIBySize(min_region_size=4, connectivity=None)
185183

186184

187185
def test_invalid_connectivity_value_raises():
188-
arr = np.full((4, 4), np.nan)
189-
arr[1:3, 1:3] = True
190186
with pytest.raises(ValueError, match="Unsupported connectivity value: 3."):
191187
FilterROIBySize(min_region_size=4, connectivity=3)

0 commit comments

Comments
 (0)