File tree Expand file tree Collapse file tree 2 files changed +52
-24
lines changed
Expand file tree Collapse file tree 2 files changed +52
-24
lines changed Original file line number Diff line number Diff line change 1+ import importlib
2+
13import pytest
24
35import 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 )
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments