@@ -501,13 +501,44 @@ def test_figure_repr():
501
501
assert repr (fig ) == "<Figure size 100x200 with 0 Axes>"
502
502
503
503
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 ():
505
519
fig , ax = plt .subplots (constrained_layout = True )
506
520
with pytest .warns (UserWarning ):
507
521
# this should warn,
508
522
fig .subplots_adjust (top = 0.8 )
509
523
assert not (fig .get_constrained_layout ())
510
524
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
+
511
542
512
543
@check_figures_equal (extensions = ["png" , "pdf" ])
513
544
def test_add_artist (fig_test , fig_ref ):
0 commit comments