Skip to content

Commit

Permalink
Fix cache for old functools versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Feb 8, 2024
1 parent 3ea4e02 commit 149b8b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gpm_api/io/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def check_remote_storage(storage):
return storage.lower()


@functools.cache
@functools.lru_cache(maxsize=None)
def check_transfer_tool(transfer_tool):
"""Check the transfer tool."""
valid_transfer_tools = ["curl", "wget"]
if transfer_tool not in valid_transfer_tools:
raise ValueError(
f"{transfer_tool} is an invalid 'transfer_tool'. Valid values are {valid_transfer_tools}."
f"'{transfer_tool}' is an invalid 'transfer_tool'. Valid values are {valid_transfer_tools}."
)

# Check WGET or CURL is installed
Expand Down
22 changes: 22 additions & 0 deletions gpm_api/tests/test_io/test_io_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from typing import List, Dict, Any
from gpm_api.io import checks
from gpm_api.io.products import available_products, available_scan_modes, available_product_versions
from pytest_mock.plugin import MockerFixture
from subprocess import CalledProcessError


def test_check_base_dir() -> None:
Expand Down Expand Up @@ -180,6 +182,26 @@ def test_check_remote_storage() -> None:
checks.check_remote_storage(123)


def test_check_transfer_tool(mocker: MockerFixture):
"""Test check_transfer_tool()"""
# Assert "curl" is available and return "curl"
transfer_tool = "curl" # "wget" is not mandatory
assert checks.check_transfer_tool(transfer_tool=transfer_tool) == transfer_tool

# Test the function with an invalid transfer tool
invalid_tool = "invalid_tool"
with pytest.raises(ValueError) as exc_info:
checks.check_transfer_tool(transfer_tool=invalid_tool)
assert f"'{invalid_tool}' is an invalid 'transfer_tool'." in str(exc_info.value)

# Test the function with a valid transfer tool that is not installed
transfer_tool = "wget"
mocker.patch("subprocess.run", side_effect=CalledProcessError(1, [transfer_tool, "--version"]))
with pytest.raises(ValueError) as exc_info:
checks.check_transfer_tool(transfer_tool)
assert f"{transfer_tool.upper()} is not installed on your machine !" in str(exc_info.value)


def test_check_version(
versions: List[int],
) -> None:
Expand Down

0 comments on commit 149b8b9

Please sign in to comment.