Skip to content

Commit 1a103ce

Browse files
authored
Mark unit tests with @pytest.mark.benchmark part 2 (#2924)
* Benchmark test_binstats_no_outgrid * Benchmark test_blockmean_input_xyz and test_blockmean_input_xyz * Benchmark test_blockmedian_input_table_matrix * Benchmark test_load_libgmt * Benchmark test_put_matrix and test_put_matrix_grid * Benchmark test_put_strings * Benchmark test_put_vector and test_put_vector_string_dtype * Benchmark test_call_module and test_dataarray_to_matrix_works * Benchmark four test_clib_virtualfile tests Specifically test_virtual_file, test_virtualfile_from_data_required_z_matrix, test_virtualfile_from_vectors, and test_virtualfile_from_matrix * Install pyarrow in benchmarks.yml * Benchmark test_coast_region * Benchmark test_colorbar_box * Benchmark test_config_format_date_map * Benchmark test_contour_matrix * Benchmark load_remote_dataset_wrapper * Benchmark test_earth_relief_holes * Benchmark test_dimfilter_no_outgrid * Benchmark test_figure_repr * Benchmark test_filter1d_format * Benchmark test_accessor_set_geographic_cartesian_roundtrip * Benchmark test_virtualfile_from_vectors_one_string_or_object_column
1 parent 98e0074 commit 1a103ce

20 files changed

+47
-2
lines changed

.github/workflows/benchmarks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
echo $CONDA/bin >> $GITHUB_PATH
5959
conda install --solver=libmamba gmt=6.4.0 python=3.12 \
6060
numpy pandas xarray netCDF4 packaging \
61-
geopandas pytest pytest-mpl
61+
geopandas pyarrow pytest pytest-mpl
6262
python -m pip install -U pytest-codspeed setuptools
6363
6464
# Download cached remote files (artifacts) from GitHub

pygmt/tests/test_accessor.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_accessor_set_pixel_registration():
4646
assert grid.gmt.registration == 1 # ensure changed to pixel registration
4747

4848

49+
@pytest.mark.benchmark
4950
def test_accessor_set_geographic_cartesian_roundtrip():
5051
"""
5152
Check that we can set a grid to switch between the default Cartesian coordinate type

pygmt/tests/test_binstats.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55

66
import numpy.testing as npt
7+
import pytest
78
from pygmt import binstats
89
from pygmt.helpers import GMTTempFile
910

@@ -26,6 +27,7 @@ def test_binstats_outgrid():
2627
assert Path(tmpfile.name).stat().st_size > 0 # check that outgrid exists
2728

2829

30+
@pytest.mark.benchmark
2931
def test_binstats_no_outgrid():
3032
"""
3133
Test binstats with no set outgrid.

pygmt/tests/test_blockm.py

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def test_blockmean_input_table_matrix(array_func, dataframe):
4545
npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0])
4646

4747

48+
@pytest.mark.benchmark
4849
def test_blockmean_input_xyz(dataframe):
4950
"""
5051
Run blockmean by passing in x/y/z as input.
@@ -99,6 +100,7 @@ def test_blockmean_without_outfile_setting():
99100
npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0])
100101

101102

103+
@pytest.mark.benchmark
102104
def test_blockmode_input_dataframe(dataframe):
103105
"""
104106
Run blockmode by passing in a pandas.DataFrame as input.

pygmt/tests/test_blockmedian.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def test_blockmedian_input_dataframe(dataframe):
3131
npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0])
3232

3333

34+
@pytest.mark.benchmark
3435
def test_blockmedian_input_table_matrix(dataframe):
3536
"""
3637
Run blockmedian using table input that is not a pandas.DataFrame but still a matrix.

pygmt/tests/test_clib.py

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def test_destroy_session_fails():
130130
ses.destroy()
131131

132132

133+
@pytest.mark.benchmark
133134
def test_call_module():
134135
"""
135136
Run a command to see if call_module works.
@@ -388,6 +389,7 @@ def test_write_data_fails():
388389
)
389390

