Skip to content

Commit a67d7fe

Browse files
committed
Update PixelMaskCollection tests to use real EITData
1 parent 5bac9b0 commit a67d7fe

1 file changed

Lines changed: 13 additions & 25 deletions

File tree

tests/test_pixelmask_collection.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from collections.abc import Callable
2-
from unittest.mock import MagicMock
32

43
import numpy as np
54
import pytest
65

76
from eitprocessing.datahandling.eitdata import EITData
87
from eitprocessing.datahandling.pixelmap import PixelMap
98
from eitprocessing.datahandling.sequence import Sequence
10-
from eitprocessing.roi import PixelMask
9+
from eitprocessing.roi import PixelMask, get_geometric_mask
1110
from eitprocessing.roi.pixelmaskcollection import PixelMaskCollection
1211

1312

@@ -331,36 +330,25 @@ def test_apply_unsupported_type():
331330
assert "Unsupported data type" in str(excinfo.value)
332331

333332

334-
def test_apply_to_eitdata_branch():
335-
# Create a MagicMock that is recognized as an instance of EITData
336-
eit_data_mock = MagicMock(spec=EITData)
337-
eit_data_mock.pixel_impedance = np.array([[1.0, 2.0], [3.0, 4.0]])
338-
339-
# Ensure .apply() on a PixelMask returns an EITData instance (or mock)
340-
def mock_apply(
341-
_self: "PixelMaskCollection",
342-
_data: "EITData | np.ndarray | PixelMap",
343-
*,
344-
_label: str | None = None,
345-
**_kwargs: object,
346-
) -> EITData:
347-
"""Mock apply method for PixelMaskCollection."""
348-
return MagicMock(spec=EITData)
349-
350-
# Patch PixelMask.apply for this test
351-
PixelMask.apply = mock_apply
352-
353-
pm1 = PixelMask([[True, False], [False, True]], label="mask1")
354-
pm2 = PixelMask([[True, True], [False, False]], label="mask2")
333+
def test_apply_to_eitdata(draeger1: Sequence):
334+
eit_data = draeger1.eit_data["raw"]
335+
pm1 = get_geometric_mask("ventral")
336+
pm2 = get_geometric_mask("dorsal")
355337

356338
collection = PixelMaskCollection([pm1, pm2])
357339

358-
result = collection.apply(eit_data_mock)
340+
result = collection.apply(eit_data)
359341

360342
assert isinstance(result, dict)
361-
assert set(result.keys()) == {"mask1", "mask2"}
343+
assert set(result.keys()) == {"ventral", "dorsal"}
362344
assert all(isinstance(v, EITData) for v in result.values())
363345

346+
assert np.all(np.isnan(result["ventral"].pixel_impedance[:, 16:, :])), "All dorsal pixels should be NaN"
347+
assert np.any(~np.isnan(result["ventral"].pixel_impedance[:, :16, :])), "Some venttral pixels should not be NaN"
348+
349+
assert np.all(np.isnan(result["dorsal"].pixel_impedance[:, :16, :])), "All ventral pixels should be NaN"
350+
assert np.any(~np.isnan(result["dorsal"].pixel_impedance[:, 16:, :])), "Some dorsal pixels should not be NaN"
351+
364352

365353
def test_empty_collection_behavior():
366354
# Allow emtpy collection initialization

0 commit comments

Comments
 (0)