From 9c38826494c5576c8a8271d78349592b36d1119e Mon Sep 17 00:00:00 2001 From: Lukas Weidenholzer Date: Fri, 14 Jul 2023 16:04:32 +0200 Subject: [PATCH] add tests for drop_dimension --- tests/test_dimensions.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/test_dimensions.py b/tests/test_dimensions.py index c83c638b..1088cb7f 100644 --- a/tests/test_dimensions.py +++ b/tests/test_dimensions.py @@ -1,7 +1,14 @@ import numpy as np import pytest -from openeo_processes_dask.process_implementations.cubes.general import add_dimension +from openeo_processes_dask.process_implementations.cubes.general import ( + add_dimension, + drop_dimension, +) +from openeo_processes_dask.process_implementations.exceptions import ( + DimensionLabelCountMismatch, + DimensionNotAvailable, +) from tests.general_checks import general_output_checks from tests.mockdata import create_fake_rastercube @@ -33,3 +40,27 @@ def test_add_dimension(temporal_interval, bounding_box, random_raster_data): data=input_cube, name="weird", label="test", type="temporal" ) assert output_cube_2.openeo.temporal_dims[1] == "weird" + + +@pytest.mark.parametrize("size", [(30, 30, 20, 2)]) +@pytest.mark.parametrize("dtype", [np.float32]) +def test_drop_dimension(temporal_interval, bounding_box, random_raster_data): + input_cube = create_fake_rastercube( + data=random_raster_data, + spatial_extent=bounding_box, + temporal_extent=temporal_interval, + bands=["B02", "B04"], + backend="dask", + ) + DIM_TO_DROP = "bands" + + with pytest.raises(DimensionNotAvailable): + drop_dimension(input_cube, "notthere") + + with pytest.raises(DimensionLabelCountMismatch): + drop_dimension(input_cube, DIM_TO_DROP) + + suitable_cube = input_cube.where(input_cube.bands == "B02", drop=True) + + output_cube = drop_dimension(suitable_cube, DIM_TO_DROP) + assert DIM_TO_DROP not in output_cube.dims