Skip to content

Commit

Permalink
Mark unit tests with @pytest.mark.benchmark part 1 (#2911)
Browse files Browse the repository at this point in the history
* Benchmark test_geopandas_info_geodataframe
* Benchmark test_select_input_dataframe
* Benchmark test_grdfill_dataarray
* Benchmark test_grdimage_image_dataarray
* Benchmark test_meca_spec_multiple_focalmecha
* Benchmark test_grdimage_grid_and_shading_with_xarray
* Benchmark test_grdinfo
* Benchmark test_x2sys_cross_input_dataframe_output_dataframe
* Benchmark test_grdview_drapegrid_dataarray
* Benchmark test_solar_set_terminator_datetime
* Benchmark test_tilemap_ogc_wgs84
* Benchmark test_grd2cpt
* Benchmark test_grd2xyz
* Benchmark test_grdclip_no_outgrid
* Benchmark test_grdcontour_labels
* Benchmark test_grdcut_dataarray_in_dataarray_out
* Benchmark test_grdfilter_dataarray_in_dataarray_out
* Benchmark test_grdgradient_no_outgrid
* Benchmark test_equalize_grid_no_outgrid and test_compute_bins_no_outfile
* Benchmark test_grdlandmask_no_outgrid
* Benchmark test_grdproject_no_outgrid
* Benchmark test_grdsample_dataarray_out
* Benchmark test_grdtrack_input_dataframe_and_dataarray
* Benchmark test_grdvolume_no_outgrid
* Benchmark test_histogram
* Benchmark test_info_pandas_dataframe_date_column and test_info_xarray_dataset_time_column
* Benchmark test_inset_aliases
* Benchmark test_io_load_dataarray
* Benchmark test_legend_entries
* Benchmark test_logo
* Benchmark test_makecpt_output_cpt_file
* Benchmark test_nearneighbor_input_xyz
* Benchmark test_plot_vectors
* Benchmark test_plot3d_vectors
* Benchmark test_project_input_matrix
* Benchmark test_psconvert
* Benchmark test_rose_plot_data_using_cpt
* Benchmark test_begin_end
* Benchmark test_sph2grd_no_outgrid
* Benchmark test_sphdistance_no_outgrid
* Benchmark test_sphinterpolate_no_outgrid
* Benchmark test_subplot_basic_frame
* Benchmark test_surface_input_xyz
* Benchmark test_ternary_3_labels
* Benchmark test_text_multiple_lines_of_text
* Benchmark test_timestamp_font
* Benchmark test_delaunay_triples_input_xyz and test_regular_grid_no_outgrid
* Benchmark test_velo_pandas_dataframe
* Benchmark test_which_multiple
* Benchmark test_wiggle_data_incols
* Benchmark test_x2sys_init_units_gap
* Benchmark test_xyz2grd_input_array
  • Loading branch information
weiji14 committed Dec 27, 2023
1 parent 3076ddc commit c550f83
Show file tree
Hide file tree
Showing 53 changed files with 59 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 @@ -61,7 +61,7 @@ jobs:
echo $CONDA/bin >> $GITHUB_PATH
conda install --solver=libmamba gmt=6.4.0 python=3.12 \
numpy pandas xarray netCDF4 packaging \
pytest pytest-benchmark pytest-mpl
geopandas pytest pytest-benchmark pytest-mpl
python -m pip install -U pytest-codspeed setuptools
# Install the package that we want to test
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def fixture_gdf_ridge():
return gdf


@pytest.mark.benchmark
def test_geopandas_info_geodataframe(gdf):
"""
Check that info can return the bounding box region from a
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grd2cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def fixture_grid():
return load_static_earth_relief()


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_grd2cpt(grid):
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grd2xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def fixture_grid():
return load_static_earth_relief()


@pytest.mark.benchmark
def test_grd2xyz(grid):
"""
Make sure grd2xyz works as expected.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_grdclip_outgrid(grid, expected_grid):
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


@pytest.mark.benchmark
def test_grdclip_no_outgrid(grid, expected_grid):
"""
Test the below and above parameters for grdclip with no set outgrid.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_grdcontour(grid):
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_grdcontour_labels(grid):
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_grdcut_dataarray_in_file_out(grid, expected_grid, region):
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


@pytest.mark.benchmark
def test_grdcut_dataarray_in_dataarray_out(grid, expected_grid, region):
"""
Test grdcut on an input DataArray, and output as DataArray.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def fixture_expected_grid():
)


