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