-
Notifications
You must be signed in to change notification settings - Fork 214
/
test_grd2cpt.py
73 lines (58 loc) · 1.86 KB
/
test_grd2cpt.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
"""
Test pygmt.grd2cpt.
"""
import os
import pytest
from pygmt import Figure, grd2cpt
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile
from pygmt.helpers.testing import load_static_earth_relief
@pytest.fixture(scope="module", name="grid")
def fixture_grid():
"""
Load the grid data from the sample earth_relief file.
"""
return load_static_earth_relief()
@pytest.mark.mpl_image_compare
def test_grd2cpt(grid):
"""
Test creating a CPT with grd2cpt to create a CPT based off a grid input and
plot it with a color bar.
"""
fig = Figure()
fig.basemap(frame="a", projection="W0/15c", region="d")
grd2cpt(grid=grid)
fig.colorbar(frame="a")
return fig
def test_grd2cpt_blank_output(grid):
"""
Use incorrect setting by passing in blank file name to output parameter.
"""
with pytest.raises(GMTInvalidInput):
grd2cpt(grid=grid, output="")
def test_grd2cpt_invalid_output(grid):
"""
Use incorrect setting by passing in invalid type to output parameter.
"""
with pytest.raises(GMTInvalidInput):
grd2cpt(grid=grid, output=["some.cpt"])
def test_grd2cpt_output_to_cpt_file(grid):
"""
Save the generated static color palette table to a .cpt file.
"""
with GMTTempFile(suffix=".cpt") as cptfile:
grd2cpt(grid=grid, output=cptfile.name)
assert os.path.getsize(cptfile.name) > 0
def test_grd2cpt_unrecognized_data_type():
"""
Test that an error will be raised if an invalid data type is passed to
grid.
"""
with pytest.raises(GMTInvalidInput):
grd2cpt(grid=0)
def test_grd2cpt_categorical_and_cyclic(grid):
"""
Use incorrect setting by setting both categorical and cyclic to True.
"""
with pytest.raises(GMTInvalidInput):
grd2cpt(grid=grid, cmap="batlow", categorical=True, cyclic=True)