From e72b77c9a4f99eddc48f214e8c6a7d676165b38e Mon Sep 17 00:00:00 2001 From: uriii3 Date: Tue, 18 Feb 2025 13:14:21 +0100 Subject: [PATCH] add tests on out of bounds stereo --- .../download_functions/subset_xarray.py | 2 - tests/test_originalGrid_datasets.py | 69 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/copernicusmarine/download_functions/subset_xarray.py b/copernicusmarine/download_functions/subset_xarray.py index 6d243af6..dbb13a6f 100644 --- a/copernicusmarine/download_functions/subset_xarray.py +++ b/copernicusmarine/download_functions/subset_xarray.py @@ -157,8 +157,6 @@ def _dataset_custom_sel( coordinates_selection_method: CoordinatesSelectionMethod, ) -> xarray.Dataset: coord_label = coord_type - logger.info(f"Selecting {coord_label} coordinates") - logger.info(f"Selection method: {dataset.sizes}") if coord_label in dataset.sizes: if coordinates_selection_method == "outside": if ( diff --git a/tests/test_originalGrid_datasets.py b/tests/test_originalGrid_datasets.py index 2843d969..9fbc64ee 100644 --- a/tests/test_originalGrid_datasets.py +++ b/tests/test_originalGrid_datasets.py @@ -203,3 +203,72 @@ def run_one_dataset(self, dataset_info): assert returned_value["coordinates_extent"][1]["minimum"] == float( min_x ) + + def test_out_of_bounds(self): + command = [ + "copernicusmarine", + "subset", + "-i", + "cmems_mod_arc_bgc_anfc_ecosmo_P1D-m", + "--dataset-part", + "originalGrid", + "--maximum-x", + "100", + "--minimum-x", + "-100", + "--maximum-y", + "10", + "--minimum-y", + "4", + "-t", + "2020", + "-T", + "2020", + "--dry-run", + ] + self.output = execute_in_terminal(command) + assert self.output.returncode == 0 + assert b"WARNING" in self.output.stderr + assert ( + b"Some of your subset selection [-100.0, 100.0] for the" + b" x dimension exceed the dataset coordinates [-36.0, 38.0]" + in self.output.stderr + ) + assert ( + b"Some of your subset selection [-100.0, 100.0] for the " + b"y dimension exceed the dataset coordinates [-43.0, 28.0]" + in self.output.stderr + ) + + def test_out_of_bounds_w_error(self): + command = [ + "copernicusmarine", + "subset", + "-i", + "cmems_mod_arc_bgc_anfc_ecosmo_P1D-m", + "--dataset-part", + "originalGrid", + "--maximum-x", + "1", + "--minimum-x", + "-1", + "--maximum-y", + "10", + "--minimum-y", + "4", + "-t", + "2020", + "-T", + "2020", + "--dry-run", + "--coordinates-selection-method", + "strict-inside", + ] + self.output = execute_in_terminal(command) + assert self.output.returncode == 1 + assert b"ERROR" in self.output.stderr + assert ( + b"Some of your subset selection [-100.0, 100.0] for the y" + b" dimension exceed the dataset coordinates [-43.0, 28.0]" + in self.output.stderr + )