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

Fix Napari relared tests fails #376

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/widgets/test_widget_open_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import napari
import numpy as np
import pytest
from pytestqt import qtbot

from plantseg.io.h5 import create_h5
from plantseg.io.voxelsize import VoxelSize
Expand All @@ -11,8 +11,7 @@
IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true" # set to true in GitHub Actions by default to skip CUDA tests


@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="GUI tests hangs in GitHub Actions.")
def test_widget_open_file(make_napari_viewer_proxy, path_h5):
def test_widget_open_file(qtbot, make_napari_viewer_proxy, path_h5):
viewer = make_napari_viewer_proxy()
shape = (10, 10, 10)
data = np.random.rand(*shape).astype(np.float32)
Expand All @@ -29,7 +28,8 @@ def test_widget_open_file(make_napari_viewer_proxy, path_h5):
stack_layout="ZYX",
update_other_widgets=False,
)
napari.run()

qtbot.wait(100)

assert viewer.layers[0].name == "test_raw"
assert viewer.layers[0].data.shape == shape
Expand Down
30 changes: 15 additions & 15 deletions tests/widgets/test_widget_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
from magicgui import magicgui
from napari.types import LayerDataTuple
from pytestqt import qtbot

from plantseg.core.image import ImageLayout, ImageProperties, PlantSegImage, SemanticType
from plantseg.io.voxelsize import VoxelSize
Expand Down Expand Up @@ -51,9 +52,8 @@ def widget_add_image(image: PlantSegImage) -> LayerDataTuple:
return image.to_napari_layer_tuple()


@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="GUI tests hangs in GitHub Actions.")
class TestWidgetRescaling:
def test_rescaling_from_factor(self, make_napari_viewer_proxy, sample_image):
def test_rescaling_from_factor(self, qtbot, make_napari_viewer_proxy, sample_image):
viewer = make_napari_viewer_proxy()
widget_add_image(sample_image)

Expand All @@ -64,14 +64,14 @@ def test_rescaling_from_factor(self, make_napari_viewer_proxy, sample_image):
rescaling_factor=(factor, factor, factor),
update_other_widgets=False,
)
napari.run()
qtbot.wait(100)

old_layer = viewer.layers[sample_image.name]
new_layer = viewer.layers[sample_image.name + '_rescaled']
np.testing.assert_allclose(new_layer.data.shape, np.multiply(old_layer.data.shape, factor), rtol=1e-5)
np.testing.assert_allclose(np.multiply(new_layer.scale, factor), old_layer.scale, rtol=1e-5)

def test_rescaling_to_layer_voxel_size(self, make_napari_viewer_proxy, sample_image, sample_label):
def test_rescaling_to_layer_voxel_size(self, qtbot, make_napari_viewer_proxy, sample_image, sample_label):
viewer = make_napari_viewer_proxy()
widget_add_image(sample_image)
widget_add_image(sample_label)
Expand All @@ -82,15 +82,15 @@ def test_rescaling_to_layer_voxel_size(self, make_napari_viewer_proxy, sample_im
reference_layer=viewer.layers[sample_label.name],
update_other_widgets=False,
)
napari.run()
qtbot.wait(100)

reference_layer = viewer.layers[sample_label.name]
new_layer = viewer.layers[sample_image.name + '_rescaled']

np.testing.assert_allclose(new_layer.data.shape, reference_layer.data.shape, rtol=1e-5)
np.testing.assert_allclose(new_layer.scale, reference_layer.scale, rtol=1e-5)

def test_rescaling_to_model_voxel_size(self, make_napari_viewer_proxy, sample_image):
def test_rescaling_to_model_voxel_size(self, qtbot, make_napari_viewer_proxy, sample_image):
viewer = make_napari_viewer_proxy()
widget_add_image(sample_image)

Expand All @@ -100,7 +100,7 @@ def test_rescaling_to_model_voxel_size(self, make_napari_viewer_proxy, sample_im
reference_model='PlantSeg_3Dnuc_platinum', # voxel size: (0.2837, 0.1268, 0.1268)
update_other_widgets=False,
)
napari.run()
qtbot.wait(200)

