Skip to content

Commit d392060

Browse files
committed
Add tests for the Pattern class
1 parent dc5ecb9 commit d392060

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pygmt/tests/test_params_pattern.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Test the Pattern class.
3+
"""
4+
5+
import pytest
6+
from pygmt.exceptions import GMTValueError
7+
from pygmt.params import Pattern
8+
9+
10+
def test_pattern():
11+
"""
12+
Test the Pattern class.
13+
"""
14+
assert str(Pattern(1)) == "p1"
15+
assert str(Pattern(id=1)) == "p1"
16+
17+
assert str(Pattern("pattern.png")) == "ppattern.png"
18+
19+
assert str(Pattern(10, bgcolor="red")) == "p10+bred"
20+
assert str(Pattern(20, fgcolor="blue")) == "p20+fblue"
21+
assert str(Pattern(30, bgcolor="red", fgcolor="blue")) == "p30+bred+fblue"
22+
assert str(Pattern(30, fgcolor="blue", bgcolor="")) == "p30+b+fblue"
23+
assert str(Pattern(30, fgcolor="", bgcolor="red")) == "p30+bred+f"
24+
25+
assert str(Pattern(40, dpi=300)) == "p40+r300"
26+
27+
assert str(Pattern(50, reversed=True)) == "P50"
28+
29+
pattern = Pattern(90, reversed=True, bgcolor="red", fgcolor="blue", dpi=300)
30+
assert str(pattern) == "P90+bred+fblue+r300"
31+
32+
pattern = Pattern("pattern.png", bgcolor="red", fgcolor="blue", dpi=300)
33+
assert str(pattern) == "ppattern.png+bred+fblue+r300"
34+
35+
36+
def test_pattern_invalid_id():
37+
"""
38+
Test that an invalid pattern id raises a GMTValueError.
39+
"""
40+
with pytest.raises(GMTValueError):
41+
_ = str(Pattern(91))
42+
with pytest.raises(GMTValueError):
43+
_ = str(Pattern(0))

0 commit comments

Comments
 (0)