Skip to content

Commit

Permalink
connection fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
HansVRP committed Oct 30, 2024
1 parent 5a318cc commit c2385e5
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions tests/tests_integration/features/test_feature_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
import xarray as xr
import openeo

from openeo_gfmap import BoundingBoxExtent, FetchType, TemporalContext
from openeo_gfmap.backend import BACKEND_CONNECTIONS, Backend, BackendContext
Expand All @@ -27,8 +28,20 @@
)
TEMPORAL_EXTENT = TemporalContext("2023-10-01", "2024-01-01")

backends = [Backend.CDSE]
backend = Backend.CDSE

@pytest.fixture
def connection():
"""Fixture to create a connection for the fixed backend."""
conn = BACKEND_CONNECTIONS[backend]()
# Assuming authenticate_oidc is needed; you can adjust this based on your context.
conn.authenticate_oidc()
return conn

@pytest.fixture
def backend_context(connection):
"""Fixture to create backend context."""
return BackendContext(backend=backend)

class DummyPatchExtractor(PatchFeatureExtractor):
def output_labels(self) -> list:
Expand Down Expand Up @@ -91,10 +104,7 @@ def execute(self, inarr: xr.DataArray) -> xr.DataArray:
# TODO; A convoluted test. I would write unit test functions for the functionalities defined within the Feature extractor class.
# Then we can adapt this test to an integration/regression test
# Is the idea to test the extractor? We want to catch data unavailibility?
@pytest.mark.parametrize("backend", backends)
def test_patch_feature_udf(backend: Backend):
connection = BACKEND_CONNECTIONS[backend]()
backend_context = BackendContext(backend=backend)
def test_patch_feature_udf(connection, backend_context):

output_path = (
Path(__file__).parent.parent / f"results/patch_features_{backend.value}.nc/"
Expand Down Expand Up @@ -137,10 +147,7 @@ def test_patch_feature_udf(backend: Backend):


# TODO Similar as above, but for S1
@pytest.mark.parametrize("backend", backends)
def test_s1_rescale(backend: Backend):
connection = BACKEND_CONNECTIONS[backend]()
backend_context = BackendContext(backend=backend)
def test_s1_rescale(connection, backend_context):
output_path = (
Path(__file__).parent.parent
/ f"results/s1_rescaled_features_{backend.value}.nc"
Expand Down Expand Up @@ -182,10 +189,7 @@ def test_s1_rescale(backend: Backend):


# TODO Replace by unit test on the functionalities defined in PatchFeatureExtractor/PointFeatureExtractor
@pytest.mark.parametrize("backend", backends)
def test_latlon_extractor(backend: Backend):
connection = BACKEND_CONNECTIONS[backend]()
backend_context = BackendContext(backend=backend)
def test_latlon_extractor(connection, backend_context):
output_path = (
Path(__file__).parent.parent / f"results/latlon_features_{backend.value}.nc"
)
Expand Down

0 comments on commit c2385e5

Please sign in to comment.