Skip to content

Commit 767eec4

Browse files
Change test_grdvolume.py to use static_earth_relief (#1747)
1 parent 9fa3b66 commit 767eec4

File tree

1 file changed

+29
-40
lines changed

1 file changed

+29
-40
lines changed

pygmt/tests/test_grdvolume.py

+29-40
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@
88
import pandas as pd
99
import pytest
1010
from pygmt import grdvolume
11-
from pygmt.datasets import load_earth_relief
1211
from pygmt.exceptions import GMTInvalidInput
1312
from pygmt.helpers import GMTTempFile
13+
from pygmt.helpers.testing import load_static_earth_relief
1414

1515

1616
@pytest.fixture(scope="module", name="grid")
1717
def fixture_grid():
1818
"""
1919
Load the grid data from the sample earth_relief file.
2020
"""
21-
return load_earth_relief(resolution="01d", region=[-100, -95, 34, 39])
21+
return load_static_earth_relief()
22+
23+
24+
@pytest.fixture(scope="module", name="region")
25+
def fixture_region():
26+
"""
27+
Set the data region for the tests.
28+
"""
29+
return [-53, -50, -22, -20]
2230

2331

2432
@pytest.fixture(scope="module", name="data")
@@ -28,50 +36,25 @@ def fixture_data():
2836
"""
2937
data = np.array(
3038
[
31-
[
32-
2.00000000e02,
33-
1.59920815e11,
34-
3.16386172e13,
35-
1.97839269e02,
36-
],
37-
[
38-
2.50000000e02,
39-
1.44365835e11,
40-
2.38676788e13,
41-
1.65327751e02,
42-
],
43-
[
44-
3.00000000e02,
45-
1.23788259e11,
46-
1.71278707e13,
47-
1.38364259e02,
48-
],
49-
[
50-
3.50000000e02,
51-
9.79597525e10,
52-
1.15235913e13,
53-
1.17635978e02,
54-
],
55-
[
56-
4.00000000e02,
57-
7.26646663e10,
58-
7.22303463e12,
59-
9.94022955e01,
60-
],
39+
[2.00000000e02, 2.30079975e10, 3.92142453e12, 1.70437454e02],
40+
[2.50000000e02, 2.30079975e10, 2.77102465e12, 1.20437454e02],
41+
[3.00000000e02, 2.30079975e10, 1.62062477e12, 7.04374542e01],
42+
[3.50000000e02, 1.76916116e10, 4.53991397e11, 2.56613930e01],
43+
[4.00000000e02, 2.81602292e09, 2.34764859e10, 8.33675242e00],
6144
]
6245
)
6346
return data
6447

6548

66-
def test_grdvolume_format(grid):
49+
def test_grdvolume_format(grid, region):
6750
"""
6851
Test that correct formats are returned.
6952
"""
70-
grdvolume_default = grdvolume(grid=grid)
53+
grdvolume_default = grdvolume(grid=grid, region=region)
7154
assert isinstance(grdvolume_default, pd.DataFrame)
72-
grdvolume_array = grdvolume(grid=grid, output_type="numpy")
55+
grdvolume_array = grdvolume(grid=grid, output_type="numpy", region=region)
7356
assert isinstance(grdvolume_array, np.ndarray)
74-
grdvolume_df = grdvolume(grid=grid, output_type="pandas")
57+
grdvolume_df = grdvolume(grid=grid, output_type="pandas", region=region)
7558
assert isinstance(grdvolume_df, pd.DataFrame)
7659

7760

@@ -92,21 +75,27 @@ def test_grdvolume_no_outfile(grid):
9275
grdvolume(grid=grid, output_type="file")
9376

9477

95-
def test_grdvolume_no_outgrid(grid, data):
78+
def test_grdvolume_no_outgrid(grid, data, region):
9679
"""
9780
Test the expected output of grdvolume with no output file set.
9881
"""
99-
test_output = grdvolume(grid=grid, contour=[200, 400, 50], output_type="numpy")
82+
test_output = grdvolume(
83+
grid=grid, contour=[200, 400, 50], output_type="numpy", region=region
84+
)
10085
npt.assert_allclose(test_output, data)
10186

10287

103-
def test_grdvolume_outgrid(grid):
88+
def test_grdvolume_outgrid(grid, region):
10489
"""
10590
Test the expected output of grdvolume with an output file set.
10691
"""
10792
with GMTTempFile(suffix=".csv") as tmpfile:
10893
result = grdvolume(
109-
grid=grid, contour=[200, 400, 50], output_type="file", outfile=tmpfile.name
94+
grid=grid,
95+
contour=[200, 400, 50],
96+
output_type="file",
97+
outfile=tmpfile.name,
98+
region=region,
11099
)
111100
assert result is None # return value is None
112101
assert os.path.exists(path=tmpfile.name) # check that outfile exists

0 commit comments

Comments
 (0)