Skip to content

Commit 725b0d7

Browse files
committed
WIP
1 parent 4fdd2a6 commit 725b0d7

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

tests/test_controller.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ndv.controllers import ArrayViewer
1313
from ndv.models._array_display_model import ArrayDisplayModel, ChannelMode
1414
from ndv.models._lut_model import LUTModel
15+
from ndv.models._roi_model import RectangularROIModel
1516
from ndv.views import _app, gui_frontend
1617
from ndv.views.bases import ArrayView, LutView
1718
from ndv.views.bases._graphics._canvas import ArrayCanvas, HistogramCanvas
@@ -21,7 +22,7 @@
2122
from ndv.controllers._channel_controller import ChannelController
2223

2324

24-
def _get_mock_canvas() -> ArrayCanvas:
25+
def _get_mock_canvas(*_: Any) -> ArrayCanvas:
2526
mock = MagicMock(spec=ArrayCanvas)
2627
img_handle = MagicMock(spec=ImageHandle)
2728
img_handle.data.return_value = np.zeros((10, 10)).astype(np.uint8)
@@ -205,3 +206,18 @@ def test_array_viewer_with_app() -> None:
205206
if gui_frontend() != _app.GuiFrontend.WX:
206207
visax_mock.assert_called_once()
207208
assert viewer.display_model.visible_axes == (0, -2, -1)
209+
210+
211+
@no_type_check
212+
@_patch_views
213+
def test_roi_controller() -> None:
214+
ctrl = ArrayViewer()
215+
216+
# Until a user interacts with ctrl.roi, there is no ROI model
217+
assert ctrl._roi_model is None
218+
ctrl.roi = RectangularROIModel()
219+
assert ctrl._roi_model is not None
220+
ctrl.roi = None
221+
assert ctrl._roi_model is None
222+
223+
# Clicking the ROI button and then clicking the canvas creates a ROI

tests/test_models.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest.mock import Mock
22

33
from ndv.models._array_display_model import ArrayDisplayModel
4+
from ndv.models._roi_model import RectangularROIModel
45

56

67
def test_array_display_model() -> None:
@@ -23,3 +24,28 @@ def test_array_display_model() -> None:
2324

2425
assert ArrayDisplayModel.model_json_schema(mode="validation")
2526
assert ArrayDisplayModel.model_json_schema(mode="serialization")
27+
28+
29+
def test_rectangular_roi_model() -> None:
30+
m = RectangularROIModel()
31+
32+
mock = Mock()
33+
m.events.bounding_box.connect(mock)
34+
m.events.visible.connect(mock)
35+
36+
m.bounding_box = ((10, 10), (20, 20))
37+
mock.assert_called_once_with(
38+
((10, 10), (20, 20)), # New bounding box value
39+
((0, 0), (0, 0)), # Initial bounding box on construction
40+
)
41+
mock.reset_mock()
42+
43+
m.visible = False
44+
mock.assert_called_once_with(
45+
False, # New visibility
46+
True, # Initial visibility on construction
47+
)
48+
mock.reset_mock()
49+
50+
assert RectangularROIModel.model_json_schema(mode="validation")
51+
assert RectangularROIModel.model_json_schema(mode="serialization")

0 commit comments

Comments
 (0)