390391

392+
@pytest.mark.benchmark
391393
def test_dataarray_to_matrix_works():
392394
"""
393395
Check that dataarray_to_matrix returns correct output.

pygmt/tests/test_clib_loading.py

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_clib_names():
6262

6363
###############################################################################
6464
# Test load_libgmt
65+
@pytest.mark.benchmark
6566
def test_load_libgmt():
6667
"""
6768
Test that loading libgmt works and doesn't crash.

pygmt/tests/test_clib_put_matrix.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def fixture_dtypes():
1919
return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split()
2020

2121

22+
@pytest.mark.benchmark
2223
def test_put_matrix(dtypes):
2324
"""
2425
Check that assigning a numpy 2-D array to a dataset works.
@@ -64,6 +65,7 @@ def test_put_matrix_fails():
6465
lib.put_matrix(dataset=None, matrix=np.empty((10, 2)), pad=0)
6566

6667

68+
@pytest.mark.benchmark
6769
def test_put_matrix_grid(dtypes):
6870
"""
6971
Check that assigning a numpy 2-D array to an ASCII and netCDF grid works.

pygmt/tests/test_clib_put_strings.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pygmt.helpers import GMTTempFile
1010

1111

12+
@pytest.mark.benchmark
1213
def test_put_strings():
1314
"""
1415
Check that assigning a numpy array of dtype str to a dataset works.

pygmt/tests/test_clib_put_vector.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def fixture_dtypes():
2020
return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split()
2121

2222

23+
@pytest.mark.benchmark
2324
def test_put_vector(dtypes):
2425
"""
2526
Check that assigning a numpy array to a dataset works.
@@ -97,6 +98,7 @@ def test_put_vector_mixed_dtypes(dtypes):
9798
npt.assert_allclose(newy, y)
9899

99100

101+
@pytest.mark.benchmark
100102
def test_put_vector_string_dtype():
101103
"""
102104
Passing string type vectors to a dataset.

pygmt/tests/test_clib_virtualfiles.py

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def fixture_dtypes_pandas(dtypes):
4747
return tuple(dtypes_pandas)
4848

4949

50+
@pytest.mark.benchmark
5051
def test_virtual_file(dtypes):
5152
"""
5253
Test passing in data via a virtual file with a Dataset.
@@ -122,6 +123,7 @@ def test_virtual_file_bad_direction():
122123
pass
123124

124125

126+
@pytest.mark.benchmark
125127
@pytest.mark.parametrize(
126128
("array_func", "kind"),
127129
[(np.array, "matrix"), (pd.DataFrame, "vector"), (xr.Dataset, "vector")],
@@ -202,6 +204,7 @@ def test_virtualfile_from_data_fail_non_valid_data(data):
202204
)
203205

204206

207+
@pytest.mark.benchmark
205208
def test_virtualfile_from_vectors(dtypes):
206209
"""
207210
Test the automation for transforming vectors to virtual file dataset.
@@ -221,6 +224,7 @@ def test_virtualfile_from_vectors(dtypes):
221224
assert output == expected
222225

223226

227+
@pytest.mark.benchmark
224228
@pytest.mark.parametrize("dtype", [str, object])
225229
def test_virtualfile_from_vectors_one_string_or_object_column(dtype):
226230
"""
@@ -290,6 +294,7 @@ def test_virtualfile_from_vectors_diff_size():
290294
pass
291295

292296

297+
@pytest.mark.benchmark
293298
def test_virtualfile_from_matrix(dtypes):
294299
"""
295300
Test transforming a matrix to virtual file dataset.

pygmt/tests/test_coast.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pygmt.exceptions import GMTInvalidInput
77

88

9+
@pytest.mark.benchmark
910
@pytest.mark.mpl_image_compare
1011
def test_coast_region():
1112
"""

pygmt/tests/test_colorbar.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pygmt import Figure
66

77

