@@ -501,13 +501,44 @@ def test_figure_repr():
501501 assert repr (fig ) == "<Figure size 100x200 with 0 Axes>"
502502
503503
504- def test_warn_cl_plus_tl ():
504+ def test_valid_layouts ():
505+ fig = Figure (layout = None )
506+ assert not fig .get_tight_layout ()
507+ assert not fig .get_constrained_layout ()
508+
509+ fig = Figure (layout = 'tight' )
510+ assert fig .get_tight_layout ()
511+ assert not fig .get_constrained_layout ()
512+
513+ fig = Figure (layout = 'constrained' )
514+ assert not fig .get_tight_layout ()
515+ assert fig .get_constrained_layout ()
516+
517+
518+ def test_invalid_layouts ():
505519 fig , ax = plt .subplots (constrained_layout = True )
506520 with pytest .warns (UserWarning ):
507521 # this should warn,
508522 fig .subplots_adjust (top = 0.8 )
509523 assert not (fig .get_constrained_layout ())
510524
525+ # Using layout + (tight|constrained)_layout warns, but the former takes
526+ # precedence.
527+ with pytest .warns (UserWarning , match = "Figure parameters 'layout' and "
528+ "'tight_layout' cannot" ):
529+ fig = Figure (layout = 'tight' , tight_layout = False )
530+ assert fig .get_tight_layout ()
531+ assert not fig .get_constrained_layout ()
532+ with pytest .warns (UserWarning , match = "Figure parameters 'layout' and "
533+ "'constrained_layout' cannot" ):
534+ fig = Figure (layout = 'constrained' , constrained_layout = False )
535+ assert not fig .get_tight_layout ()
536+ assert fig .get_constrained_layout ()
537+
538+ with pytest .raises (ValueError ,
539+ match = "'foobar' is not a valid value for layout" ):
540+ Figure (layout = 'foobar' )
541+
511542
512543@check_figures_equal (extensions = ["png" , "pdf" ])
513544def test_add_artist (fig_test , fig_ref ):
0 commit comments