Skip to content

Commit 4b355af

Browse files
Copilotbw4sz
andauthored
Simplify relative path tests for plot functions (#1209)
* Initial plan * Simplify tests: consolidate three relative path tests into one Co-authored-by: bw4sz <[email protected]> * Use polygon geometry in relative path test for proper coverage Co-authored-by: bw4sz <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: bw4sz <[email protected]>
1 parent 4b88101 commit 4b355af

File tree

1 file changed

+8
-44
lines changed

1 file changed

+8
-44
lines changed

tests/test_visualize.py

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,23 @@ def test_plot_results_polygon(gdf_poly, tmpdir):
156156
assert os.path.exists(os.path.join(tmpdir, "OSBS_029.png"))
157157

158158

159-
def test_plot_results_polygon_relative_no_dims(tmpdir):
160-
# Build polygon gdf with relative image_path and root_dir, without passing width/height
161-
full_path = get_data("OSBS_029.tif")
159+
def test_plot_with_relative_paths(tmpdir):
160+
# Test that plot_results and plot_annotations work with relative paths and root_dir
161+
full_path = get_data("OSBS_029.png")
162162
relative_name = os.path.basename(full_path)
163163
root_dir = os.path.dirname(full_path)
164164

165165
data = {
166-
'geometry': [
167-
geometry.Polygon([(10, 10), (20, 10), (20, 20), (10, 20), (15, 25)]),
168-
geometry.Polygon([(30, 30), (40, 30), (40, 40), (30, 40), (35, 35)])
169-
],
170-
'label': ['Tree', 'Tree'],
171-
'image_path': [relative_name, relative_name],
172-
'score': [0.9, 0.8]
166+
'geometry': [geometry.Polygon([(10, 10), (20, 10), (20, 20), (10, 20), (15, 25)])],
167+
'label': ['Tree'],
168+
'image_path': [relative_name],
169+
'score': [0.9]
173170
}
174171
gdf = gpd.GeoDataFrame(data)
175172
gdf.root_dir = root_dir
176173

177-
# Should auto-detect width/height using root_dir + image_path
178174
visualize.plot_results(gdf, savedir=tmpdir, show=False)
175+
visualize.plot_annotations(gdf, savedir=tmpdir, show=False)
179176
assert os.path.exists(os.path.join(tmpdir, "OSBS_029.png"))
180177

181178

@@ -236,37 +233,4 @@ def test_image_empty():
236233
assert image is not None
237234

238235

239-
def test_plot_results_with_relative_image_path_and_root_dir(tmpdir):
240-
# Use a relative image_path and ensure df.root_dir is used by _load_image
241-
full_path = get_data("OSBS_029.png")
242-
relative_name = os.path.basename(full_path)
243-
root_dir = os.path.dirname(full_path)
244-
245-
df = pd.DataFrame({
246-
'xmin': [10], 'ymin': [10], 'xmax': [30], 'ymax': [30],
247-
'label': ['Tree'], 'image_path': [relative_name], 'score': [0.9]
248-
})
249-
250-
gdf = utilities.read_file(df)
251-
gdf.root_dir = root_dir
252236

253-
visualize.plot_results(gdf, savedir=tmpdir, show=False)
254-
assert os.path.exists(os.path.join(tmpdir, "OSBS_029.png"))
255-
256-
257-
def test_plot_annotations_with_relative_image_path_and_root_dir(tmpdir):
258-
# Use a relative image_path and ensure df.root_dir is used by _load_image
259-
full_path = get_data("OSBS_029.png")
260-
relative_name = os.path.basename(full_path)
261-
root_dir = os.path.dirname(full_path)
262-
263-
df = pd.DataFrame({
264-
'xmin': [10], 'ymin': [10], 'xmax': [30], 'ymax': [30],
265-
'label': ['Tree'], 'image_path': [relative_name]
266-
})
267-
268-
gdf = utilities.read_file(df)
269-
gdf.root_dir = root_dir
270-
271-
visualize.plot_annotations(gdf, savedir=tmpdir, show=False)
272-
assert os.path.exists(os.path.join(tmpdir, "OSBS_029.png"))

0 commit comments

Comments
 (0)