diff --git a/environment.yml b/environment.yml index bf78c41b84e..f9fbe025aac 100644 --- a/environment.yml +++ b/environment.yml @@ -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 diff --git a/pygmt/figure.py b/pygmt/figure.py index 591c30b5c85..2e0a0895d3b 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -419,7 +419,7 @@ def _repr_html_(self) -> str: html = '' 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, diff --git a/pygmt/helpers/tempfile.py b/pygmt/helpers/tempfile.py index 033e34c3a46..38f914b7f89 100644 --- a/pygmt/helpers/tempfile.py +++ b/pygmt/helpers/tempfile.py @@ -132,7 +132,7 @@ def tempfile_from_geojson(geojson): E.g. '1a2b3c4d5e6.gmt'. """ with GMTTempFile(suffix=".gmt") as tmpfile: - import geopandas as gpd + import geopandas as gpd # noqa: PLC0415 Path(tmpfile.name).unlink() # Ensure file is deleted first ogrgmt_kwargs = {"filename": tmpfile.name, "driver": "OGR_GMT", "mode": "w"} @@ -157,7 +157,7 @@ def tempfile_from_geojson(geojson): geojson.to_file(**ogrgmt_kwargs) except AttributeError: # Other 'geo' formats which implement __geo_interface__ - import json + import json # noqa: PLC0415 jsontext = json.dumps(geojson.__geo_interface__) gpd.read_file(filename=io.StringIO(jsontext)).to_file(**ogrgmt_kwargs) diff --git a/pygmt/helpers/testing.py b/pygmt/helpers/testing.py index c658f9d350d..eda69f1d634 100644 --- a/pygmt/helpers/testing.py +++ b/pygmt/helpers/testing.py @@ -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) @@ -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) diff --git a/pygmt/tests/test_clib.py b/pygmt/tests/test_clib.py index c5727e16692..b1e1b02c730 100644 --- a/pygmt/tests/test_clib.py +++ b/pygmt/tests/test_clib.py @@ -2,6 +2,7 @@ Test the wrappers for the C API. """ +import importlib from contextlib import contextmanager import pytest @@ -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" diff --git a/pygmt/tests/test_clib_dataarray_to_matrix.py b/pygmt/tests/test_clib_dataarray_to_matrix.py index ec8e5e27e5a..7dfaf2df81a 100644 --- a/pygmt/tests/test_clib_dataarray_to_matrix.py +++ b/pygmt/tests/test_clib_dataarray_to_matrix.py @@ -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(): diff --git a/pygmt/tests/test_datatypes_dataset.py b/pygmt/tests/test_datatypes_dataset.py index 56f18143035..ace3dcbd9b6 100644 --- a/pygmt/tests/test_datatypes_dataset.py +++ b/pygmt/tests/test_datatypes_dataset.py @@ -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 diff --git a/pygmt/tests/test_figure.py b/pygmt/tests/test_figure.py index 7565e66f363..ef1f94452f6 100644 --- a/pygmt/tests/test_figure.py +++ b/pygmt/tests/test_figure.py @@ -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: @@ -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() diff --git a/pygmt/tests/test_grdclip.py b/pygmt/tests/test_grdclip.py index 818488914a8..a8824467131 100644 --- a/pygmt/tests/test_grdclip.py +++ b/pygmt/tests/test_grdclip.py @@ -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(): diff --git a/pygmt/tests/test_grdfill.py b/pygmt/tests/test_grdfill.py index c15b8464b7e..ed81a934cfa 100644 --- a/pygmt/tests/test_grdfill.py +++ b/pygmt/tests/test_grdfill.py @@ -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) diff --git a/pygmt/tests/test_grdhisteq.py b/pygmt/tests/test_grdhisteq.py index be1ccb7db95..35ca1cf9de7 100644 --- a/pygmt/tests/test_grdhisteq.py +++ b/pygmt/tests/test_grdhisteq.py @@ -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( diff --git a/pygmt/tests/test_grdimage_image.py b/pygmt/tests/test_grdimage_image.py index 5314c3882a2..392dad9941b 100644 --- a/pygmt/tests/test_grdimage_image.py +++ b/pygmt/tests/test_grdimage_image.py @@ -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 diff --git a/pygmt/tests/test_session_management.py b/pygmt/tests/test_session_management.py index d949f1a51c0..7217f56b4e4 100644 --- a/pygmt/tests/test_session_management.py +++ b/pygmt/tests/test_session_management.py @@ -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() diff --git a/pygmt/tests/test_timestamp.py b/pygmt/tests/test_timestamp.py index 0bf292e231c..d89a06c6c03 100644 --- a/pygmt/tests/test_timestamp.py +++ b/pygmt/tests/test_timestamp.py @@ -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 diff --git a/pygmt/tests/test_triangulate.py b/pygmt/tests/test_triangulate.py index 88f945a6c1d..4e4ba794240 100644 --- a/pygmt/tests/test_triangulate.py +++ b/pygmt/tests/test_triangulate.py @@ -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( diff --git a/pyproject.toml b/pyproject.toml index d8007e4c2d8..e391433947f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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