Skip to content

Commit

Permalink
Try to fix tests not liking a blocked napari window
Browse files Browse the repository at this point in the history
  • Loading branch information
k034b363 committed Dec 5, 2024
1 parent c5ad265 commit c29784e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions plantcv/geospatial/napari_save_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os


def napari_save_points(images, num_points, outdir="./", bands="R,G,B", block=True, show=True):
def napari_save_points(images, num_points, outdir="./", bands="R,G,B", show_window=True):
"""Opens a set of images one at a time in a Napari window, waits for users
to click points and then saves those points to a file with the same name as the image.
Expand Down Expand Up @@ -45,12 +45,13 @@ def napari_save_points(images, num_points, outdir="./", bands="R,G,B", block=Tru
# Save image name for output file
img_name = (image_path.split("/")[-1]).split(".")[:-1]

viewer = napari.Viewer(show=show)
viewer = napari.Viewer(show=show_window)

# Add the image and points layer
viewer.add_image(image)
viewer.add_points(name="points")
viewer.show(block=block)
if show_window:
viewer.show(block=True)

# Save file if correct number of points
if len(viewer.layers["points"].data) == num_points:
Expand All @@ -63,7 +64,7 @@ def napari_save_points(images, num_points, outdir="./", bands="R,G,B", block=Tru
warn('Image ' + str(image_path) + ' collected incorrect number of points. ' +
'Added to redo list.')
# Close the viewer in case it wasn't shown
if not show:
if not show_window:
viewer.close()
# Reset debug
pcv.params.debug = debug
Expand Down
4 changes: 2 additions & 2 deletions tests/test_geospatial_napari_save_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_geospatial_napari_save_points(test_data, tmpdir):
"""Test for plantcv-geospatial."""
cache_dir = tmpdir.mkdir("cache")
images = [test_data.rgb_tif]
redo_list = napari_save_points(images, num_points=4, outdir=cache_dir, block=False, show=False)
redo_list = napari_save_points(images, num_points=4, outdir=cache_dir, show=False)
assert len(redo_list) == 1


Expand All @@ -20,5 +20,5 @@ def test_geospatial_napari_save_points_output(test_data, tmpdir):
img = read_geotif(filename=test_data.rgb_tif, bands="R,G,B")
print_image(img.pseudo_rgb, os.path.join(cache_dir, "rgb.png"))
images = [os.path.join(cache_dir, "rgb.png")]
_ = napari_save_points(images, num_points=0, outdir=cache_dir, block=False, show=False)
_ = napari_save_points(images, num_points=0, outdir=cache_dir, show=False)
assert os.path.exists(os.path.join(cache_dir, "rgb_warp.txt"))

0 comments on commit c29784e

Please sign in to comment.