-
Notifications
You must be signed in to change notification settings - Fork 214
/
test_solar.py
120 lines (107 loc) · 3.03 KB
/
test_solar.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
"""
Test Figure.solar.
"""
import datetime
import pytest
from pygmt import Figure
from pygmt.exceptions import GMTInvalidInput
@pytest.mark.mpl_image_compare
def test_solar_terminators():
"""
Test passing the solar argument with a time string and no terminator type
to confirm the default terminator type.
"""
fig = Figure()
fig.basemap(region="d", projection="W0/15c", frame="a")
fig.solar(
terminator="d",
pen="1p,blue",
terminator_datetime="1990-02-17 04:25:00",
)
fig.solar(
terminator="a",
pen="1p,red",
terminator_datetime="1990-02-17 04:25:00",
)
fig.solar(
terminator="c",
pen="1p,green",
terminator_datetime="1990-02-17 04:25:00",
)
fig.solar(
terminator="n",
pen="1p,yellow",
terminator_datetime="1990-02-17 04:25:00",
)
return fig
@pytest.mark.mpl_image_compare(filename="test_solar_set_terminator_datetime.png")
@pytest.mark.parametrize(
"terminator_datetime",
[
pytest.param("1990-02-17 04:25:00", id="terminator_datetime_string"),
datetime.datetime(year=1990, month=2, day=17, hour=4, minute=25, second=0),
],
)
def test_solar_set_terminator_datetime(terminator_datetime):
"""
Test passing the solar argument with the day_night terminator and a
datetime string.
"""
fig = Figure()
fig.solar(
region="d",
projection="W0/15c",
frame="a",
terminator="day_night",
terminator_datetime=terminator_datetime,
)
return fig
def test_invalid_terminator_type():
"""
Test if solar fails when it receives an invalid terminator type.
"""
fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.solar(
region="d",
projection="W0/15c",
frame="a",
terminator="invalid",
)
def test_invalid_parameter():
"""
Test if solar fails when it receives a GMT argument for 'T' instead of the
PyGMT arguments for 'terminator' and 'terminator_datetime'.
"""
fig = Figure()
with pytest.raises(GMTInvalidInput):
# Use single-letter parameter 'T' for testing
fig.solar(
region="d", projection="W0/15c", frame="a", T="d+d1990-02-17T04:25:00"
)
def test_invalid_datetime():
"""
Test if solar fails when it receives an invalid datetime string.
"""
fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.solar(
region="d",
projection="W0/15c",
frame="a",
terminator_datetime="199A-02-17 04:25:00",
)
@pytest.mark.mpl_image_compare(filename="test_solar_set_terminator_datetime.png")
def test_solar_default_terminator():
"""
Test passing the solar argument with a time string and no terminator type
to confirm the default terminator type.
"""
fig = Figure()
fig.solar(
region="d",
projection="W0/15c",
frame="a",
terminator_datetime="1990-02-17 04:25:00",
)
return fig