Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: cover optional dependencies #17

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/conformal_tights/_darts_forecaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
_LikelihoodMixin,
)
except ImportError:
FUTURE_LAGS_TYPE = int
LAGS_TYPE = list[int]
FUTURE_LAGS_TYPE = tuple[int, int] | list[int] | dict[str, tuple[int, int] | list[int]]
LAGS_TYPE = int | list[int] | dict[str, int | list[int]]

class TimeSeries: ...

Expand Down
30 changes: 30 additions & 0 deletions tests/test_optional_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Test this package's optional dependencies."""

import sys
from unittest.mock import patch

import pytest


@pytest.mark.parametrize("optional_dependency", ["darts", "pandas"])
def test_optional_dependencies(optional_dependency: str) -> None:
"""Test that we get an expected error when an optional dependency are not available."""
# Prevent the optional dependency from being loaded.
with patch.dict("sys.modules", {optional_dependency: None}):
# Unload Conformal Tights.
mods_to_unload = [mod for mod in sys.modules if mod.startswith("conformal_tights")]
for mod in mods_to_unload:
del sys.modules[mod]

# Reload Conformal Tights now that the selected optional dependency is not available.
from conformal_tights import ConformalCoherentQuantileRegressor, DartsForecaster

# Test that we raise the appropriate error.
conformal_predictor = ConformalCoherentQuantileRegressor()
with pytest.raises(ImportError, match=f".*install.*{optional_dependency}.*"):
_ = DartsForecaster(model=conformal_predictor)

# Unload Conformal Tights again.
mods_to_unload = [mod for mod in sys.modules if mod.startswith("conformal_tights")]
for mod in mods_to_unload:
del sys.modules[mod]