Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Geojson file fields #107

Merged
merged 15 commits into from
Dec 4, 2024
22 changes: 21 additions & 1 deletion tests/test_earthspy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import pandas as pd
import requests
import sentinelhub as shb

import json
AdrienWehrle marked this conversation as resolved.
Show resolved Hide resolved
import glob

class TestEarthspy:
# create local variables from environment secrets for convenience
Expand Down Expand Up @@ -330,6 +331,25 @@ def test_sentinelhub_request(self) -> None:
# # check that a Sentinel Hub request was created
assert isinstance(sr2, shb.SentinelHubRequest)

def test_geojson(self) -> None:
"""Test geojson files"""

folder_path = glob.glob("earthspy/data/*", recursive=True)
for file in folder_path:
with open(file, "r+") as files_geo:
data = json.load(files_geo)
array_coord = np.array(data["features"][0]["geometry"]
['coordinates'][0])

# check if the figure is a Polygon
assert data["features"][0]["geometry"]['type'] == "Polygon"
# check if the coordinates are in the right format
assert array_coord.shape == (5, 2)
# check if the coordinates are between -90 and 90
assert ((array_coord >= -90) & (array_coord <= 90)).all()
# check if the first and the last coordinates are the same
assert array_coord[0, 0] == array_coord[-1, 0]

def test_rename_output_files(self) -> None:
"""Test output renaming"""

Expand Down