Skip to content

Commit

Permalink
added test for available_data method
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjalling-dejong committed Jun 18, 2024
1 parent 03e083a commit deea146
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
11 changes: 3 additions & 8 deletions EO_Floods/floodmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,10 @@ def set_provider(self, provider: str, datasets: Optional[List[str] | str]):
else:
raise ValueError(f"Given provider {provider} not supported")

def available_data(self) -> List[dict,]:
"""Returns information of the chosen datasets for the given temporal and
def available_data(self):
"""Prints information of the chosen datasets for the given temporal and
spatial resolution. The information contains the dataset name, the number
of images, and the timestamp of the images.
Returns
-------
List[dict,]
List of dictionaries describing the data
of images, the timestamp of the images, and a quality score in percentage.
"""

hf = HydraFloods(
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
from EO_Floods.auth import ee_initialize
from EO_Floods.dataset import DATASETS
from EO_Floods.providers import HydraFloods
from EO_Floods.floodmap import FloodMap

ee_initialize()

Expand All @@ -13,3 +15,12 @@ def get_hydrafloods_instance(dataset_list: list) -> HydraFloods:
end_date="2023-04-30",
geometry=[4.221067, 51.949474, 4.471006, 52.073727],
)


@pytest.fixture()
def flood_map() -> FloodMap:
return FloodMap(
start_date="2022-10-01",
end_date="2022-10-15",
geometry=[67.740187, 27.712453, 68.104933, 28.000935],
)
25 changes: 11 additions & 14 deletions tests/test_floodmap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import geemap.foliumap as geemap
import hydrafloods as hf
from unittest.mock import patch, call

from EO_Floods.floodmap import FloodMap
from EO_Floods.dataset import Dataset
Expand Down Expand Up @@ -37,20 +38,16 @@ def test_FloodMap_init():
)


def test_FloodMap_info():
floodmap = FloodMap(
start_date="2023-04-01",
end_date="2023-04-30",
geometry=[4.221067, 51.949474, 4.471006, 52.073727],
datasets="Sentinel-2",
provider="hydrafloods",
use_qa=False,
)

floodmap_info = floodmap.info
assert isinstance(floodmap_info, list)
assert isinstance(floodmap_info[0], dict)
assert floodmap_info[0]["Number of images"] == 10
@patch("builtins.print")
def test_available_data(mocked_print, flood_map):
flood_map.available_data()
print_args = mocked_print.mock_calls[0][1][0]
assert "Sentinel-1" in print_args
assert "Sentinel-2" in print_args
assert "Landsat 7" in print_args
assert "Landsat 8" in print_args
assert "VIIRS" in print_args
assert "MODIS" in print_args


def test_FloodMap_preview_data():
Expand Down

0 comments on commit deea146

Please sign in to comment.