Skip to content

Commit bdecbcd

Browse files
separated out plot tests into external tests and added test for informative error message
1 parent d28aa41 commit bdecbcd

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

tests/test_plot.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
1+
import importlib
2+
13
import pytest
24

35
import traces
46

5-
6-
@pytest.mark.mpl_image_compare(
7-
savefig_kwargs={"bbox_inches": "tight", "dpi": 300},
8-
remove_text=True,
9-
style="ggplot",
10-
tolerance=20,
11-
)
12-
def test_plot():
13-
ts = traces.TimeSeries()
14-
ts[0] = 0
15-
ts[1] = 2
16-
ts[3] = 1
17-
ts[5] = 0
18-
19-
figure, axes = ts.plot()
20-
return figure
7+
matplotlib_importable = importlib.util.find_spec("matplotlib")
218

229

23-
def test_invalid_call():
10+
def _make_ts():
2411
ts = traces.TimeSeries()
2512
ts[0] = 0
2613
ts[1] = 1
14+
return ts
2715

28-
ts.plot(interpolate="previous")
29-
ts.plot(interpolate="linear")
3016

31-
with pytest.raises(ValueError):
32-
ts.plot(interpolate="yomama")
17+
def test_message_when_matplotlib_not_installed():
18+
"""When matplotlib is not importable, make sure that calling plot
19+
raises an informative error message.
3320
21+
"""
22+
if not matplotlib_importable:
23+
ts = _make_ts()
3424

35-
def test_empty():
36-
ts = traces.TimeSeries()
25+
with pytest.raises(ImportError) as error:
26+
ts.plot()
3727

38-
ts.plot()
28+
assert "need to install matplotlib" in str(error)

tests/test_plot_external.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
3+
import traces
4+
5+
6+
@pytest.mark.mpl_image_compare(
7+
savefig_kwargs={"bbox_inches": "tight", "dpi": 300},
8+
remove_text=True,
9+
style="ggplot",
10+
tolerance=20,
11+
)
12+
def test_plot():
13+
ts = traces.TimeSeries()
14+
ts[0] = 0
15+
ts[1] = 2
16+
ts[3] = 1
17+
ts[5] = 0
18+
19+
figure, axes = ts.plot()
20+
return figure
21+
22+
23+
def test_invalid_call():
24+
ts = traces.TimeSeries()
25+
ts[0] = 0
26+
ts[1] = 1
27+
28+
ts.plot(interpolate="previous")
29+
ts.plot(interpolate="linear")
30+
31+
with pytest.raises(ValueError):
32+
ts.plot(interpolate="yomama")
33+
34+
35+
def test_empty():
36+
ts = traces.TimeSeries()
37+
38+
ts.plot()

0 commit comments

Comments
 (0)