-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathtest_params_pattern.py
More file actions
51 lines (38 loc) · 1.45 KB
/
test_params_pattern.py
File metadata and controls
51 lines (38 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Test the Pattern class.
"""
import pytest
from pygmt.exceptions import GMTValueError
from pygmt.params import Pattern
def test_pattern():
"""
Test the Pattern class.
"""
assert str(Pattern(1)) == "p1"
assert str(Pattern(id=1)) == "p1"
assert str(Pattern("pattern.png")) == "ppattern.png"
assert str(Pattern(10, bgcolor="red")) == "p10+bred"
assert str(Pattern(20, fgcolor="blue")) == "p20+fblue"
assert str(Pattern(30, bgcolor="red", fgcolor="blue")) == "p30+bred+fblue"
assert str(Pattern(30, fgcolor="blue", bgcolor="")) == "p30+b+fblue"
assert str(Pattern(30, fgcolor="", bgcolor="red")) == "p30+bred+f"
assert str(Pattern(40, dpi=300)) == "p40+r300"
assert str(Pattern(50, reversed=True)) == "P50"
pattern = Pattern(90, reversed=True, bgcolor="red", fgcolor="blue", dpi=300)
assert str(pattern) == "P90+bred+fblue+r300"
pattern = Pattern("pattern.png", bgcolor="red", fgcolor="blue", dpi=300)
assert str(pattern) == "ppattern.png+bred+fblue+r300"
def test_pattern_invalid_id():
"""
Test that an invalid pattern id raises a GMTValueError.
"""
with pytest.raises(GMTValueError):
_ = str(Pattern(91))
with pytest.raises(GMTValueError):
_ = str(Pattern(0))
def test_pattern_invalid_colors():
"""
Test that both fgcolor and bgcolor cannot be empty strings.
"""
with pytest.raises(GMTValueError):
_ = str(Pattern(10, fgcolor="", bgcolor=""))