8+
@pytest.mark.benchmark
89
@pytest.mark.mpl_image_compare
910
def test_colorbar_box():
1011
"""

pygmt/tests/test_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_config_font_annot():
6464
return fig
6565

6666

67+
@pytest.mark.benchmark
6768
@pytest.mark.mpl_image_compare
6869
def test_config_format_date_map():
6970
"""

pygmt/tests/test_contour.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_contour_vec(region):
4646
return fig
4747

4848

49+
@pytest.mark.benchmark
4950
@pytest.mark.mpl_image_compare(filename="test_contour_matrix.png")
5051
@pytest.mark.parametrize(
5152
"array_func",

pygmt/tests/test_datasets_load_remote_datasets.py

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ def load_remote_dataset_wrapper(resolution="01d", region=None, registration=None
1919
)
2020

2121

22+
@pytest.mark.benchmark
23+
def test_load_remote_dataset_benchmark_with_region():
24+
"""
25+
Benchmark loading a remote dataset with 'region'.
26+
"""
27+
data = load_remote_dataset_wrapper(resolution="01d", region=[-10, 10, -5, 5])
28+
assert data.name == "seafloor_age"
29+
assert data.attrs["long_name"] == "age of seafloor crust"
30+
assert data.attrs["cpt"] == "@earth_age.cpt"
31+
assert data.attrs["units"] == "Myr"
32+
assert data.attrs["horizontal_datum"] == "WGS84"
33+
assert data.gmt.registration == 0
34+
assert data.shape == (11, 21)
35+
36+
2237
def test_load_remote_dataset_invalid_resolutions():
2338
"""
2439
Make sure _load_remote_dataset fails for invalid resolutions.

pygmt/tests/test_datasets_samples.py

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def test_load_notre_dame_topography():
180180
assert data["z"].max() == 960
181181

182182

183+
@pytest.mark.benchmark
183184
def test_earth_relief_holes():
184185
"""
185186
Check that the @earth_relief_20m_holes.grd dataset loads without errors.

pygmt/tests/test_dimfilter.py

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_dimfilter_outgrid(grid, expected_grid):
5959
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
6060

6161

62+
@pytest.mark.benchmark
6263
def test_dimfilter_no_outgrid(grid, expected_grid):
6364
"""
6465
Test the required parameters for dimfilter with no set outgrid.

pygmt/tests/test_figure.py

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_figure_region_country_codes():
5656
npt.assert_allclose(fig.region, np.array([0.0, 360.0, -90.0, 90.0]))
5757

5858

59+
@pytest.mark.benchmark
5960
def test_figure_repr():
6061
"""
6162
Make sure that figure output's PNG and HTML printable representations look ok.

pygmt/tests/test_filter1d.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def fixture_data():
2222

2323
def test_filter1d_no_outfile(data):
2424
"""
25-
Test filter1d with no set outgrid.
25+
Test filter1d with no set outfile.
2626
"""
2727
result = filter1d(data=data, filter_type="g5")
2828
assert result.shape == (671, 2)
@@ -79,13 +79,17 @@ def test_filter1d_outfile_incorrect_output_type(data):
7979
assert Path(tmpfile.name).stat().st_size > 0 # check that outfile exists
8080

8181

82+
@pytest.mark.benchmark
8283
def test_filter1d_format(data):
8384
"""
8485
Test that correct formats are returned.
8586
"""
8687
time_series_default = filter1d(data=data, filter_type="g5")
8788
assert isinstance(time_series_default, pd.DataFrame)
89+
assert time_series_default.shape == (671, 2)
8890
time_series_array = filter1d(data=data, filter_type="g5", output_type="numpy")
8991
assert isinstance(time_series_array, np.ndarray)
92+
assert time_series_array.shape == (671, 2)
9093
time_series_df = filter1d(data=data, filter_type="g5", output_type="pandas")
9194
assert isinstance(time_series_df, pd.DataFrame)
95+
assert time_series_df.shape == (671, 2)

0 commit comments

Comments
 (0)