Skip to content

Commit

Permalink
test: cover optional dependencies (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsorber authored Apr 19, 2024
1 parent 436ee11 commit b0af57d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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]

0 comments on commit b0af57d

Please sign in to comment.