Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark unit tests with @pytest.mark.benchmark part 2 #2924

Merged
merged 24 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
622dbcf
Benchmark test_binstats_no_outgrid
weiji14 Dec 27, 2023
5f419f1
Benchmark test_blockmean_input_xyz and test_blockmean_input_xyz
weiji14 Dec 27, 2023
f77db73
Benchmark test_blockmedian_input_table_matrix
weiji14 Dec 27, 2023
7d86e3c
Benchmark test_load_libgmt
weiji14 Dec 27, 2023
2875bf6
Benchmark test_put_matrix and test_put_matrix_grid
weiji14 Dec 27, 2023
998654b
Benchmark test_put_strings
weiji14 Dec 27, 2023
bae569b
Benchmark test_put_vector and test_put_vector_string_dtype
weiji14 Dec 27, 2023
cf9f56a
Benchmark test_call_module and test_dataarray_to_matrix_works
weiji14 Dec 27, 2023
84443ff
Benchmark four test_clib_virtualfile tests
weiji14 Dec 27, 2023
7197e8e
Install pyarrow in benchmarks.yml
weiji14 Dec 27, 2023
7e59b55
Benchmark test_coast_region
weiji14 Dec 27, 2023
a05d975
Benchmark test_colorbar_box
weiji14 Dec 27, 2023
658c737
Benchmark test_config_format_date_map
weiji14 Dec 27, 2023
b403808
Benchmark test_contour_matrix
weiji14 Dec 27, 2023
b32d1dc
Merge branch 'main' into pytest/mark-benchmark-part2
weiji14 Dec 27, 2023
406fc14
Benchmark load_remote_dataset_wrapper
weiji14 Dec 27, 2023
c88f70e
Benchmark test_earth_relief_holes
weiji14 Dec 27, 2023
7c14093
Benchmark test_dimfilter_no_outgrid
weiji14 Dec 27, 2023
af98e47
Benchmark test_figure_repr
weiji14 Dec 27, 2023
b7e4e0e
Benchmark test_filter1d_format
weiji14 Dec 27, 2023
f85aae7
Benchmark test_accessor_set_geographic_cartesian_roundtrip
weiji14 Dec 27, 2023
d44092e
Merge branch 'main' into pytest/mark-benchmark-part2
weiji14 Dec 30, 2023
eef9dc8
Benchmark test_virtualfile_from_vectors_one_string_or_object_column
weiji14 Dec 30, 2023
4c1f1e9
Merge branch 'main' into pytest/mark-benchmark-part2
weiji14 Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 \
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)
Comment on lines +22 to +34
Copy link
Member Author

@weiji14 weiji14 Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of benchmarking all the various load_earth_* functions, I just made created a new one that tests the _load_remote_dataset function, and it should cover the refactoring happening at #2917. Note that this test is somewhat duplicating test_earth_age_01d_with_region, but should be ok I hope.



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.
Comment on lines +183 to 186
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only benchmarking test_earth_relief_holes since it calls both pygmt.which and pygmt.io.load_dataarray. The other sample datasets call pygmt.which and pd.read_csv only.

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)
Loading