Skip to content

Commit 18aaa0e

Browse files
committed
TST: improve coverage
1 parent b579280 commit 18aaa0e

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

lib/matplotlib/figure.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2494,8 +2494,7 @@ def set_tight_layout(self, tight):
24942494
tight = mpl.rcParams['figure.autolayout']
24952495
_tight_parameters = tight if isinstance(tight, dict) else {}
24962496
if bool(tight):
2497-
self.set_layout_engine(TightLayoutEngine(self,
2498-
**_tight_parameters))
2497+
self.set_layout_engine(TightLayoutEngine(**_tight_parameters))
24992498
self.stale = True
25002499

25012500
def get_constrained_layout(self):
@@ -2528,8 +2527,7 @@ def set_constrained_layout(self, constrained):
25282527
_constrained = bool(constrained)
25292528
_parameters = constrained if isinstance(constrained, dict) else {}
25302529
if _constrained:
2531-
self.set_layout_engine(ConstrainedLayoutEngine(self,
2532-
**_parameters))
2530+
self.set_layout_engine(ConstrainedLayoutEngine(**_parameters))
25332531
self.stale = True
25342532

25352533
@_api.deprecated(

lib/matplotlib/tests/test_constrainedlayout.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
12
import numpy as np
23
import pytest
34

@@ -567,3 +568,20 @@ def test_gridspec_addressing():
567568
gs = fig.add_gridspec(3, 3)
568569
sp = fig.add_subplot(gs[0:, 1:])
569570
fig.draw_without_rendering()
571+
572+
573+
def test_discouraged_api():
574+
fig, ax = plt.subplots(constrained_layout=True)
575+
fig.draw_without_rendering()
576+
577+
with pytest.warns(MatplotlibDeprecationWarning,
578+
match="was deprecated in Matplotlib 3.6"):
579+
fig, ax = plt.subplots()
580+
fig.set_constrained_layout(True)
581+
fig.draw_without_rendering()
582+
583+
with pytest.warns(MatplotlibDeprecationWarning,
584+
match="was deprecated in Matplotlib 3.6"):
585+
fig, ax = plt.subplots()
586+
fig.set_constrained_layout({'w_pad': 0.02, 'h_pad': 0.02})
587+
fig.draw_without_rendering()

lib/matplotlib/tests/test_tightlayout.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import warnings
2+
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
23

34
import numpy as np
45
from numpy.testing import assert_array_equal
@@ -367,3 +368,11 @@ def test_clipped_to_axes():
367368
m.set_clip_path(rect.get_path(), rect.get_transform())
368369
assert not h._fully_clipped_to_axes()
369370
assert not m._fully_clipped_to_axes()
371+
372+
373+
def test_tight_pads():
374+
fig, ax = plt.subplots()
375+
with pytest.warns(MatplotlibDeprecationWarning,
376+
match='was deprecated in Matplotlib 3.6'):
377+
fig.set_tight_layout({'pad': 0.15})
378+
fig.draw_without_rendering()

0 commit comments

Comments
 (0)