55import pytest
66from pygmt import Figure
77from pygmt .alias import AliasSystem
8+ from pygmt .exceptions import GMTInvalidInput
89from pygmt .params .position import Position
910from pygmt .src .colorbar import _alias_option_D
1011
@@ -16,7 +17,12 @@ def test_colorbar():
1617 Create a simple colorbar.
1718 """
1819 fig = Figure ()
19- fig .colorbar (cmap = "gmt/rainbow" , position = "x0c/0c+w4c" , frame = True )
20+ fig .colorbar (
21+ cmap = "gmt/rainbow" ,
22+ position = Position ((0 , 0 ), cstype = "plotcoords" ),
23+ length = 4 ,
24+ frame = True ,
25+ )
2026 return fig
2127
2228
@@ -63,3 +69,36 @@ def alias_wrapper(**kwargs):
6369
6470 assert alias_wrapper (move_text = ["annotations" , "label" , "unit" ]) == "+malu"
6571 assert alias_wrapper (label_as_column = True ) == "+mc"
72+
73+
74+ @pytest .mark .mpl_image_compare (filename = "test_colorbar.png" )
75+ def test_colorbar_position_deprecated_syntax ():
76+ """
77+ Check that passing the deprecated GMT CLI syntax string to 'position' works.
78+ """
79+ fig = Figure ()
80+ fig .colorbar (cmap = "gmt/rainbow" , position = "x0/0+w4c" , frame = True )
81+ return fig
82+
83+
84+ def test_image_position_mixed_syntax ():
85+ """
86+ Test that mixing deprecated GMT CLI syntax string with new parameters.
87+ """
88+ fig = Figure ()
89+ with pytest .raises (GMTInvalidInput ):
90+ fig .colorbar (cmap = "gmt/rainbow" , position = "x0/0" , length = "4c" )
91+ with pytest .raises (GMTInvalidInput ):
92+ fig .colorbar (cmap = "gmt/rainbow" , position = "x0/0" , width = "0.5c" )
93+ with pytest .raises (GMTInvalidInput ):
94+ fig .colorbar (cmap = "gmt/rainbow" , position = "x0/0" , orientation = "horizontal" )
95+ with pytest .raises (GMTInvalidInput ):
96+ fig .colorbar (cmap = "gmt/rainbow" , position = "x0/0" , reverse = True )
97+ with pytest .raises (GMTInvalidInput ):
98+ fig .colorbar (cmap = "gmt/rainbow" , position = "x0/0" , nan_rectangle = True )
99+ with pytest .raises (GMTInvalidInput ):
100+ fig .colorbar (cmap = "gmt/rainbow" , position = "x0/0" , sidebar_triangles = True )
101+ with pytest .raises (GMTInvalidInput ):
102+ fig .colorbar (cmap = "gmt/rainbow" , position = "x0/0" , move_text = ["label" ])
103+ with pytest .raises (GMTInvalidInput ):
104+ fig .colorbar (cmap = "gmt/rainbow" , position = "x0/0" , label_as_column = True )
0 commit comments