From df5382c83d5f068888559c7cf3a47ce6a686713c Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Tue, 31 Aug 2021 20:38:06 -0400 Subject: [PATCH] Add tests for Plot.on input validation --- seaborn/tests/_core/test_plot.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/seaborn/tests/_core/test_plot.py b/seaborn/tests/_core/test_plot.py index fdfe1b045c..fea5c85d93 100644 --- a/seaborn/tests/_core/test_plot.py +++ b/seaborn/tests/_core/test_plot.py @@ -694,6 +694,9 @@ def test_on_figure(self, facet): assert m.passed_axes == f.axes assert p._figure is f + @pytest.mark.skipif( + LooseVersion(mpl.__version__) < "3.4", reason="mpl<3.4 does not have SubFigure", + ) @pytest.mark.parametrize("facet", [True, False]) def test_on_subfigure(self, facet): @@ -707,6 +710,24 @@ def test_on_subfigure(self, facet): assert m.passed_axes == sf2.figure.axes[1:] assert p._figure is sf2.figure + def test_on_type_check(self): + + p = Plot() + with pytest.raises(TypeError, match="The `Plot.on`.+"): + p.on([]) + + def test_on_axes_with_subplots_error(self): + + ax = mpl.figure.Figure().subplots() + + p1 = Plot().facet(["a", "b"]).on(ax) + with pytest.raises(RuntimeError, match="Cannot create multiple subplots"): + p1.plot() + + p2 = Plot().pair([["a", "b"], ["x", "y"]]).on(ax) + with pytest.raises(RuntimeError, match="Cannot create multiple subplots"): + p2.plot() + class TestFacetInterface: