Skip to content

Commit 0cdf8e4

Browse files
committed
test: respect optional holoviews dependency in LearnerND plot test
1 parent a5ee55b commit 0cdf8e4

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

adaptive/tests/unit/test_learnernd.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
from scipy.spatial import ConvexHull
66

7+
import adaptive.notebook_integration as notebook_integration
78
from adaptive.learner.base_learner import uses_nth_neighbors
89
from adaptive.learner.learnerND import (
910
LearnerND,
@@ -152,9 +153,28 @@ def f_vec(x):
152153
assert np.isclose(result[1], 0.0)
153154

154155

156+
def test_learnerND_1d_plot_requires_holoviews(monkeypatch):
157+
"""Test that plotting fails with a clear error without holoviews."""
158+
159+
import_module = notebook_integration.importlib.import_module
160+
161+
def missing_holoviews(name):
162+
if name == "holoviews":
163+
raise ModuleNotFoundError
164+
return import_module(name)
165+
166+
monkeypatch.setattr(notebook_integration.importlib, "import_module", missing_holoviews)
167+
168+
learner = make_1d_learner()
169+
tell_1d_points(learner)
170+
171+
with pytest.raises(RuntimeError, match="holoviews is not installed; plotting is disabled."):
172+
learner.plot()
173+
174+
155175
def test_learnerND_1d_plot():
156176
"""Test that 1D plot() does not crash."""
157-
import holoviews as hv
177+
hv = pytest.importorskip("holoviews")
158178

159179
hv.extension("bokeh")
160180
learner = make_1d_learner()

0 commit comments

Comments
 (0)