Skip to content

Commit b84afb4

Browse files
committed
update test_text,plot,plot3d
1 parent 1791698 commit b84afb4

File tree

6 files changed

+15
-20
lines changed

6 files changed

+15
-20
lines changed

pygmt/src/plot.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pygmt._typing import PathLike, TableLike
99
from pygmt.alias import Alias, AliasSystem
1010
from pygmt.clib import Session
11-
from pygmt.exceptions import GMTInvalidInput, GMTTypeError
11+
from pygmt.exceptions import GMTParameterError, GMTTypeError
1212
from pygmt.helpers import (
1313
build_arg_list,
1414
data_kind,
@@ -272,8 +272,7 @@ def plot( # noqa: PLR0912, PLR0913
272272
data["symbol"] = symbol
273273
else:
274274
if any(v is not None for v in (x, y)):
275-
msg = "Too much data. Use either data or x/y/z."
276-
raise GMTInvalidInput(msg)
275+
raise GMTParameterError(at_most_one={"data", "x/y/z"})
277276
for name, value in [
278277
("direction", direction),
279278
("fill", kwargs.get("G")),

pygmt/src/plot3d.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pygmt._typing import PathLike, TableLike
99
from pygmt.alias import Alias, AliasSystem
1010
from pygmt.clib import Session
11-
from pygmt.exceptions import GMTInvalidInput, GMTTypeError
11+
from pygmt.exceptions import GMTParameterError, GMTTypeError
1212
from pygmt.helpers import (
1313
build_arg_list,
1414
data_kind,
@@ -252,8 +252,7 @@ def plot3d( # noqa: PLR0912, PLR0913
252252
data["symbol"] = symbol
253253
else:
254254
if any(v is not None for v in (x, y, z)):
255-
msg = "Too much data. Use either data or x/y/z."
256-
raise GMTInvalidInput(msg)
255+
raise GMTParameterError(at_most_one={"data", "x/y/z"})
257256

258257
for name, value in [
259258
("direction", direction),

pygmt/src/text.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pygmt._typing import AnchorCode, PathLike, StringArrayTypes, TableLike
1010
from pygmt.alias import Alias, AliasSystem
1111
from pygmt.clib import Session
12-
from pygmt.exceptions import GMTInvalidInput, GMTParameterError, GMTTypeError
12+
from pygmt.exceptions import GMTParameterError, GMTTypeError
1313
from pygmt.helpers import (
1414
_check_encoding,
1515
build_arg_list,
@@ -34,7 +34,7 @@
3434
it="use_word",
3535
w="wrap",
3636
)
37-
def text_( # noqa: PLR0912, PLR0913, PLR0915
37+
def text_( # noqa: PLR0912, PLR0913
3838
self,
3939
textfiles: PathLike | TableLike | None = None,
4040
x=None,
@@ -191,8 +191,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
191191
+ (position is not None)
192192
+ (x is not None or y is not None)
193193
) != 1:
194-
msg = "Provide either 'textfiles', 'x'/'y'/'text', or 'position'/'text'."
195-
raise GMTInvalidInput(msg)
194+
raise GMTParameterError(at_most_one={"textfiles", "x/y/text", "position/text"})
196195

197196
data_is_required = position is None
198197
kind = data_kind(textfiles, required=data_is_required)
@@ -209,8 +208,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
209208
)
210209

211210
if textfiles is not None and text is not None:
212-
msg = "'text' can't be specified when 'textfiles' is given."
213-
raise GMTInvalidInput(msg)
211+
raise GMTParameterError(at_most_one={"textfiles", "text"})
214212
if kind == "empty" and text is None:
215213
raise GMTParameterError(
216214
required="text", reason="Required when 'x' and 'y' are set."

pygmt/tests/test_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111
import xarray as xr
1212
from pygmt import Figure, which
13-
from pygmt.exceptions import GMTInvalidInput, GMTTypeError
13+
from pygmt.exceptions import GMTInvalidInput, GMTParameterError, GMTTypeError
1414
from pygmt.helpers import GMTTempFile
1515

1616
POINTS_DATA = Path(__file__).parent / "data" / "points.txt"
@@ -78,7 +78,7 @@ def test_plot_fail_no_data(data, region):
7878
frame="afg",
7979
)
8080
# Should also fail if given too much data
81-
with pytest.raises(GMTInvalidInput):
81+
with pytest.raises(GMTParameterError):
8282
fig.plot(
8383
x=data[:, 0],
8484
y=data[:, 1],

pygmt/tests/test_plot3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
import pytest
99
from pygmt import Figure
10-
from pygmt.exceptions import GMTInvalidInput, GMTTypeError
10+
from pygmt.exceptions import GMTInvalidInput, GMTParameterError, GMTTypeError
1111
from pygmt.helpers import GMTTempFile
1212

1313
POINTS_DATA = Path(__file__).parent / "data" / "points.txt"
@@ -97,7 +97,7 @@ def test_plot3d_fail_no_data(data, region):
9797
fig.plot3d(
9898
style="c0.2c", x=data[0], y=data[1], region=region, projection="X10c"
9999
)
100-
with pytest.raises(GMTInvalidInput):
100+
with pytest.raises(GMTParameterError):
101101
fig.plot3d(
102102
style="c0.2c", data=data, x=data[0], region=region, projection="X10c"
103103
)

pygmt/tests/test_text.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from pygmt import Figure, config
1010
from pygmt.exceptions import (
1111
GMTCLibError,
12-
GMTInvalidInput,
1312
GMTParameterError,
1413
GMTTypeError,
1514
)
@@ -151,19 +150,19 @@ def test_text_invalid_inputs(region):
151150
Run text by providing invalid combinations of inputs.
152151
"""
153152
fig = Figure()
154-
with pytest.raises(GMTInvalidInput):
153+
with pytest.raises(GMTParameterError):
155154
fig.text(
156155
region=region, projection="x1c", x=1.2, y=2.4, position="MC", text="text"
157156
)
158-
with pytest.raises(GMTInvalidInput):
157+
with pytest.raises(GMTParameterError):
159158
fig.text(region=region, projection="x1c", textfiles="file.txt", text="text")
160159
with pytest.raises(GMTParameterError):
161160
fig.text(region=region, projection="x1c", position="MC", text=None)
162161
with pytest.raises(GMTTypeError):
163162
fig.text(
164163
region=region, projection="x1c", position="MC", text=["text1", "text2"]
165164
)
166-
with pytest.raises(GMTInvalidInput):
165+
with pytest.raises(GMTParameterError):
167166
fig.text(region=region, projection="x1c", textfiles="file.txt", x=1.2, y=2.4)
168167

169168

0 commit comments

Comments
 (0)