Skip to content

Commit b67e7be

Browse files
committed
Test controller autoscaling logic
1 parent 795bfb9 commit b67e7be

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

tests/test_controller.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ndv._types import MouseMoveEvent
1212
from ndv.controllers import ArrayViewer
1313
from ndv.models._array_display_model import ArrayDisplayModel, ChannelMode
14-
from ndv.models._lut_model import LUTModel
14+
from ndv.models._lut_model import ClimsManual, ClimsMinMax, LUTModel
1515
from ndv.views import _app, gui_frontend
1616
from ndv.views.bases import ArrayView, LutView
1717
from ndv.views.bases._graphics._canvas import ArrayCanvas, HistogramCanvas
@@ -204,21 +204,23 @@ def test_array_viewer_with_app() -> None:
204204
assert viewer.display_model.visible_axes == (0, -2, -1)
205205

206206

207-
# @pytest.mark.usefixtures("any_app")
208-
# def test_channel_autoscale() -> None:
209-
# data = np.random.randint(0, 255, size=(10, 10, 10, 10, 10), dtype="uint8")
210-
# viewer = ArrayViewer(data)
211-
212-
# lut_model = viewer._lut_controllers[None].lut_model
213-
# old_clims = lut_model.clims
214-
215-
# # Adjust the clims with autoscale off
216-
# lut_model.autoscale = False
217-
# lut_model.clims = (old_clims[0] + 1, old_clims[1] + 1)
218-
219-
# # Assert turning autoscale back on reverts the clims
220-
# lut_model.autoscale = True
221-
# assert lut_model.clims == old_clims
222-
223-
# # NB: The view is (currently) responsible for disabling autoscale when
224-
# # it moves a clim. Thus that behavior is tested for each backend.
207+
@pytest.mark.usefixtures("any_app")
208+
def test_channel_autoscale() -> None:
209+
# NB: Use a planar dataset so we can manually compute the min/max
210+
data = np.random.randint(0, 255, size=(10, 10), dtype="uint8")
211+
mi, ma = np.nanmin(data), np.nanmax(data)
212+
viewer = ArrayViewer(data)
213+
214+
lut_ctrl = viewer._lut_controllers[None]
215+
lut_model = lut_ctrl.lut_model
216+
lut_model.clims = ClimsManual(min=1, max=2)
217+
218+
# Ensure newly added lut views have the correct clims
219+
mock_viewer = MagicMock(LutView)
220+
lut_ctrl.add_lut_view(mock_viewer)
221+
mock_viewer.set_clims.assert_called_once_with((1, 2))
222+
223+
# Ensure autoscaling sets the clims
224+
mock_viewer.set_clims.reset_mock()
225+
lut_model.clims = ClimsMinMax()
226+
mock_viewer.set_clims.assert_called_once_with((mi, ma))

0 commit comments

Comments
 (0)