Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using temporary directory for store array for paint test #6191

Merged
merged 1 commit into from Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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