Skip to content

Commit a375e69

Browse files
committed
Improve tests
1 parent 324b973 commit a375e69

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

pygmt/tests/test_alias_system.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,27 @@
88
from pygmt.helpers import build_arg_list
99

1010

11-
def func(projection=None, region=None, frame=None, label=None, text=None, **kwargs):
11+
def func(
12+
projection=None,
13+
region=None,
14+
frame=None,
15+
label=None,
16+
text=None,
17+
offset=None,
18+
**kwargs,
19+
):
1220
"""
1321
A simple function to test the alias system.
1422
"""
1523
alias = AliasSystem(
1624
J=Alias(projection, name="projection"),
1725
R=Alias(region, name="region", separator="/", size=[4, 6]),
1826
B=Alias(frame, name="frame"),
19-
U=[Alias(label, name="label"), Alias(text, name="text", prefix="+t")],
27+
U=[
28+
Alias(label, name="label"),
29+
Alias(text, name="text", prefix="+t"),
30+
Alias(offset, name="offset", prefix="+o", separator="/"),
31+
],
2032
).update(kwargs)
2133
return build_arg_list(alias.kwdict)
2234

@@ -32,14 +44,15 @@ def test_alias_system_long_form():
3244
# Repeatable parameters.
3345
assert func(frame=["WSen", "xaf", "yaf"]) == ["-BWSen", "-Bxaf", "-Byaf"]
3446
# Multiple long-form parameters.
35-
assert func(label="abcd", text="efg") == ["-Uabcd+tefg"]
47+
assert func(label="abcd", text="efg", offset=(12, 12)) == ["-Uabcd+tefg+o12/12"]
3648
assert func(
3749
projection="H10c",
3850
region=[0, 10, 0, 20],
3951
label="abcd",
4052
text="efg",
53+
offset=(12, 12),
4154
frame=["WSen", "xaf", "yaf"],
42-
) == ["-BWSen", "-Bxaf", "-Byaf", "-JH10c", "-R0/10/0/20", "-Uabcd+tefg"]
55+
) == ["-BWSen", "-Bxaf", "-Byaf", "-JH10c", "-R0/10/0/20", "-Uabcd+tefg+o12/12"]
4356

4457

4558
def test_alias_system_one_alias_short_form():
@@ -69,13 +82,14 @@ def test_alias_system_multiple_aliases_short_form():
6982
Test that the alias system works with multiple aliases when short-form parameters
7083
are used.
7184
"""
85+
_msg_long = r"Use long-form parameters 'label', with optional parameters 'text' \(\+t\), 'offset' \(\+o\) instead."
7286
# Long-form exists but is not given, and short-form is given.
73-
msg = r"Short-form parameter 'U' is not recommended. Use long-form parameters 'label', with optional parameters 'text' \(\+t\) instead."
87+
msg = rf"Short-form parameter 'U' is not recommended. {_msg_long}"
7488
with pytest.warns(SyntaxWarning, match=msg):
7589
assert func(U="abcd+tefg") == ["-Uabcd+tefg"]
7690

7791
# Coexistence of long-form and short-form parameters.
78-
msg = r"Short-form parameter 'U' conflicts with long-form parameters and is not recommended. Use long-form parameters 'label', with optional parameters 'text' \(\+t\) instead."
92+
msg = rf"Short-form parameter 'U' conflicts with long-form parameters and is not recommended. {_msg_long}"
7993
with pytest.raises(GMTInvalidInput, match=msg):
8094
func(label="abcd", U="efg")
8195

0 commit comments

Comments
 (0)