11import matplotlib .pyplot as plt
22import numpy as np
3- from pytest import raises
3+ import pytest
44
5- from mplotutils .colorbar_utils import (
5+ from mplotutils ._colorbar import (
66 _get_cbax ,
77 _parse_shift_shrink ,
88 _parse_size_aspect_pad ,
@@ -25,54 +25,72 @@ def test_parse_shift_shrink():
2525
2626 assert _parse_shift_shrink (0.5 , 0.5 ) == (0.5 , 0.5 )
2727
28- with raises (AssertionError ):
28+ with pytest . raises (ValueError , match = "'shift' must be in 0...1" ):
2929 _parse_shift_shrink (- 0.1 , 0 )
3030
31- with raises (AssertionError ):
31+ with pytest . raises (ValueError , match = "'shift' must be in 0...1" ):
3232 _parse_shift_shrink (1.1 , 0 )
3333
34- with raises (AssertionError ):
34+ with pytest . raises (ValueError , match = "'shrink' must be in 0...1" ):
3535 _parse_shift_shrink (0 , - 0.1 )
3636
37- with raises (AssertionError ):
37+ with pytest . raises (ValueError , match = "'shrink' must be in 0...1" ):
3838 _parse_shift_shrink (0 , 1.1 )
3939
40-
41- # =============================================================================
40+ with pytest . warns ( UserWarning , match = "'shift' is larger than 'shrink'" ):
41+ _parse_shift_shrink ( 0.6 , 0.3 )
4242
4343
4444def test_parse_size_aspect_pad ():
4545 """
4646 size, aspect, pad = _parse_size_aspect_pad(size, aspect, pad, 'horizontal')
4747 """
4848
49- res = _parse_size_aspect_pad (0.1 , None , 0.1 , "horizontal" )
50- exp = (0.1 , None , 0.1 )
51- assert res == exp
49+ with pytest .raises (ValueError , match = "Can only pass one of 'aspect' and 'size'" ):
50+ _parse_size_aspect_pad (1 , 1 , 0.1 , "horizontal" )
5251
53- res = _parse_size_aspect_pad (None , None , 0.1 , "horizontal" )
54- exp = (10 , 20 , 0.1 )
55- assert res == exp
52+ result = _parse_size_aspect_pad (0.1 , None , 0.1 , "horizontal" )
53+ assert result == (0.1 , None , 0.1 )
5654
57- res = _parse_size_aspect_pad (None , 20 , 0.1 , "horizontal" )
58- exp = (10 , 20 , 0.1 )
59- assert res == exp
55+ result = _parse_size_aspect_pad (None , None , 0.1 , "horizontal" )
56+ assert result == (None , 20 , 0.1 )
6057
61- with raises (ValueError ):
62- _parse_size_aspect_pad (1 , 1 , 0.1 , "horizontal" )
58+ result = _parse_size_aspect_pad (None , 10 , 0.1 , "horizontal" )
59+ assert result == (None , 10 , 0.1 )
60+
61+ result = _parse_size_aspect_pad (None , 20 , 0.1 , "horizontal" )
62+ assert result == (None , 20 , 0.1 )
6363
64- res = _parse_size_aspect_pad (None , None , None , "horizontal" )
65- exp = (10 , 20 , 0.15 )
66- assert res == exp
64+ result = _parse_size_aspect_pad (None , None , None , "horizontal" )
65+ assert result == (None , 20 , 0.15 )
6766
68- res = _parse_size_aspect_pad (None , None , None , "vertical" )
69- exp = (10 , 20 , 0.05 )
70- assert res == exp
67+ result = _parse_size_aspect_pad (None , None , None , "vertical" )
68+ assert result == (None , 20 , 0.05 )
7169
7270
7371# =============================================================================
7472
7573
74+ def test_colorbar_differnt_figures ():
75+
76+ _ , ax1 = plt .subplots ()
77+ _ , ax2 = plt .subplots ()
78+
79+ h = ax1 .pcolormesh ([[0 , 1 ]])
80+
81+ with pytest .raises (ValueError , match = "must belong to the same figure" ):
82+ colorbar (h , ax1 , ax2 )
83+
84+
85+ def test_colorbar_ax_and_ax2_error ():
86+
87+ _ , (ax1 , ax2 , ax3 ) = plt .subplots (3 , 1 )
88+ h = ax1 .pcolormesh ([[0 , 1 ]])
89+
90+ with pytest .raises (ValueError , match = "Cannot pass `ax`, and `ax2`" ):
91+ colorbar (h , ax1 , ax2 , ax = ax3 )
92+
93+
7694def _easy_cbar_vert (** kwargs ):
7795
7896 f , ax = plt .subplots ()
@@ -363,19 +381,15 @@ def test_colorbar():
363381 f1 , ax1 = plt .subplots ()
364382 h = ax1 .pcolormesh ([[0 , 1 ]])
365383
366- with raises (ValueError ):
384+ with pytest . raises (ValueError ):
367385 colorbar (h , ax1 , orientation = "wrong" )
368386
369- with raises (ValueError ):
387+ with pytest . raises (ValueError ):
370388 colorbar (h , ax1 , anchor = 5 )
371389
372- with raises (ValueError ):
390+ with pytest . raises (ValueError ):
373391 colorbar (h , ax1 , panchor = 5 )
374392
375- with raises (AssertionError ):
376- f2 , ax2 = plt .subplots ()
377- colorbar (h , ax1 , ax2 )
378-
379393
380394# =============================================================================
381395
0 commit comments