old_layer = viewer.layers[sample_image.name]
new_layer = viewer.layers[sample_image.name + '_rescaled']
Expand All @@ -116,7 +116,7 @@ def test_rescaling_to_model_voxel_size(self, make_napari_viewer_proxy, sample_im

np.testing.assert_allclose(new_shape * new_scale, old_shape * old_scale, atol=0.1)

def test_rescaling_to_voxel_size(self, make_napari_viewer_proxy, sample_image):
def test_rescaling_to_voxel_size(self, qtbot, make_napari_viewer_proxy, sample_image):
viewer = make_napari_viewer_proxy()
widget_add_image(sample_image)

Expand All @@ -127,7 +127,7 @@ def test_rescaling_to_voxel_size(self, make_napari_viewer_proxy, sample_image):
out_voxel_size=expected_scale,
update_other_widgets=False,
)
napari.run()
qtbot.wait(100)

old_layer = viewer.layers[sample_image.name]
new_layer = viewer.layers[sample_image.name + '_rescaled']
Expand All @@ -138,7 +138,7 @@ def test_rescaling_to_voxel_size(self, make_napari_viewer_proxy, sample_image):
np.testing.assert_allclose(new_layer.data.shape, expected_shape, rtol=1e-5)
np.testing.assert_allclose(new_layer.scale, expected_scale, rtol=1e-5)

def test_rescaling_to_layer_shape(self, make_napari_viewer_proxy, sample_image, sample_label):
def test_rescaling_to_layer_shape(self, qtbot, make_napari_viewer_proxy, sample_image, sample_label):
viewer = make_napari_viewer_proxy()
widget_add_image(sample_image)
widget_add_image(sample_label)
Expand All @@ -149,7 +149,7 @@ def test_rescaling_to_layer_shape(self, make_napari_viewer_proxy, sample_image,
reference_layer=viewer.layers[sample_label.name],
update_other_widgets=False,
)
napari.run()
qtbot.wait(100)

reference_layer = viewer.layers[sample_label.name]
new_layer = viewer.layers[sample_image.name + '_reshaped']
Expand All @@ -159,7 +159,7 @@ def test_rescaling_to_layer_shape(self, make_napari_viewer_proxy, sample_image,
# In our special case in this test, yes, the scale should be the same
np.testing.assert_allclose(new_layer.scale, reference_layer.scale, rtol=1e-5)

def test_rescaling_set_shape(self, make_napari_viewer_proxy, sample_image):
def test_rescaling_set_shape(self, qtbot, make_napari_viewer_proxy, sample_image):
viewer = make_napari_viewer_proxy()
widget_add_image(sample_image)

Expand All @@ -170,7 +170,7 @@ def test_rescaling_set_shape(self, make_napari_viewer_proxy, sample_image):
reference_shape=target_shape,
update_other_widgets=False,
)
napari.run()
qtbot.wait(100)

old_layer = viewer.layers[sample_image.name]
new_layer = viewer.layers[sample_image.name + '_reshaped']
Expand All @@ -182,7 +182,7 @@ def test_rescaling_set_shape(self, make_napari_viewer_proxy, sample_image):

np.testing.assert_allclose(new_layer.scale, expected_scale, rtol=1e-5)

def test_rescaling_set_voxel_size(self, make_napari_viewer_proxy, sample_image):
def test_rescaling_set_voxel_size(self, qtbot, make_napari_viewer_proxy, sample_image):
viewer = make_napari_viewer_proxy()
widget_add_image(sample_image)

Expand All @@ -193,7 +193,7 @@ def test_rescaling_set_voxel_size(self, make_napari_viewer_proxy, sample_image):
out_voxel_size=target_voxel_size,
update_other_widgets=False,
)
napari.run()
qtbot.wait(100)

new_layer = viewer.layers[sample_image.name + '_set_voxel_size']
np.testing.assert_allclose(new_layer.scale, target_voxel_size, rtol=1e-5)