Skip to content

Commit

Permalink
Test Geojson file fields (#107)
Browse files Browse the repository at this point in the history
* adding compression option

* Adding modification and verification in method

* add test_geojson method to test the geojson file

* restore earthspy file

* Add loop over file and test

* Adding comments and use of glob

* add pre-commit file and last change in test_earthspy

* Modify comments and doc of `test_geojson`

* reran precommit

* bring tests out of file context

* check that geojson files are found

* change tests on

* rename test method

---------

Co-authored-by: Adrien Wehrlé <adrien.wehrle@hotmail.fr>
  • Loading branch information
Antsalacia and AdrienWehrle authored Dec 4, 2024
1 parent 07967b4 commit b7db112
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: CI
on: [push]
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
miniconda:
Expand Down
33 changes: 33 additions & 0 deletions tests/test_earthspy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

import glob
import json
import os

import numpy as np
Expand Down Expand Up @@ -332,6 +334,37 @@ def test_sentinelhub_request(self) -> None:
# # check that a Sentinel Hub request was created
assert isinstance(sr2, shb.SentinelHubRequest)

def test_geojson_files(self) -> None:
"""Test fields of GEOJSON files"""

# list all geojson files available in earthspy
geojson_files = glob.glob("./earthspy/data/*")

# check that files were found
assert len(geojson_files) > 0

for file in geojson_files:

with open(file, "r+") as f:
data = json.load(f)

# extract coordinates of geometry nodes
geometry_coordinates = np.array(
data["features"][0]["geometry"]["coordinates"][0]
)

# check if feature is a polygon
assert data["features"][0]["geometry"]["type"] == "Polygon"

# check if coordinates match a 4-point square
assert geometry_coordinates.shape == (5, 2)

# check if the coordinates are valid longitude/latitude coordinates
assert ((geometry_coordinates >= -90) & (geometry_coordinates <= 90)).all()

# check if first coordinate is repeated on the last element
assert geometry_coordinates[0, 0] == geometry_coordinates[-1, 0]

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

Expand Down

0 comments on commit b7db112

Please sign in to comment.