|
11 | 11 | from ndv._types import MouseMoveEvent
|
12 | 12 | from ndv.controllers import ArrayViewer
|
13 | 13 | 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 |
15 | 15 | from ndv.views import _app, gui_frontend
|
16 | 16 | from ndv.views.bases import ArrayView, LutView
|
17 | 17 | from ndv.views.bases._graphics._canvas import ArrayCanvas, HistogramCanvas
|
@@ -204,21 +204,24 @@ def test_array_viewer_with_app() -> None:
|
204 | 204 | assert viewer.display_model.visible_axes == (0, -2, -1)
|
205 | 205 |
|
206 | 206 |
|
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 | + # Test some random LutController |
| 215 | + lut_ctrl = next(iter(viewer._lut_controllers.values())) |
| 216 | + lut_model = lut_ctrl.lut_model |
| 217 | + lut_model.clims = ClimsManual(min=1, max=2) |
| 218 | + |
| 219 | + # Ensure newly added lut views have the correct clims |
| 220 | + mock_viewer = MagicMock(LutView) |
| 221 | + lut_ctrl.add_lut_view(mock_viewer) |
| 222 | + mock_viewer.set_clims.assert_called_once_with((1, 2)) |
| 223 | + |
| 224 | + # Ensure autoscaling sets the clims |
| 225 | + mock_viewer.set_clims.reset_mock() |
| 226 | + lut_model.clims = ClimsMinMax() |
| 227 | + mock_viewer.set_clims.assert_called_once_with((mi, ma)) |
0 commit comments