diff --git a/napari/_tests/utils.py b/napari/_tests/utils.py index 78cb0699e6c..ecfc83e6124 100644 --- a/napari/_tests/utils.py +++ b/napari/_tests/utils.py @@ -140,6 +140,11 @@ def dtype(self) -> DTypeLike: def shape(self) -> Tuple[int, ...]: return self.data.shape + @property + def ndim(self) -> int: + # LayerDataProtocol does not have ndim, but this should be equivalent. + return len(self.data.shape) + def __getitem__( self, key: Union[Index, Tuple[Index, ...], LayerDataProtocol] ) -> LayerDataProtocol: diff --git a/napari/components/_tests/test_layer_slicer.py b/napari/components/_tests/test_layer_slicer.py index 012222c8b69..48518195269 100644 --- a/napari/components/_tests/test_layer_slicer.py +++ b/napari/components/_tests/test_layer_slicer.py @@ -11,7 +11,7 @@ from napari._tests.utils import DEFAULT_TIMEOUT_SECS, LockableData from napari.components import Dims from napari.components._layer_slicer import _LayerSlicer -from napari.layers import Image, Points +from napari.layers import Image, Labels, Points # The following fakes are used to control execution of slicing across # multiple threads, while also allowing us to mimic real classes @@ -336,6 +336,26 @@ def test_submit_with_one_3d_image(layer_slicer): np.testing.assert_equal(layer_result.image.view, data[2, :, :]) +def test_submit_with_3d_labels(layer_slicer): + np.random.seed(0) + data = np.random.randint(20, size=(8, 7, 6)) + lockable_data = LockableData(data) + layer = Labels(lockable_data, multiscale=False) + dims = Dims( + ndim=3, + ndisplay=2, + range=((0, 8, 1), (0, 7, 1), (0, 6, 1)), + point=(2, 0, 0), + ) + + with lockable_data.lock: + future = layer_slicer.submit(layers=[layer], dims=dims) + assert not future.done() + + layer_result = _wait_for_response(future)[layer] + np.testing.assert_equal(layer_result.image.view, data[2, :, :]) + + def test_submit_with_one_3d_points(layer_slicer): """ensure that async slicing of points does not block""" np.random.seed(0)