-
Notifications
You must be signed in to change notification settings - Fork 214
/
test_config.py
200 lines (174 loc) · 5.77 KB
/
test_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
"""
Test pygmt.config.
"""
import pytest
from pygmt import Figure, config
@pytest.mark.mpl_image_compare
def test_config():
"""
Test if config works globally and locally.
"""
fig = Figure()
# Change global settings of current figure
config(FONT_ANNOT_PRIMARY="blue")
fig.basemap(
region=[0, 10, 0, 10], projection="X5c/5c", frame=["af", "+tBlue Annotation"]
)
with config(FONT_LABEL="red", FONT_ANNOT_PRIMARY="red"):
fig.shift_origin(xshift="7c")
fig.basemap(
region=[0, 10, 0, 10],
projection="X5c/5c",
frame=["xaf+lred label", "yaf", "+tred annotation"],
)
fig.shift_origin(xshift="7c")
fig.basemap(
region=[0, 10, 0, 10],
projection="X5c/5c",
frame=["af", "+tBlue Annotation"],
)
# Revert to default settings in current figure
config(FONT_ANNOT_PRIMARY="black")
return fig
@pytest.mark.mpl_image_compare
def test_config_font_one():
"""
Test that setting FONT config changes all FONT_* settings except FONT_LOGO.
Specifically, this test only checks that FONT_ANNOT_PRIMARY, FONT_ANNOT_SECONDARY,
FONT_LABEL, and FONT_TITLE are modified.
"""
fig = Figure()
with config(FONT="8p,red"):
fig.basemap(region=[0, 9, 0, 9], projection="C3/3/9c", compass="jTL+w3c+d4.5+l")
fig.basemap(compass="jBR+w3.5c+d-4.5+l")
return fig
@pytest.mark.mpl_image_compare
def test_config_font_annot():
"""
Test that setting FONT_ANNOT config changes both FONT_ANNOT_PRIMARY and
FONT_ANNOT_SECONDARY.
"""
fig = Figure()
with config(FONT_ANNOT="6p,red"):
fig.basemap(region=[0, 9, 0, 9], projection="C3/3/9c", compass="jTL+w3c+d4.5")
fig.basemap(compass="jBR+w3.5c+d-4.5")
return fig
@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_config_format_date_map():
"""
Test that setting FORMAT_DATE_MAP config changes how the output date string is
plotted.
Note the space in 'o dd', this acts as a regression test for
https://github.com/GenericMappingTools/pygmt/issues/247.
Setting FORMAT_DATE_MAP="yyyy mm dd" as a regression test for
https://github.com/GenericMappingTools/pygmt/issues/2298.
"""
fig = Figure()
# Set FORMAT_DATE_MAP to "yyyy mm dd" which contains whitespaces.
config(FORMAT_DATE_MAP="yyyy mm dd")
with config(FORMAT_DATE_MAP="o dd"):
fig.basemap(
region=["1969-7-21T", "1969-7-23T", 0, 1],
projection="X2.5c/0.1c",
frame=["sxa1D", "S"],
)
return fig
@pytest.mark.mpl_image_compare
def test_config_format_time_map():
"""
Test that setting FORMAT_TIME_MAP config changes both FORMAT_TIME_PRIMARY_MAP and
FORMAT_TIME_SECONDARY_MAP.
"""
fig = Figure()
with config(FORMAT_TIME_MAP="abbreviation"):
fig.basemap(
region=["2020-1-24T", "2020-1-27T", 0, 1],
projection="X6c/1c",
frame=["pa1K", "sa1K", "NWse"],
)
fig.basemap(frame=["pa1K", "sa1K", "nwSE"])
return fig
@pytest.mark.mpl_image_compare
def test_config_map_annot_offset():
"""
Test that setting MAP_ANNOT_OFFSET config changes both MAP_ANNOT_OFFSET_PRIMARY and
MAP_ANNOT_OFFSET_SECONDARY.
"""
fig = Figure()
with config(MAP_ANNOT_OFFSET="15p"):
fig.basemap(
region=["2020-1-24T", "2020-1-27T", 0, 1],
projection="X6c/1c",
frame=["pa1d", "sa1d", "NWse"],
)
fig.basemap(frame=["pa1d", "sa1d", "nwSE"])
return fig
@pytest.mark.mpl_image_compare
def test_config_map_grid_cross_size():
"""
Test that setting MAP_GRID_CROSS_SIZE config changes both
MAP_GRID_CROSS_SIZE_PRIMARY and MAP_GRID_CROSS_SIZE_SECONDARY.
"""
fig = Figure()
with config(MAP_GRID_CROSS_SIZE="3p"):
fig.basemap(
region=["2020-1-24T21:00", "2020-1-25T00:00", 0, 1],
projection="X6c/2c",
frame=["pa1Hg", "sa45mg45m", "NWse"],
verbose="e",
)
fig.shift_origin(yshift=-3)
fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="e")
return fig
@pytest.mark.mpl_image_compare
def test_config_map_grid_pen():
"""
Test that setting MAP_GRID_PEN config changes both MAP_GRID_PEN_PRIMARY and
MAP_GRID_PEN_SECONDARY.
"""
fig = Figure()
with config(MAP_GRID_PEN="thick,red"):
fig.basemap(
region=["2020-1-24T21:00", "2020-1-25T00:00", 0, 1],
projection="X6c/2c",
frame=["pa1Hg", "sa45mg45m", "NWse"],
verbose="e",
)
fig.shift_origin(yshift=-3)
fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="e")
return fig
@pytest.mark.mpl_image_compare
def test_config_map_tick_length():
"""
Test that setting MAP_TICK_LENGTH config changes both MAP_TICK_LENGTH_PRIMARY and
MAP_TICK_LENGTH_SECONDARY.
"""
fig = Figure()
with config(MAP_TICK_LENGTH="5p"):
fig.basemap(
region=["2020-1-24T21:00", "2020-1-25T00:00", 0, 1],
projection="X6c/2c",
frame=["pa1Hg", "sa45mg45m", "NWse"],
verbose="e",
)
fig.shift_origin(yshift=-3)
fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="e")
return fig
@pytest.mark.mpl_image_compare
def test_config_map_tick_pen():
"""
Test that setting MAP_TICK_PEN config changes both MAP_TICK_PEN_PRIMARY and
MAP_TICK_PEN_SECONDARY.
"""
fig = Figure()
with config(MAP_TICK_PEN="thick,red"):
fig.basemap(
region=["2020-1-24T21:00", "2020-1-25T00:00", 0, 1],
projection="X6c/2c",
frame=["pa1Hg", "sa45mg45m", "NWse"],
verbose="e",
)
fig.shift_origin(yshift=-3)
fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="e")
return fig