4
4
import pytest
5
5
6
6
from matplotlib import _preprocess_data
7
-
7
+ from matplotlib .axes import Axes
8
+ from matplotlib .testing .decorators import check_figures_equal
8
9
9
10
# Notes on testing the plotting functions itself
10
11
# * the individual decorated plotting functions are tested in 'test_axes.py'
@@ -72,11 +73,18 @@ def test_function_call_without_data(func):
72
73
assert (func (None , x = "x" , y = "y" , label = "text" ) ==
73
74
"x: ['x'], y: ['y'], ls: x, w: xyz, label: text" )
74
75
76
+ @pytest .mark .parametrize ('func' , all_funcs , ids = all_func_ids )
77
+ def test_function_call_with_dict_input (func ):
78
+ """Tests with dict input, unpacking via preprocess_pipeline"""
79
+ data = {'a' : 1 , 'b' : 2 }
80
+ assert (func (None , data .keys (), data .values ()) ==
81
+ "x: ['a', 'b'], y: [1, 2], ls: x, w: xyz, label: None" )
82
+
75
83
76
84
@pytest .mark .parametrize ('func' , all_funcs , ids = all_func_ids )
77
85
def test_function_call_with_dict_data (func ):
78
86
"""Test with dict data -> label comes from the value of 'x' parameter."""
79
- data = {"a" : [1 , 2 ], "b" : [8 , 9 ], "w" : "NOT" }
87
+ data = {'a' : [1 , 2 ], 'b' : [8 , 9 ], "w" : "NOT" }
80
88
assert (func (None , "a" , "b" , data = data ) ==
81
89
"x: [1, 2], y: [8, 9], ls: x, w: xyz, label: b" )
82
90
assert (func (None , x = "a" , y = "b" , data = data ) ==
@@ -215,3 +223,29 @@ def funcy(ax, x, y, z, t=None):
215
223
assert not re .search (r"every other argument" , funcy .__doc__ )
216
224
assert not re .search (r"the following arguments .*: \*x\*, \*t\*\." ,
217
225
funcy .__doc__ )
226
+
227
+
228
+ class TestPlotTypes :
229
+ plotters = [Axes .scatter , Axes .bar , Axes .plot ]
230
+
231
+ @pytest .mark .parametrize ('plotter' , plotters )
232
+ @check_figures_equal (extensions = ['png' ])
233
+ def test_dict_unpack (self , plotter , fig_test , fig_ref ):
234
+ x = [1 ,2 ,3 ]
235
+ y = [4 ,5 ,6 ]
236
+ ddict = dict (zip (x ,y ))
237
+
238
+ plotter (fig_test .subplots (),
239
+ ddict .keys (), ddict .values ())
240
+ plotter (fig_ref .subplots (), x , y )
241
+
242
+ @pytest .mark .parametrize ('plotter' , plotters )
243
+ @check_figures_equal (extensions = ['png' ])
244
+ def test_data_kwarg (self , plotter , fig_test , fig_ref ):
245
+ x = [1 ,2 ,3 ]
246
+ y = [4 ,5 ,6 ]
247
+
248
+ plotter (fig_test .subplots (), 'xval' , 'yval' ,
249
+ data = {'xval' :x , 'yval' :y })
250
+ plotter (fig_ref .subplots (), x , y )
251
+
0 commit comments