()
| 711 | |
| 712 | |
| 713 | def test_invalid_layouts(): |
| 714 | fig, ax = plt.subplots(layout="constrained") |
| 715 | with pytest.warns(UserWarning): |
| 716 | # this should warn, |
| 717 | fig.subplots_adjust(top=0.8) |
| 718 | assert isinstance(fig.get_layout_engine(), ConstrainedLayoutEngine) |
| 719 | |
| 720 | # Using layout + (tight|constrained)_layout warns, but the former takes |
| 721 | # precedence. |
| 722 | wst = "The Figure parameters 'layout' and 'tight_layout'" |
| 723 | with pytest.warns(UserWarning, match=wst): |
| 724 | fig = Figure(layout='tight', tight_layout=False) |
| 725 | assert isinstance(fig.get_layout_engine(), TightLayoutEngine) |
| 726 | wst = "The Figure parameters 'layout' and 'constrained_layout'" |
| 727 | with pytest.warns(UserWarning, match=wst): |
| 728 | fig = Figure(layout='constrained', constrained_layout=False) |
| 729 | assert not isinstance(fig.get_layout_engine(), TightLayoutEngine) |
| 730 | assert isinstance(fig.get_layout_engine(), ConstrainedLayoutEngine) |
| 731 | |
| 732 | with pytest.raises(ValueError, |
| 733 | match="Invalid value for 'layout'"): |
| 734 | Figure(layout='foobar') |
| 735 | |
| 736 | # test that layouts can be swapped if no colorbar: |
| 737 | fig, ax = plt.subplots(layout="constrained") |
| 738 | fig.set_layout_engine("tight") |
| 739 | assert isinstance(fig.get_layout_engine(), TightLayoutEngine) |
| 740 | fig.set_layout_engine("constrained") |
| 741 | assert isinstance(fig.get_layout_engine(), ConstrainedLayoutEngine) |
| 742 | |
| 743 | # test that layouts cannot be swapped if there is a colorbar: |
| 744 | fig, ax = plt.subplots(layout="constrained") |
| 745 | pc = ax.pcolormesh(np.random.randn(2, 2)) |
| 746 | fig.colorbar(pc) |
| 747 | with pytest.raises(RuntimeError, match='Colorbar layout of new layout'): |
| 748 | fig.set_layout_engine("tight") |
| 749 | fig.set_layout_engine("none") |
| 750 | with pytest.raises(RuntimeError, match='Colorbar layout of new layout'): |
| 751 | fig.set_layout_engine("tight") |
| 752 | |
| 753 | fig, ax = plt.subplots(layout="tight") |
| 754 | pc = ax.pcolormesh(np.random.randn(2, 2)) |
| 755 | fig.colorbar(pc) |
| 756 | with pytest.raises(RuntimeError, match='Colorbar layout of new layout'): |
| 757 | fig.set_layout_engine("constrained") |
| 758 | fig.set_layout_engine("none") |
| 759 | assert isinstance(fig.get_layout_engine(), PlaceHolderLayoutEngine) |
| 760 | |
| 761 | with pytest.raises(RuntimeError, match='Colorbar layout of new layout'): |
| 762 | fig.set_layout_engine("constrained") |
| 763 | |
| 764 | |
| 765 | @check_figures_equal() |
nothing calls this directly
no test coverage detected
searching dependent graphs…