Skip to content

Commit

Permalink
added the dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
volker-baecker committed Nov 26, 2024
1 parent de98dc7 commit 91795c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 46 deletions.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ dependencies = [
"magicgui",
"qtpy",
"scikit-image",
"cellpose",
"czifile",
"big-fish",
"scikit-image"
]

[project.optional-dependencies]
Expand Down
48 changes: 2 additions & 46 deletions src/segment_embryo/_tests/test_widget.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,18 @@
import numpy as np

from segment_embryo._widget import (
ExampleQWidget,
ImageThreshold,
threshold_autogenerate_widget,
threshold_magic_widget,
EmbryoSegmentationWidget
)


def test_threshold_autogenerate_widget():
# because our "widget" is a pure function, we can call it and
# test it independently of napari
im_data = np.random.random((100, 100))
thresholded = threshold_autogenerate_widget(im_data, 0.5)
assert thresholded.shape == im_data.shape
# etc.


# make_napari_viewer is a pytest fixture that returns a napari viewer object
# you don't need to import it, as long as napari is installed
# in your testing environment
def test_threshold_magic_widget(make_napari_viewer):
viewer = make_napari_viewer()
layer = viewer.add_image(np.random.random((100, 100)))

# our widget will be a MagicFactory or FunctionGui instance
my_widget = threshold_magic_widget()

# if we "call" this object, it'll execute our function
thresholded = my_widget(viewer.layers[0], 0.5)
assert thresholded.shape == layer.data.shape
# etc.


def test_image_threshold_widget(make_napari_viewer):
viewer = make_napari_viewer()
layer = viewer.add_image(np.random.random((100, 100)))
my_widget = ImageThreshold(viewer)

# because we saved our widgets as attributes of the container
# we can set their values without having to "interact" with the viewer
my_widget._image_layer_combo.value = layer
my_widget._threshold_slider.value = 0.5

# this allows us to run our functions directly and ensure
# correct results
my_widget._threshold_im()
assert len(viewer.layers) == 2


# capsys is a pytest fixture that captures stdout and stderr output streams
def test_example_q_widget(make_napari_viewer, capsys):
# make viewer and add an image layer using our fixture
viewer = make_napari_viewer()
viewer.add_image(np.random.random((100, 100)))

# create our widget, passing in the viewer
my_widget = ExampleQWidget(viewer)
my_widget = EmbryoSegmentationWidget(viewer)

# call our widget method
my_widget._on_click()
Expand Down

0 comments on commit 91795c9

Please sign in to comment.