Skip to content

Commit d9acbbf

Browse files
authored
Fix RUF043 violations in ruff v0.13.0 (#4083)
1 parent d43d0f9 commit d9acbbf

File tree

7 files changed

+13
-17
lines changed

7 files changed

+13
-17
lines changed

pygmt/src/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,5 @@ def from_params(
242242
"""
243243
for convention, param_list in cls._params.items():
244244
if set(param_list).issubset(set(params)):
245-
return cls(convention, component=component)
245+
return cls(convention, component=component) # type: ignore[arg-type]
246246
raise GMTValueError(params, description="focal mechanism parameters")

pygmt/tests/test_alias_system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ def test_alias_system_one_alias_short_form():
7171
# Long-form exists but is not given, and short-form is given.
7272
with pytest.warns(
7373
SyntaxWarning,
74-
match="Short-form parameter 'J' is not recommended. Use long-form parameter 'projection' instead.",
74+
match=r"Short-form parameter 'J' is not recommended. Use long-form parameter 'projection' instead.",
7575
):
7676
assert func(J="X10c") == ["-JX10c"]
7777

7878
# Coexistence of long-form and short-form parameters.
7979
with pytest.raises(
8080
GMTInvalidInput,
81-
match="Short-form parameter 'J' conflicts with long-form parameters and is not recommended. Use long-form parameter 'projection' instead.",
81+
match=r"Short-form parameter 'J' conflicts with long-form parameters and is not recommended. Use long-form parameter 'projection' instead.",
8282
):
8383
func(projection="X10c", J="H10c")
8484

pygmt/tests/test_clib_loading.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_check_libgmt():
4343
Make sure check_libgmt fails when given a bogus library.
4444
"""
4545
libgmt = FakedLibGMT("/path/to/libgmt.so")
46-
msg = f"Error loading '{libgmt}'. Couldn't access function GMT_Create_Session."
46+
msg = rf"Error loading '{libgmt}'. Couldn't access function GMT_Create_Session."
4747
with pytest.raises(GMTCLibError, match=msg):
4848
check_libgmt(libgmt)
4949

@@ -150,7 +150,7 @@ def test_two_broken_libraries(self):
150150
rf"Error loading GMT shared library at '{self.faked_libgmt1._name}'.\n"
151151
rf"Error loading '{self.faked_libgmt1._name}'. Couldn't access.*\n"
152152
rf"Error loading GMT shared library at '{self.faked_libgmt2._name}'.\n"
153-
f"Error loading '{self.faked_libgmt2._name}'. Couldn't access.*"
153+
rf"Error loading '{self.faked_libgmt2._name}'. Couldn't access.*"
154154
)
155155
with pytest.raises(GMTCLibNotFoundError, match=msg_regex):
156156
load_libgmt(lib_fullnames=lib_fullnames)
@@ -168,7 +168,7 @@ def test_load_brokenlib_invalidpath(self):
168168
rf"Error loading GMT shared library at '{self.faked_libgmt1._name}'.\n"
169169
rf"Error loading '{self.faked_libgmt1._name}'. Couldn't access.*\n"
170170
rf"Error loading GMT shared library at '{self.invalid_path}'.\n"
171-
f"Unable to find '{self.invalid_path}'"
171+
rf"Unable to find '{self.invalid_path}'"
172172
)
173173
with pytest.raises(GMTCLibNotFoundError, match=msg_regex):
174174
load_libgmt(lib_fullnames=lib_fullnames)

pygmt/tests/test_clib_put_vector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def test_put_vector_invalid_dtype():
225225
dim=[2, 3, 0, 0], # ncolumns, nrows, dtype, unused
226226
)
227227
data = np.array([37, 12, 556], dtype=dtype)
228-
with pytest.raises(GMTTypeError, match="Unrecognized data type"):
228+
with pytest.raises(GMTTypeError, match=r"Unrecognized data type"):
229229
lib.put_vector(dataset, column=0, vector=data)
230230

231231

pygmt/tests/test_figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_figure_savefig_directory_nonexists():
174174
"""
175175
fig = Figure()
176176
fig.basemap(region="10/70/-300/800", projection="X3i/5i", frame="af")
177-
with pytest.raises(FileNotFoundError, match="No such directory:"):
177+
with pytest.raises(FileNotFoundError, match=r"No such directory:"):
178178
fig.savefig("a-nonexist-directory/test_figure_savefig_directory_nonexists.png")
179179

180180

@@ -185,7 +185,7 @@ def test_figure_savefig_unknown_extension():
185185
fig = Figure()
186186
fig.basemap(region="10/70/-300/800", projection="X3i/5i", frame="af")
187187
fname = "test_figure_savefig_unknown_extension.test"
188-
with pytest.raises(GMTValueError, match="Invalid file extension: 'test'."):
188+
with pytest.raises(GMTValueError, match=r"Invalid file extension: 'test'."):
189189
fig.savefig(fname)
190190

191191

@@ -196,7 +196,7 @@ def test_figure_savefig_ps_extension():
196196
fig = Figure()
197197
fig.basemap(region="10/70/-300/800", projection="X3c/5c", frame="af")
198198
fname = "test_figure_savefig_ps_extension.ps"
199-
with pytest.raises(GMTValueError, match="Extension '.ps' is not supported."):
199+
with pytest.raises(GMTValueError, match=r"Extension '.ps' is not supported."):
200200
fig.savefig(fname)
201201

202202

pygmt/tests/test_tilemap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_tilemap_no_contextily():
8686
Raise an ImportError when contextily is not installed.
8787
"""
8888
fig = Figure()
89-
with pytest.raises(ImportError, match="Package `contextily` is required"):
89+
with pytest.raises(ImportError, match=r"Package `contextily` is required"):
9090
fig.tilemap(
9191
region=[-20000000.0, 20000000.0, -20000000.0, 20000000.0],
9292
zoom=0,
@@ -105,7 +105,7 @@ def test_tilemap_no_rioxarray():
105105
# error about contextily, not rioxarray. Here we mock contextily as installed, to
106106
# make sure that we see the rioxarray error message when rioxarray is not installed.
107107
with patch("pygmt.datasets.tile_map._HAS_CONTEXTILY", True):
108-
with pytest.raises(ImportError, match="Package `rioxarray` is required"):
108+
with pytest.raises(ImportError, match=r"Package `rioxarray` is required"):
109109
fig.tilemap(
110110
region=[-180.0, 180.0, -90, 90], zoom=0, lonlat=True, frame="afg"
111111
)

pygmt/tests/test_xarray_backend.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import importlib
6-
import re
76

87
import numpy as np
98
import numpy.testing as npt
@@ -121,10 +120,7 @@ def test_xarray_backend_gmt_read_invalid_kind():
121120
Check that xarray.open_dataarray(..., engine="gmt") fails with missing or incorrect
122121
'raster_kind'.
123122
"""
124-
with pytest.raises(
125-
TypeError,
126-
match=re.escape("missing a required argument: 'raster_kind'"),
127-
):
123+
with pytest.raises(TypeError, match=r"missing a required argument: 'raster_kind'"):
128124
xr.open_dataarray("nokind.nc", engine="gmt")
129125

130126
with pytest.raises(GMTValueError):

0 commit comments

Comments
 (0)