Skip to content

Commit

Permalink
feat: script to compress SMAP files
Browse files Browse the repository at this point in the history
  • Loading branch information
renaudjester committed Jun 14, 2024
1 parent 8e6f653 commit 0b1f229
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion tests/test_command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def test_login_is_prompt_when_configuration_file_doest_not_exist(
command, env=environment_without_crendentials
)
assert self.output.returncode == 1
assert b"username:" in self.output.stderr
assert b"username:" in self.output.stdout

def test_login_command(self, tmp_path):
self.check_credentials_username_specified_password_prompt(tmp_path)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import time
from subprocess import CompletedProcess
from typing import Optional

logger = logging.getLogger()

Expand All @@ -23,11 +24,12 @@ def remove_extra_logging_prefix_info(multi_line_message: bytes):
def execute_in_terminal(
command: list[str],
timeout_second: float = FIVE_MINUTES,
input=None,
env=None,
input: Optional[bytes] = None,
env: Optional[dict[str, str]] = None,
) -> CompletedProcess[bytes]:
t1 = time.time()
logger.info(f"Running command: {' '.join(command)}...")
command_to_print = " ".join([str(c) for c in command])
logger.info(f"Running command: {command_to_print}...")
output = subprocess.run(
command,
capture_output=True,
Expand All @@ -37,7 +39,5 @@ def execute_in_terminal(
)
t2 = time.time()
duration_second = t2 - t1
logger.info(
f"Command executed in {duration_second} s: {' '.join(command)}"
)
logger.info(f"Command executed in {duration_second} s: {command_to_print}")
return output
32 changes: 15 additions & 17 deletions tests/test_warnings_subset_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def _build_custom_command(
f"{subset_method}",
]

def test_subset_warning_properly(self):
# Dataset with longitude bounds from -179.97... to 179.91...
# The call should return a warning (and correctly the bounds)
def test_subset_send_warning_with_method_nearest(self):
dataset_id = (
"cmems_obs-oc_glo_bgc-plankton_nrt_l4-gapfree-multi-4km_P1D"
)
Expand All @@ -54,17 +52,17 @@ def test_subset_warnings_differently(self):
command2 = self._build_custom_command(
dataset_id, "thetao", -179.9, 179.9, "nearest"
)
output1 = execute_in_terminal(command1, input=b"n")
output2 = execute_in_terminal(command2, input=b"n")
self.output1 = execute_in_terminal(command1, input=b"n")
self.output2 = execute_in_terminal(command2, input=b"n")

assert (
b"Some or all of your subset selection [-180.0, 180.0] for the longitude "
b"dimension exceed the dataset coordinates [-180.0, 179.91668701171875]"
) in output1.stdout
) in self.output1.stderr
assert (
b"Some or all of your subset selection [-179.9, 179.9] for the longitude "
b"dimension exceed the dataset coordinates [-180.0, 179.91668701171875]"
) not in output2.stdout # Here they don't have to appear
) not in self.output2.stderr

def test_subset_warnings_when_surpassing(self):
# Dataset with longitude bounds from [-179.9791717529297, 179.9791717529297]
Expand All @@ -79,19 +77,19 @@ def test_subset_warnings_when_surpassing(self):
command2 = self._build_custom_command(
dataset_id, "CHL", -179.99, 179.99, "nearest"
)
output1 = execute_in_terminal(command1, input=b"n")
output2 = execute_in_terminal(command2, input=b"n")
self.output1 = execute_in_terminal(command1, input=b"n")
self.output2 = execute_in_terminal(command2, input=b"n")

assert (
b"Some or all of your subset selection [-180.0, 180.0] for the longitude "
b"dimension exceed the dataset coordinates "
b"[-179.9791717529297, 179.9791717529297]"
) in output1.stdout
) in self.output1.stderr
assert (
b"Some or all of your subset selection [-179.99, 179.99] for the longitude "
b"dimension exceed the dataset coordinates "
b"[-179.9791717529297, 179.9791717529297]"
) in output2.stdout
) in self.output2.stderr

def test_subset_strict_error(self):
dataset_id = (
Expand All @@ -104,21 +102,21 @@ def test_subset_strict_error(self):
command2 = self._build_custom_command(
dataset_id, "CHL", -179.9, 179.9, "strict"
)
output1 = execute_in_terminal(command1, input=b"n")
output2 = execute_in_terminal(command2, input=b"n")
self.output1 = execute_in_terminal(command1, input=b"n")
self.output2 = execute_in_terminal(command2, input=b"n")
assert (
b"""one was selected: "arco-geo-series"\nERROR"""
) in output1.stdout
) in self.output1.stderr
assert (
b"Some or all of your subset selection [-180.0, 180.0] for the longitude "
b"dimension exceed the dataset coordinates "
b"[-179.9791717529297, 179.9791717529297]"
) in output1.stdout
) in self.output1.stderr
assert (
b"""one was selected: "arco-geo-series"\nERROR"""
) not in output2.stdout
) not in self.output2.stderr
assert (
b"Some or all of your subset selection [-179.9, 179.9] for the longitude "
b"dimension exceed the dataset coordinates "
b"[-179.9791717529297, 179.9791717529297]"
) not in output2.stdout
) not in self.output2.stderr

0 comments on commit 0b1f229

Please sign in to comment.