Skip to content

Commit

Permalink
Mark unit tests with @pytest.mark.benchmark part 2 (#2924)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
weiji14 authored Jan 6, 2024
1 parent 98e0074 commit 1a103ce
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
echo $CONDA/bin >> $GITHUB_PATH
conda install --solver=libmamba gmt=6.4.0 python=3.12 \
numpy pandas xarray netCDF4 packaging \
geopandas pytest pytest-mpl
geopandas pyarrow pytest pytest-mpl
python -m pip install -U pytest-codspeed setuptools
# Download cached remote files (artifacts) from GitHub
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_accessor_set_pixel_registration():
assert grid.gmt.registration == 1 # ensure changed to pixel registration


@pytest.mark.benchmark
def test_accessor_set_geographic_cartesian_roundtrip():
"""
Check that we can set a grid to switch between the default Cartesian coordinate type
Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_binstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

import numpy.testing as npt
import pytest
from pygmt import binstats
from pygmt.helpers import GMTTempFile

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


@pytest.mark.benchmark
def test_binstats_no_outgrid():
"""
Test binstats with no set outgrid.
Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_blockm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_blockmean_input_table_matrix(array_func, dataframe):
npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0])


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


@pytest.mark.benchmark
def test_blockmode_input_dataframe(dataframe):
"""
Run blockmode by passing in a pandas.DataFrame as input.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_blockmedian.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_blockmedian_input_dataframe(dataframe):
npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0])


@pytest.mark.benchmark
def test_blockmedian_input_table_matrix(dataframe):
"""
Run blockmedian using table input that is not a pandas.DataFrame but still a matrix.
Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def test_destroy_session_fails():
ses.destroy()


@pytest.mark.benchmark
def test_call_module():
"""
Run a command to see if call_module works.
Expand Down Expand Up @@ -388,6 +389,7 @@ def test_write_data_fails():
)


@pytest.mark.benchmark
def test_dataarray_to_matrix_works():
"""
Check that dataarray_to_matrix returns correct output.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_clib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_clib_names():

###############################################################################
# Test load_libgmt
@pytest.mark.benchmark
def test_load_libgmt():
"""
Test that loading libgmt works and doesn't crash.
Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_clib_put_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def fixture_dtypes():
return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split()


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


@pytest.mark.benchmark
def test_put_matrix_grid(dtypes):
"""
Check that assigning a numpy 2-D array to an ASCII and netCDF grid works.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_clib_put_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pygmt.helpers import GMTTempFile


@pytest.mark.benchmark
def test_put_strings():
"""
Check that assigning a numpy array of dtype str to a dataset works.
Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_clib_put_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def fixture_dtypes():
return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split()


@pytest.mark.benchmark
def test_put_vector(dtypes):
"""
Check that assigning a numpy array to a dataset works.
Expand Down Expand Up @@ -97,6 +98,7 @@ def test_put_vector_mixed_dtypes(dtypes):
npt.assert_allclose(newy, y)


@pytest.mark.benchmark
def test_put_vector_string_dtype():
"""
Passing string type vectors to a dataset.
Expand Down
5 changes: 5 additions & 0 deletions pygmt/tests/test_clib_virtualfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def fixture_dtypes_pandas(dtypes):
return tuple(dtypes_pandas)


@pytest.mark.benchmark
def test_virtual_file(dtypes):
"""
Test passing in data via a virtual file with a Dataset.
Expand Down Expand Up @@ -122,6 +123,7 @@ def test_virtual_file_bad_direction():
pass


@pytest.mark.benchmark
@pytest.mark.parametrize(
("array_func", "kind"),
[(np.array, "matrix"), (pd.DataFrame, "vector"), (xr.Dataset, "vector")],
Expand Down Expand Up @@ -202,6 +204,7 @@ def test_virtualfile_from_data_fail_non_valid_data(data):
)


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


@pytest.mark.benchmark
@pytest.mark.parametrize("dtype", [str, object])
def test_virtualfile_from_vectors_one_string_or_object_column(dtype):
"""
Expand Down Expand Up @@ -290,6 +294,7 @@ def test_virtualfile_from_vectors_diff_size():
pass


@pytest.mark.benchmark
def test_virtualfile_from_matrix(dtypes):
"""
Test transforming a matrix to virtual file dataset.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_coast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pygmt.exceptions import GMTInvalidInput


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_coast_region():
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pygmt import Figure


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_colorbar_box():
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_config_font_annot():
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_config_format_date_map():
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_contour_vec(region):
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare(filename="test_contour_matrix.png")
@pytest.mark.parametrize(
"array_func",
Expand Down
15 changes: 15 additions & 0 deletions pygmt/tests/test_datasets_load_remote_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ def load_remote_dataset_wrapper(resolution="01d", region=None, registration=None
)


@pytest.mark.benchmark
def test_load_remote_dataset_benchmark_with_region():
"""
Benchmark loading a remote dataset with 'region'.
"""
data = load_remote_dataset_wrapper(resolution="01d", region=[-10, 10, -5, 5])
assert data.name == "seafloor_age"
assert data.attrs["long_name"] == "age of seafloor crust"
assert data.attrs["cpt"] == "@earth_age.cpt"
assert data.attrs["units"] == "Myr"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.gmt.registration == 0
assert data.shape == (11, 21)


def test_load_remote_dataset_invalid_resolutions():
"""
Make sure _load_remote_dataset fails for invalid resolutions.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def test_load_notre_dame_topography():
assert data["z"].max() == 960


@pytest.mark.benchmark
def test_earth_relief_holes():
"""
Check that the @earth_relief_20m_holes.grd dataset loads without errors.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_dimfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_dimfilter_outgrid(grid, expected_grid):
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


@pytest.mark.benchmark
def test_dimfilter_no_outgrid(grid, expected_grid):
"""
Test the required parameters for dimfilter with no set outgrid.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_figure_region_country_codes():
npt.assert_allclose(fig.region, np.array([0.0, 360.0, -90.0, 90.0]))


@pytest.mark.benchmark
def test_figure_repr():
"""
Make sure that figure output's PNG and HTML printable representations look ok.
Expand Down
6 changes: 5 additions & 1 deletion pygmt/tests/test_filter1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def fixture_data():

def test_filter1d_no_outfile(data):
"""
Test filter1d with no set outgrid.
Test filter1d with no set outfile.
"""
result = filter1d(data=data, filter_type="g5")
assert result.shape == (671, 2)
Expand Down Expand Up @@ -79,13 +79,17 @@ def test_filter1d_outfile_incorrect_output_type(data):
assert Path(tmpfile.name).stat().st_size > 0 # check that outfile exists


@pytest.mark.benchmark
def test_filter1d_format(data):
"""
Test that correct formats are returned.
"""
time_series_default = filter1d(data=data, filter_type="g5")
assert isinstance(time_series_default, pd.DataFrame)
assert time_series_default.shape == (671, 2)
time_series_array = filter1d(data=data, filter_type="g5", output_type="numpy")
assert isinstance(time_series_array, np.ndarray)
assert time_series_array.shape == (671, 2)
time_series_df = filter1d(data=data, filter_type="g5", output_type="pandas")
assert isinstance(time_series_df, pd.DataFrame)
assert time_series_df.shape == (671, 2)

0 comments on commit 1a103ce

Please sign in to comment.