@@ -571,7 +571,8 @@ def test_invalid_layouts():
571
571
572
572
# test that layouts can be swapped if no colorbar:
573
573
fig , ax = plt .subplots (layout = "constrained" )
574
- fig .set_layout_engine ("tight" )
574
+ with pytest .warns (UserWarning ):
575
+ fig .set_layout_engine ("tight" )
575
576
assert isinstance (fig .get_layout_engine (), TightLayoutEngine )
576
577
fig .set_layout_engine ("constrained" )
577
578
assert isinstance (fig .get_layout_engine (), ConstrainedLayoutEngine )
@@ -581,7 +582,8 @@ def test_invalid_layouts():
581
582
pc = ax .pcolormesh (np .random .randn (2 , 2 ))
582
583
fig .colorbar (pc )
583
584
with pytest .raises (RuntimeError , match = 'Colorbar layout of new layout' ):
584
- fig .set_layout_engine ("tight" )
585
+ with pytest .warns (UserWarning ):
586
+ fig .set_layout_engine ("tight" )
585
587
fig .set_layout_engine ("none" )
586
588
with pytest .raises (RuntimeError , match = 'Colorbar layout of new layout' ):
587
589
fig .set_layout_engine ("tight" )
@@ -598,6 +600,14 @@ def test_invalid_layouts():
598
600
fig .set_layout_engine ("constrained" )
599
601
600
602
603
+ @pytest .mark .parametrize ('layout' , ['constrained' , 'compressed' ])
604
+ def test_layout_change_warning (layout ):
605
+ """Raise a warning when an existing layout manager is changed to tight."""
606
+ fig , ax = plt .subplots (layout = layout )
607
+ with pytest .warns (UserWarning , match = 'The layout manager has been' ):
608
+ plt .tight_layout ()
609
+
610
+
601
611
@check_figures_equal (extensions = ["png" , "pdf" ])
602
612
def test_add_artist (fig_test , fig_ref ):
603
613
fig_test .dpi = 100
0 commit comments