From 2274a4a608cfe4ce7cefe43f540c46e56901e44a Mon Sep 17 00:00:00 2001 From: uriii3 Date: Tue, 6 Aug 2024 15:56:45 +0200 Subject: [PATCH] chore: joining the warnings into one test file --- tests/test_command_line_interface.py | 53 ------------ tests/test_python_interface.py | 13 --- tests/test_warnings_subset_bounds.py | 115 +++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 66 deletions(-) diff --git a/tests/test_command_line_interface.py b/tests/test_command_line_interface.py index b2c76ee2..11823079 100644 --- a/tests/test_command_line_interface.py +++ b/tests/test_command_line_interface.py @@ -1517,59 +1517,6 @@ def test_dataset_has_always_every_dimensions(self, tmp_path): == 4 ) - def when_I_request_a_dataset_with_subset_method_option( - self, subset_method - ): - command = [ - "copernicusmarine", - "subset", - "-i", - "med-hcmr-wav-rean-h", - "-x", - "-19", - "-X", - "-17", - "-y", - "38.007", - "-Y", - "38.028", - "-t", - "1993-01-01T00:00:00", - "-T", - "1993-01-01T06:00:00", - "-v", - "VHM0", - "--force-download", - "--subset-method", - f"{subset_method}", - ] - - self.output = execute_in_terminal(command) - - def then_I_can_read_an_error_in_stdout(self): - assert self.output.returncode == 1 - assert b"ERROR" in self.output.stderr - assert ( - b"Some of your subset selection [-19.0, -17.0] for " - b"the longitude dimension exceed the dataset coordinates" - ) in self.output.stderr - - def then_I_can_read_a_warning_in_stdout(self): - assert self.output.returncode == 0 - assert b"WARNING" in self.output.stderr - assert ( - b"Some of your subset selection [-19.0, -17.0] for " - b"the longitude dimension exceed the dataset coordinates" - ) in self.output.stderr - - def test_subset_strict_method(self): - self.when_I_request_a_dataset_with_subset_method_option("strict") - self.then_I_can_read_an_error_in_stdout() - - def test_subset_nearest_method(self): - self.when_I_request_a_dataset_with_subset_method_option("nearest") - self.then_I_can_read_a_warning_in_stdout() - def test_netcdf_compression_option(self, tmp_path): filename_without_option = "without_option.nc" filename_with_option = "with_option.nc" diff --git a/tests/test_python_interface.py b/tests/test_python_interface.py index ccf81880..08c68c65 100644 --- a/tests/test_python_interface.py +++ b/tests/test_python_interface.py @@ -7,7 +7,6 @@ import xarray from copernicusmarine import ( - core_functions, describe, get, login, @@ -287,15 +286,3 @@ def test_subset_keeps_fillvalue_empty_w_compression(self, tmp_path): assert "_FillValue" not in subsetdata.depth.attrs assert subsetdata.time.attrs["calendar"] == "gregorian" assert subsetdata.time.attrs["units"] == "hours since 1950-01-01" - - def test_error_Coord_out_of_dataset_bounds(self): - try: - _ = subset( - dataset_id="cmems_mod_glo_phy_anfc_0.083deg_P1D-m", - start_datetime=datetime.today() + timedelta(10), - force_download=True, - end_datetime=datetime.today() - + timedelta(days=10, hours=23, minutes=59), - ) - except core_functions.exceptions.CoordinatesOutOfDatasetBounds as e: - assert "Some of your subset selection" in e.__str__() diff --git a/tests/test_warnings_subset_bounds.py b/tests/test_warnings_subset_bounds.py index c16cee41..81d1d8b4 100644 --- a/tests/test_warnings_subset_bounds.py +++ b/tests/test_warnings_subset_bounds.py @@ -1,3 +1,6 @@ +from datetime import datetime, timedelta + +from copernicusmarine import core_functions, subset from tests.test_utils import execute_in_terminal @@ -168,3 +171,115 @@ def test_warn_depth_out_of_dataset_bounds(self, tmp_path): b"dimension exceed the dataset coordinates " b"[0.49402499198913574, 5727.9169921875]" ) in output.stderr + + def test_warn_elevation_out_of_dataset_bounds(self, tmp_path): + output_filename = "output.nc" + dataset_id = "cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m" + min_longitude = 29.0 + max_longitude = 30.0 + min_latitude = 30 + max_latitude = 32 + min_depth = 0.4 + max_depth = 50.0 + start_datetime = "2023-11-03" + end_datetime = "2023-11-03" + command = self._build_custom_command( + dataset_id, "thetao", min_longitude, max_longitude, "nearest" + ) + command.extend( + [ + "--minimum-latitude", + f"{min_latitude}", + "--maximum-latitude", + f"{max_latitude}", + "--start-datetime", + f"{start_datetime}", + "--end-datetime", + f"{end_datetime}", + "--minimum-depth", + f"{min_depth}", + "--maximum-depth", + f"{max_depth}", + "--vertical-dimension-as-originally-produced", + "False", + "-o", + f"{tmp_path}", + "-f", + f"{output_filename}", + ] + ) + output = execute_in_terminal(command, input=b"n") + + assert ( + b"Some of your subset selection [0.4, 50.0] for the depth " + b"dimension exceed the dataset coordinates " + b"[0.49402499198913574, 5727.9169921875]" + ) in output.stderr + assert ( + b"* elevation (elevation) float32 72B -47.37 -40.34" + ) in output.stderr + + def test_error_Coord_out_of_dataset_bounds(self): + try: + _ = subset( + dataset_id="cmems_mod_glo_phy_anfc_0.083deg_P1D-m", + start_datetime=datetime.today() + timedelta(10), + force_download=True, + end_datetime=datetime.today() + + timedelta(days=10, hours=23, minutes=59), + ) + except core_functions.exceptions.CoordinatesOutOfDatasetBounds as e: + assert "Some of your subset selection" in e.__str__() + + def when_I_request_a_dataset_with_subset_method_option( + self, subset_method + ): + command = [ + "copernicusmarine", + "subset", + "-i", + "med-hcmr-wav-rean-h", + "-x", + "-19", + "-X", + "-17", + "-y", + "38.007", + "-Y", + "38.028", + "-t", + "1993-01-01T00:00:00", + "-T", + "1993-01-01T06:00:00", + "-v", + "VHM0", + "--force-download", + "--subset-method", + f"{subset_method}", + ] + + self.output = execute_in_terminal(command) + + def then_I_can_read_an_error_in_stdout(self): + assert self.output.returncode == 1 + assert b"ERROR" in self.output.stderr + assert ( + b"Some of your subset selection [-19.0, -17.0] for " + b"the longitude dimension exceed the dataset coordinates" + ) in self.output.stderr + + def then_I_can_read_a_warning_in_stdout(self): + assert self.output.returncode == 0 + assert b"WARNING" in self.output.stderr + assert ( + b"Some of your subset selection [-19.0, -17.0] for " + b"the longitude dimension exceed the dataset coordinates" + ) in self.output.stderr + + def test_subset_strict_method(self): + self.when_I_request_a_dataset_with_subset_method_option("strict") + self.then_I_can_read_an_error_in_stdout() + + def test_subset_nearest_method(self): + self.when_I_request_a_dataset_with_subset_method_option("nearest") + self.then_I_can_read_a_warning_in_stdout()