From dc3e6e7e431927a363472ee39cfdb96f186d80e4 Mon Sep 17 00:00:00 2001 From: k034b363 Date: Fri, 4 Oct 2024 16:27:16 -0500 Subject: [PATCH] Add tests for points_to_geojson --- mkdocs.yml | 1 + pyproject.toml | 1 + tests/test_geospatial_points_to_geojson.py | 34 ++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/test_geospatial_points_to_geojson.py diff --git a/mkdocs.yml b/mkdocs.yml index cd22236..2d49917 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -20,6 +20,7 @@ nav: - Read Geo-tif Data: read_geotif.md - Transform coordinate points: transform_points.md - Transform coordinate polygons: transform_polygons.md + - Save clicked points as geojson: points_to_geojson.md markdown_extensions: - toc: permalink: True diff --git a/pyproject.toml b/pyproject.toml index 7617ecb..e6bba0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ dependencies = [ "rasterio", "fiona", "shapely", + "plantcv.annotate", ] requires-python = ">=3.6" authors = [ diff --git a/tests/test_geospatial_points_to_geojson.py b/tests/test_geospatial_points_to_geojson.py new file mode 100644 index 0000000..6a1d206 --- /dev/null +++ b/tests/test_geospatial_points_to_geojson.py @@ -0,0 +1,34 @@ +"""Tests for geospatial.points_to_geojson""" + +import pytest +import plantcv.annotate as an +from plantcv.geospatial import read_geotif +from plantcv.geospatial import points_to_geojson + +def test_geospatial_points_to_geojson_napari(test_data, tmpdir): + """Test for plantcv-geospatial.""" + cache_dir = tmpdir.mkdir("cache") + img = read_geotif(filename=test_data.rgb_tif, bands="R,G,B") + viewer = an.napari_open(img=img.pseudo_rgb, show=False) + viewer.add_points() + filename = os.path.join(cache_dir, 'test_out.geojson') + points_to_geojson(img, viewer, output=filename) + assert os.path.exists(filename) + +def test_geospatial_points_to_geojson_an(test_data, tmpdir): + """Test for plantcv-geospatial.""" + cache_dir = tmpdir.mkdir("cache") + img = read_geotif(filename=test_data.rgb_tif, bands="R,G,B") + viewer = an.Points(img=img.pseudo_rgb) + filename = os.path.join(cache_dir, 'test_out.geojson') + points_to_geojson(img, viewer, output=filename) + assert os.path.exists(filename) + +def test_geospatial_points_to_geojson_badviewer(test_data, tmpdir): + """Test for plantcv-geospatial.""" + cache_dir = tmpdir.mkdir("cache") + img = read_geotif(filename=test_data.rgb_tif, bands="R,G,B") + viewer = [] + filename = os.path.join(cache_dir, 'test_out.geojson') + with pytest.raises(RuntimeError): + points_to_geojson(img, viewer, output=filename)