Skip to content

Commit

Permalink
Stop using temporary directory for store array for paint test (#6191)
Browse files Browse the repository at this point in the history
# References and relevant issues

This is followup to #6112 

# Description

Here I changed to use in-memory storage for paint test (not to perform
disc operations).
  • Loading branch information
Czaki committed Sep 13, 2023
1 parent c34a6cd commit f19b262
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions napari/_vispy/_tests/test_vispy_labels_layer.py
Expand Up @@ -7,40 +7,39 @@
from napari.utils.interactions import mouse_press_callbacks


def make_labels_layer(array_type, path, shape):
def make_labels_layer(array_type, shape):
"""Make a labels layer, either NumPy, zarr, or tensorstore."""
chunks = tuple(s // 2 for s in shape)
if array_type == 'numpy':
labels = np.zeros(shape, dtype=np.uint32)
elif array_type in {'zarr', 'tensorstore'}:
labels = zarr.open(path, shape=shape, dtype=np.uint32, chunks=chunks)
if array_type == 'tensorstore':
elif array_type == 'zarr':
labels = zarr.zeros(shape=shape, dtype=np.uint32, chunks=chunks)
elif array_type == 'tensorstore':
ts = pytest.importorskip('tensorstore')
spec = {
'driver': 'zarr',
'kvstore': {'driver': 'file', 'path': str(path)},
'path': '',
'metadata': {
'dtype': labels.dtype.str,
'order': labels.order,
'shape': labels.shape,
},
'kvstore': {'driver': 'memory'},
"metadata": {"chunks": chunks},
}
labels = ts.open(spec, create=False, open=True).result()
labels = ts.open(
spec, create=True, dtype="uint32", shape=shape
).result()
else:
pytest.fail("array_type must be 'numpy', 'zarr', or 'tensorstore'")

return labels


@skip_local_popups
@pytest.mark.parametrize('array_type', ['numpy', 'zarr', 'tensorstore'])
def test_labels_painting(make_napari_viewer, array_type, tmp_path):
def test_labels_painting(make_napari_viewer, array_type):
"""Check that painting labels paints on the canvas.
This should work regardless of array type. See:
https://github.com/napari/napari/issues/6079
"""
viewer = make_napari_viewer(show=True)
labels = make_labels_layer(array_type, tmp_path, shape=(20, 20))
labels = make_labels_layer(array_type, shape=(20, 20))
layer = viewer.add_labels(labels)
QCoreApplication.instance().processEvents()
layer.paint((10, 10), 1, refresh=True)
Expand All @@ -50,14 +49,14 @@ def test_labels_painting(make_napari_viewer, array_type, tmp_path):

@skip_local_popups
@pytest.mark.parametrize('array_type', ['numpy', 'zarr', 'tensorstore'])
def test_labels_fill_slice(make_napari_viewer, array_type, tmp_path):
def test_labels_fill_slice(make_napari_viewer, array_type):
"""Check that painting labels paints only on current slice.
This should work regardless of array type. See:
https://github.com/napari/napari/issues/6079
"""
viewer = make_napari_viewer(show=True)
labels = make_labels_layer(array_type, tmp_path, shape=(3, 20, 20))
labels = make_labels_layer(array_type, shape=(3, 20, 20))
labels[0, :, :] = 1
labels[1, 10, 10] = 1
labels[2, :, :] = 1
Expand All @@ -72,15 +71,15 @@ def test_labels_fill_slice(make_napari_viewer, array_type, tmp_path):
@skip_local_popups
@pytest.mark.parametrize('array_type', ['numpy', 'zarr', 'tensorstore'])
def test_labels_painting_with_mouse(
MouseEvent, make_napari_viewer, array_type, tmp_path
MouseEvent, make_napari_viewer, array_type
):
"""Check that painting labels paints on the canvas when using mouse.
This should work regardless of array type. See:
https://github.com/napari/napari/issues/6079
"""
viewer = make_napari_viewer(show=True)
labels = make_labels_layer(array_type, tmp_path, shape=(20, 20))
labels = make_labels_layer(array_type, shape=(20, 20))

layer = viewer.add_labels(labels)
QCoreApplication.instance().processEvents()
Expand Down

0 comments on commit f19b262

Please sign in to comment.