Skip to content

Commit

Permalink
Add tests for points_to_geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
k034b363 committed Oct 4, 2024
1 parent 96e1a54 commit dc3e6e7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"rasterio",
"fiona",
"shapely",
"plantcv.annotate",
]
requires-python = ">=3.6"
authors = [
Expand Down
34 changes: 34 additions & 0 deletions tests/test_geospatial_points_to_geojson.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit dc3e6e7

Please sign in to comment.