Skip to content

Commit

Permalink
ignore HF HfHubHTTPError
Browse files Browse the repository at this point in the history
  • Loading branch information
younik committed Nov 27, 2024
1 parent 49f2c19 commit f7c3ee1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
from gymnasium import spaces
from gymnasium.utils.env_checker import data_equivalence
import pytest

import minari
from minari import DataCollector, EpisodeData, MinariDataset, StepData
Expand Down Expand Up @@ -702,3 +703,20 @@ def get_latest_compatible_dataset_id(namespace, dataset_name):

assert len(latest_compatible_versions) == 1
return gen_dataset_id(namespace, dataset_name, latest_compatible_versions[0])


def skip_if_error(error_type):
"""
A decorator to ignore specific error types during test execution.
:param error_type: The type of error to ignore
:return: Decorated test function
"""
def decorator(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except error_type:
pytest.skip(f"Skipping test due to {error_type.__name__}")
return wrapper
return decorator
6 changes: 5 additions & 1 deletion tests/dataset/test_dataset_download.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import pytest
from huggingface_hub.errors import HfHubHTTPError

import minari
from minari import MinariDataset
from minari.storage.datasets_root_dir import get_dataset_path
from tests.common import check_data_integrity, get_latest_compatible_dataset_id
from tests.common import check_data_integrity, get_latest_compatible_dataset_id, skip_if_error


env_names = ["pen", "door", "hammer", "relocate"]


@skip_if_error(HfHubHTTPError)
@pytest.mark.parametrize(
"dataset_id",
[
Expand Down Expand Up @@ -53,6 +55,7 @@ def test_download_dataset_from_farama_server(dataset_id: str):
assert dataset_id not in local_datasets


@skip_if_error(HfHubHTTPError)
@pytest.mark.parametrize(
"dataset_id",
[
Expand All @@ -73,6 +76,7 @@ def test_load_dataset_with_download(dataset_id: str):
minari.delete_dataset(dataset_id)


@skip_if_error(HfHubHTTPError)
def test_download_error_messages(monkeypatch):
# 1. Check if there are any remote versions of the dataset at all
with pytest.raises(ValueError, match="Couldn't find any version for dataset"):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

import pytest
from typer.testing import CliRunner
from huggingface_hub.errors import HfHubHTTPError

from minari.cli import app
from minari.storage.hosting import list_remote_datasets
from tests.common import skip_if_error
from tests.dataset.test_dataset_download import get_latest_compatible_dataset_id


runner = CliRunner()


@skip_if_error(HfHubHTTPError)
def test_list_app():
result = runner.invoke(app, ["list", "local", "--all"])
assert result.exit_code == 0
Expand All @@ -22,6 +25,7 @@ def test_list_app():
assert "Minari datasets in " in result.stdout


@skip_if_error(HfHubHTTPError)
@pytest.mark.parametrize(
"dataset_id",
[get_latest_compatible_dataset_id(namespace="D4RL/pen", dataset_name="human")],
Expand Down Expand Up @@ -51,6 +55,7 @@ def test_dataset_download_then_delete(dataset_id: str):
assert f"Dataset {dataset_id} deleted!" in result.stdout


@skip_if_error(HfHubHTTPError)
@pytest.mark.parametrize(
"dataset_id",
random.sample(
Expand Down

0 comments on commit f7c3ee1

Please sign in to comment.