Skip to content

Commit 9b65558

Browse files
authored
Figure.pygmtlogo: Validate the shape, theme, and wordmark parameters (#4755)
1 parent 76f2af6 commit 9b65558

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

examples/gallery/embellishments/pygmtlogo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646

4747
# %%
48-
# Via the ``wordamrk`` parameter the text "PyGMT" can be added on the right side or at
48+
# Via the ``wordmark`` parameter the text "PyGMT" can be added on the right side or at
4949
# the bottom of the visual. Use the ``width`` and ``height`` parameters to adjust the
5050
# size of the logo.
5151

pygmt/src/pygmtlogo.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def pygmtlogo(
321321
color
322322
``True`` for a color logo, and ``False`` for a black and white logo.
323323
position
324-
Position of the GMT logo on the plot. It can be specified in multiple ways:
324+
Position of the PyGMT logo on the plot. It can be specified in multiple ways:
325325
326326
- A :class:`pygmt.params.Position` object to fully control the reference point,
327327
anchor point, and offset.
@@ -370,19 +370,22 @@ def pygmtlogo(
370370
>>> fig.pygmtlogo(wordmark="horizontal", position="BR", height="1c")
371371
>>> fig.show()
372372
"""
373+
# Validate shape, theme, and wordmark values
374+
for value, description, choices in [
375+
(shape, "value for shape", ("circle", "hexagon")),
376+
(theme, "value for theme", ("light", "dark")),
377+
(wordmark, "value for wordmark", ("none", "horizontal", "vertical")),
378+
]:
379+
if value not in choices:
380+
raise GMTValueError(value, description=description, choices=choices)
381+
373382
# Set the default size of the visual logo to 2 cm.
374383
if width is None and height is None:
375384
match wordmark:
376385
case "none" | "vertical":
377386
width = width or "2c"
378387
case "horizontal":
379388
height = height or "2c"
380-
case _:
381-
raise GMTValueError(
382-
wordmark,
383-
description="value for wordmark",
384-
choices={"none", "horizontal", "vertical"},
385-
)
386389

387390
with GMTTempFile(suffix=".eps") as logofile:
388391
# Create logo file

pygmt/tests/test_pygmtlogo.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from pygmt import Figure
7+
from pygmt.exceptions import GMTValueError
78
from pygmt.params import Axis, Frame, Position
89
from pygmt.src.pygmtlogo import _create_logo
910

@@ -107,3 +108,16 @@ def test_pygmtlogo_wordmark_vertical(shape):
107108
wordmark="vertical",
108109
)
109110
return fig
111+
112+
113+
@pytest.mark.parametrize(
114+
("parameter", "value"),
115+
[("shape", "square"), ("theme", "blue"), ("wordmark", "diagonal")],
116+
)
117+
def test_pygmtlogo_invalid_options(parameter, value):
118+
"""
119+
Test that invalid arguments passed to shape, theme, and wordmark raise an error.
120+
"""
121+
fig = Figure()
122+
with pytest.raises(GMTValueError):
123+
fig.pygmtlogo(**{parameter: value})

0 commit comments

Comments
 (0)