Skip to content

Commit 721b46f

Browse files
committed
Validate anchor code
1 parent 1eae742 commit 721b46f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pygmt/params/position.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ def _validate(self):
181181
description="reference point",
182182
reason="Expect a valid 2-character justification code.",
183183
)
184+
# Validate the anchor if specified.
185+
if self.anchor is not None and self.anchor not in _valid_anchors:
186+
raise GMTValueError(
187+
self.anchor,
188+
description="anchor point",
189+
reason="Expect a valid 2-character justification code.",
190+
)
184191

185192
@property
186193
def _aliases(self):

pygmt/tests/test_params_position.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def test_params_position_invalid_location():
3838
"""
3939
with pytest.raises(GMTValueError):
4040
Position("invalid", type="mapcoords")
41+
with pytest.raises(GMTValueError):
42+
Position((1, 2, 3), type="mapcoords")
4143
with pytest.raises(GMTValueError):
4244
Position(5, type="plotcoords")
4345
with pytest.raises(GMTValueError):
@@ -46,3 +48,11 @@ def test_params_position_invalid_location():
4648
Position((10, 20), type="inside")
4749
with pytest.raises(GMTValueError):
4850
Position("TT", type="outside")
51+
52+
53+
def test_params_position_invalid_anchor():
54+
"""
55+
Test that invalid anchor inputs raise GMTValueError.
56+
"""
57+
with pytest.raises(GMTValueError):
58+
Position((10, 20), type="mapcoords", anchor="XX")

0 commit comments

Comments
 (0)