Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
# Dev dependencies (style checks)
- codespell
- pre-commit
- ruff>=0.10.0
- ruff>=0.12.0
# Dev dependencies (unit testing)
- matplotlib-base
- pytest>=6.0
Expand Down
2 changes: 1 addition & 1 deletion pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def _repr_html_(self) -> str:
html = '<img src="data:image/png;base64,{image}" width="{width}px">'
return html.format(image=base64_png.decode("utf-8"), width=500)

from pygmt.src import ( # type: ignore[misc]
from pygmt.src import ( # type: ignore[misc] # noqa: PLC0415
basemap,
coast,
colorbar,
Expand Down
4 changes: 2 additions & 2 deletions pygmt/helpers/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
E.g. '1a2b3c4d5e6.gmt'.
"""
with GMTTempFile(suffix=".gmt") as tmpfile:
import geopandas as gpd
import geopandas as gpd # noqa: PLC0415

Check warning on line 135 in pygmt/helpers/tempfile.py

View check run for this annotation

Codecov / codecov/patch

pygmt/helpers/tempfile.py#L135

Added line #L135 was not covered by tests

Path(tmpfile.name).unlink() # Ensure file is deleted first
ogrgmt_kwargs = {"filename": tmpfile.name, "driver": "OGR_GMT", "mode": "w"}
Expand All @@ -157,7 +157,7 @@
geojson.to_file(**ogrgmt_kwargs)
except AttributeError:
# Other 'geo' formats which implement __geo_interface__
import json
import json # noqa: PLC0415

Check warning on line 160 in pygmt/helpers/tempfile.py

View check run for this annotation

Codecov / codecov/patch

pygmt/helpers/tempfile.py#L160

Added line #L160 was not covered by tests

jsontext = json.dumps(geojson.__geo_interface__)
gpd.read_file(filename=io.StringIO(jsontext)).to_file(**ogrgmt_kwargs)
Expand Down
6 changes: 3 additions & 3 deletions pygmt/helpers/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def check_figures_equal(*, extensions=("png",), tol=0.0, result_dir="result_imag
keyword_only = inspect.Parameter.KEYWORD_ONLY

def decorator(func):
import pytest
from matplotlib.testing.compare import compare_images
import pytest # noqa: PLC0415
from matplotlib.testing.compare import compare_images # noqa: PLC0415

Path(result_dir).mkdir(parents=True, exist_ok=True)
old_sig = inspect.signature(func)
Expand Down Expand Up @@ -188,7 +188,7 @@ def skip_if_no(package):
A pytest.mark.skipif to use as either a test decorator or a
parametrization mark.
"""
import pytest
import pytest # noqa: PLC0415

try:
_ = importlib.import_module(name=package)
Expand Down
3 changes: 1 addition & 2 deletions pygmt/tests/test_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test the wrappers for the C API.
"""

import importlib
from contextlib import contextmanager

import pytest
Expand Down Expand Up @@ -241,8 +242,6 @@ def test_fails_for_wrong_version(monkeypatch):
"""
Make sure that importing clib raise an exception if GMT is too old.
"""
import importlib

with monkeypatch.context() as mpatch:
# Make sure the current GMT major version is 6.
assert clib.__gmt_version__.split(".")[0] == "6"
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_clib_dataarray_to_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_dataarray_to_matrix_irregular_inc_warning():
grid = xr.DataArray(data, coords=[("y", y), ("x", x)])
with pytest.warns(expected_warning=RuntimeWarning) as record:
dataarray_to_matrix(grid)
assert len(record) == 1
assert len(record) == 1


def test_dataarray_to_matrix_zero_inc_fails():
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_datatypes_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,6 @@ def test_dataset_to_strings_with_none_values():
Path(path).unlink()
with pytest.warns(expected_warning=RuntimeWarning) as record:
paths = which(fname=tiles, download="a")
assert len(record) == 1
assert len(record) == 1
assert len(paths) == 2
assert "" in paths
26 changes: 14 additions & 12 deletions pygmt/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def test_figure_savefig_geotiff():

# Check if a TIFF is georeferenced or not
if _HAS_RIOXARRAY:
import rioxarray
from rasterio.errors import NotGeoreferencedWarning
from rasterio.transform import Affine
import rioxarray # noqa: PLC0415
from rasterio.errors import NotGeoreferencedWarning # noqa: PLC0415
from rasterio.transform import Affine # noqa: PLC0415

# GeoTIFF
with rioxarray.open_rasterio(geofname) as xds:
Expand All @@ -152,15 +152,17 @@ def test_figure_savefig_geotiff():
# TIFF
with pytest.warns(expected_warning=NotGeoreferencedWarning) as record:
with rioxarray.open_rasterio(fname) as xds:
assert xds.rio.crs is None
npt.assert_allclose(
actual=xds.rio.bounds(), desired=(0.0, 0.0, 1331.0, 1257.0)
)
assert xds.rio.shape == (1257, 1331)
assert xds.rio.transform() == Affine(
a=1.0, b=0.0, c=0.0, d=0.0, e=1.0, f=0.0
)
assert len(record) == 1
pass
assert len(record) == 1
with rioxarray.open_rasterio(fname) as xds:
assert xds.rio.crs is None
npt.assert_allclose(
actual=xds.rio.bounds(), desired=(0.0, 0.0, 1331.0, 1257.0)
)
assert xds.rio.shape == (1257, 1331)
assert xds.rio.transform() == Affine(
a=1.0, b=0.0, c=0.0, d=0.0, e=1.0, f=0.0
)
geofname.unlink()
fname.unlink()

Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_grdclip_replace():
# TODO(PyGMT>=0.19.0): Remove this test below for the 'new' parameter
with pytest.warns(FutureWarning):
grid = grdclip(grid=grid, new=[1, 3]) # Replace 1 with 3
npt.assert_array_equal(np.unique(grid), [2, 3])
npt.assert_array_equal(np.unique(grid), [2, 3])


def test_grdclip_between_repeated():
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ def test_grdfill_deprecated_mode(grid, expected_grid):
"""
with pytest.warns(FutureWarning):
result = grdfill(grid=grid, mode="c20")
xr.testing.assert_allclose(a=result, b=expected_grid)
xr.testing.assert_allclose(a=result, b=expected_grid)
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdhisteq.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_compute_bins_outfile(grid, expected_df, region):
region=region,
outfile=tmpfile.name,
)
assert len(record) == 1 # check that only one warning was raised
assert len(record) == 1 # check that only one warning was raised
assert result is None # return value is None
assert Path(tmpfile.name).stat().st_size > 0
temp_df = pd.read_csv(
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdimage_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def test_grdimage_image_dataarray_unsupported_dtype(dtype, xr_image):
image = xr_image.copy().astype(dtype=dtype)
with pytest.warns(expected_warning=RuntimeWarning) as record:
fig.grdimage(grid=image)
assert len(record) == 1
assert len(record) == 1
2 changes: 1 addition & 1 deletion pygmt/tests/test_session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _gmt_func_wrapper(figname):
Currently, we have to import pygmt and reload it in each process. Workaround from
https://github.com/GenericMappingTools/pygmt/issues/217#issuecomment-754774875.
"""
import pygmt
import pygmt # noqa: PLC0415

reload(pygmt)
fig = pygmt.Figure()
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_timestamp_text_truncated():
with pytest.warns(expected_warning=RuntimeWarning) as record:
# a string with 70 characters will be truncated to 64 characters
fig.timestamp(text="0123456789" * 7)
assert len(record) == 1 # check that only one warning was raised
assert len(record) == 1 # check that only one warning was raised
return fig


Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_triangulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_delaunay_triples_outfile(dataframe, expected_dataframe):
with GMTTempFile(suffix=".txt") as tmpfile:
with pytest.warns(RuntimeWarning) as record:
result = triangulate.delaunay_triples(data=dataframe, outfile=tmpfile.name)
assert len(record) == 1 # check that only one warning was raised
assert len(record) == 1 # check that only one warning was raised
assert result is None # return value is None
assert Path(tmpfile.name).stat().st_size > 0
temp_df = pd.read_csv(
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ ignore = [
"D412", # No blank lines allowed between a section header and its content
"E501", # Avoid enforcing line-length violations
"ISC001", # Single-line-implicit-string-concatenation, conflict with formatter
"PD901", # Allow using the generic variable name `df` for DataFrames
"PT023", # Allow using pytest marker without parentheses
"PLR2004", # Allow any magic values
"RET504", # Allow variable assignment and return immediately for readability
Expand Down
Loading