Skip to content

Commit

Permalink
Make test smaller
Browse files Browse the repository at this point in the history
The use of a controller was causing failures in some places.
  • Loading branch information
gselzer committed Jan 17, 2025
1 parent 855d00e commit a653af7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Callable, cast, no_type_check
from typing import Any, Callable, cast, no_type_check
from unittest.mock import MagicMock, Mock, patch

import numpy as np
import pytest

from ndv._types import MouseMoveEvent
from ndv.controllers import ArrayViewer
from ndv.controllers._channel_controller import ChannelController
from ndv.models._array_display_model import ArrayDisplayModel, ChannelMode
from ndv.models._lut_model import ClimsManual, ClimsMinMax, LUTModel
from ndv.views import _app, gui_frontend
from ndv.views.bases import ArrayView, LutView
from ndv.views.bases._graphics._canvas import ArrayCanvas, HistogramCanvas
from ndv.views.bases._graphics._canvas_elements import ImageHandle

if TYPE_CHECKING:
from ndv.controllers._channel_controller import ChannelController


def _get_mock_canvas() -> ArrayCanvas:
mock = MagicMock(spec=ArrayCanvas)
Expand Down Expand Up @@ -206,19 +204,22 @@ def test_array_viewer_with_app() -> None:

@pytest.mark.usefixtures("any_app")
def test_channel_autoscale() -> None:
ctrl = ChannelController(key=None, lut_model=LUTModel(), views=[])

# NB: Use a planar dataset so we can manually compute the min/max
data = np.random.randint(0, 255, size=(10, 10), dtype="uint8")
mi, ma = np.nanmin(data), np.nanmax(data)
viewer = ArrayViewer(data)
handle = MagicMock(spec=ImageHandle)
handle.data.return_value = data
ctrl.add_handle(handle)

# Test some random LutController
lut_ctrl = next(iter(viewer._lut_controllers.values()))
lut_model = lut_ctrl.lut_model
lut_model = ctrl.lut_model
lut_model.clims = ClimsManual(min=1, max=2)

# Ensure newly added lut views have the correct clims
mock_viewer = MagicMock(LutView)
lut_ctrl.add_lut_view(mock_viewer)
ctrl.add_lut_view(mock_viewer)
mock_viewer.set_clims.assert_called_once_with((1, 2))

# Ensure autoscaling sets the clims
Expand Down

0 comments on commit a653af7

Please sign in to comment.