@pytest.mark.benchmark
def test_grdfill_dataarray_out(grid, expected_grid):
"""
Test grdfill with a DataArray output.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def fixture_expected_grid():
)


@pytest.mark.benchmark
def test_grdfilter_dataarray_in_dataarray_out(grid, expected_grid):
"""
Test grdfilter with an input DataArray, and output as DataArray.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdgradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_grdgradient_outgrid(grid, expected_grid):
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


@pytest.mark.benchmark
def test_grdgradient_no_outgrid(grid, expected_grid):
"""
Test the azimuth and direction parameters for grdgradient with no set
Expand Down
4 changes: 3 additions & 1 deletion pygmt/tests/test_grdhisteq.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def test_equalize_grid_outgrid_file(grid, expected_grid, region):
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


def test_equalize_grid_outgrid(grid, expected_grid, region):
@pytest.mark.benchmark
def test_equalize_grid_no_outgrid(grid, expected_grid, region):
"""
Test grdhisteq.equalize_grid with ``outgrid=None``.
"""
Expand All @@ -81,6 +82,7 @@ def test_equalize_grid_outgrid(grid, expected_grid, region):
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


@pytest.mark.benchmark
def test_compute_bins_no_outfile(grid, expected_df, region):
"""
Test grdhisteq.compute_bins with no ``outfile``.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def test_grdimage_shading_xarray(grid, shading):
return fig_ref, fig_test


@pytest.mark.benchmark
@check_figures_equal()
def test_grdimage_grid_and_shading_with_xarray(grid, xrgrid):
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdimage_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_grdimage_image():
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare(filename="test_grdimage_image.png")
def test_grdimage_image_dataarray(xr_image):
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def fixture_grid():
return load_static_earth_relief()


@pytest.mark.benchmark
def test_grdinfo(grid):
"""
Make sure grdinfo works as expected.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdlandmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_grdlandmask_outgrid(expected_grid):
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


@pytest.mark.benchmark
def test_grdlandmask_no_outgrid(expected_grid):
"""
Test grdlandmask with no set outgrid.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_grdproject_file_out(grid, expected_grid):
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


