Skip to content

Commit

Permalink
add test for save_coords
Browse files Browse the repository at this point in the history
  • Loading branch information
HaleySchuhl committed Mar 4, 2024
1 parent 0c95c4b commit 3ead6b6
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/test_annotate_points.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Tests for annotate.Points."""
import os
import cv2
import matplotlib
from plantcv.annotate.classes import Points
Expand Down Expand Up @@ -43,4 +45,32 @@ def test_points(test_data):
e5.xdata, e5.ydata = (301, 200)
drawer_rgb.onclick(e5)

assert drawer_rgb.coords[0] == point1
assert drawer_rgb.coords["default"][0] == point1

def test_points_save_coords(test_data, tmpdir):
"""Test for PlantCV."""
cache_dir = tmpdir.mkdir("cache")
filename = os.path.join(cache_dir, 'plantcv_print_coords.txt')
# Read in a test grayscale image
img = cv2.imread(test_data.small_rgb_img)

# initialize interactive tool
drawer_rgb = Points(img, figsize=(12, 6))

# simulate mouse clicks
# event 1, left click to add point
e1 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas,
x=0, y=0, button=1)
point1 = (200, 200)
e1.xdata, e1.ydata = point1
drawer_rgb.onclick(e1)

# event 2, left click to add point
e2 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas,
x=0, y=0, button=1)
e2.xdata, e2.ydata = (300, 200)
drawer_rgb.onclick(e2)

# Save collected coords out
drawer_rgb.print_coords(filename=filename)
assert os.path.exists(filename)

0 comments on commit 3ead6b6

Please sign in to comment.