@pytest.mark.benchmark
@pytest.mark.parametrize(
"projection",
["M10c", "EPSG:3395 +width=10", "+proj=merc +ellps=WGS84 +units=m +width=10"],
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def test_grdsample_file_out(grid, expected_grid, region, spacing):
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


@pytest.mark.benchmark
def test_grdsample_dataarray_out(grid, expected_grid, region, spacing):
"""
Test grdsample with no outgrid set and the spacing is changed.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdtrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def fixture_dataframe():
)


@pytest.mark.benchmark
def test_grdtrack_input_dataframe_and_dataarray(dataarray, dataframe, expected_array):
"""
Run grdtrack by passing in a pandas.DataFrame and xarray.DataArray as
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def test_grdview_on_a_plane_styled_with_facadepen(xrgrid):
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_grdview_drapegrid_dataarray(xrgrid):
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_grdvolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_grdvolume_no_outfile(grid):
grdvolume(grid=grid, output_type="file")


@pytest.mark.benchmark
def test_grdvolume_no_outgrid(grid, data, region):
"""
Test the expected output of grdvolume with no output file set.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def fixture_data(request):
return request.param(data)


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare(filename="test_histogram.png")
def test_histogram(data):
"""
Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def test_info_numpy_array_time_column():
assert output == expected_output


@pytest.mark.benchmark
@pytest.mark.parametrize(
"dtype",
[
Expand All @@ -144,6 +145,7 @@ def test_info_pandas_dataframe_date_column(dtype):
assert output == expected_output


@pytest.mark.benchmark
def test_info_xarray_dataset_time_column():
"""
Make sure info works on xarray.Dataset 1-D inputs with a time column.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_inset.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_inset_aliases():
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pygmt.io import load_dataarray


@pytest.mark.benchmark
def test_io_load_dataarray():
"""
Check that load_dataarray works to read a netCDF grid with
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_legend_default_position():
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_legend_entries():
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_logo.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_logo():
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_makecpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_makecpt_plot_colorbar_scaled_with_series(position):
return fig


@pytest.mark.benchmark
def test_makecpt_output_cpt_file():
"""
Save the generated static color palette table to a .cpt file.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_meca_spec_single_focalmecha_file():
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare(filename="test_meca_spec_multiple_focalmecha.png")
@pytest.mark.parametrize(
"inputtype", ["dict_mecha", "dict_mecha_mixed", "dataframe", "array2d"]
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_nearneighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_nearneighbor_input_data(array_func, ship_data):
npt.assert_allclose(output.mean(), -2378.2385)


@pytest.mark.benchmark
def test_nearneighbor_input_xyz(ship_data):
"""
Run nearneighbor by passing in x, y, z numpy.ndarrays individually.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def test_plot_from_file(region):
return fig


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


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_plot3d_vectors():
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_project_generate():
)


@pytest.mark.benchmark
@pytest.mark.parametrize("array_func", [np.array, pd.DataFrame, xr.Dataset])
def test_project_input_matrix(array_func, dataframe):
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_psconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pygmt.exceptions import GMTInvalidInput


@pytest.mark.benchmark
def test_psconvert():
"""
Check that psconvert creates a figure in the current directory.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_rose.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_rose_2d_array_multiple(data):
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_rose_plot_data_using_cpt(data):
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def fixture_dataframe():
return load_sample_data(name="bathymetry")


@pytest.mark.benchmark
def test_select_input_dataframe(dataframe):
"""
Run select by passing in a pandas.DataFrame as input.
Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"""
import os

import pytest
from pygmt.clib import Session
from pygmt.session_management import begin, end


@pytest.mark.benchmark
def test_begin_end():
"""
Run a command inside a begin-end modern mode block.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_solar_terminators():
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare(filename="test_solar_set_terminator_datetime.png")
@pytest.mark.parametrize(
"terminator_datetime",
Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_sph2grd.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 sph2grd
from pygmt.helpers import GMTTempFile

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


@pytest.mark.benchmark
def test_sph2grd_no_outgrid():
"""
Test sph2grd with no set outgrid.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_sphdistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_sphdistance_outgrid(array):
assert Path(tmpfile.name).stat().st_size > 0 # check that outgrid exists


@pytest.mark.benchmark
def test_sphdistance_no_outgrid(array):
"""
Test sphdistance with no set outgrid.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_sphinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_sphinterpolate_outgrid(mars):
assert Path(tmpfile.name).stat().st_size > 0 # check that outgrid exists


@pytest.mark.benchmark
def test_sphinterpolate_no_outgrid(mars):
"""
Test sphinterpolate with no set outgrid.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_subplot.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_subplot_basic_frame():
"""
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_surface_input_data_array(data, region, spacing, expected_grid):
check_values(output, expected_grid)


@pytest.mark.benchmark
def test_surface_input_xyz(data, region, spacing, expected_grid):
"""
Run surface by passing in x, y, z numpy.ndarrays individually.
Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_ternary.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_ternary(array):
return fig


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


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


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


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_timestamp_font(faketime):
"""
Expand Down
Loading

0 comments on commit c550f83

Please sign in to comment.